uTrack
Loading...
Searching...
No Matches
Macros | Functions
utI2S_2387.c File Reference

utI2S_2387.c handles reading and writing audio to and from the I2S bus connected to the Bluetooth hardware module on the LPC2387, as well as writing recorded audio to a file. More...

#include <LPC23xx.h>
#include <stdio.h>
#include <string.h>
#include <pcm.h>
#include "utHAL.h"
#include "utI2S_2387.h"
#include "utI2S_2387Lowlevel.h"

Macros

#define MULTIBYTE_IRQ
 
#define LMASK   0xFFFF0000
 
#define RMASK   0x0000FFFF
 
#define LSHIFT   16
 
#define RSHIFT   0
 
#define FIFO_RX_LVL   4
 The minimum number of samples needed in the I2S RX hardware FIFO before an interrupt is generated. It is only defined if MULTIBYTE_IRQ is defined, because otherwise an interrupt is generated whenever a sample is placed in the FIFO.
 
#define MAX_CHANNELS   2
 
#define DAY_MS   86400000
 

Functions

int GetNChannels ()
 
void utI2S2387_Powerup (void)
 
__irq void utI2S2387_IRQHandler (void)
 
void utI2S2387_Start (void)
 
void utI2S2387_Stop (void)
 
void utI2S2387_EndRecording (void)
 
void utI2S2387_AddDeviceAddress (const char *btAddress, bool isFirstDevice)
 Adds a Bluetooth device ID to the current metadata tags. Currently a maximum of two device IDs is supported.
 
void utI2S2387_BeginRecording (const char *filename, UT_DateTime timestamp, bool isGPSTime, const char *serial, const char *btAddress, int recordingSession, int useChannels)
 Start recording audio to a file, with a set of metadata to append when recording is stopped.
 
void utI2S2387_UpdateToGPSTime (UT_DateTime timestamp)
 Adjusts the starting timestamp in the audio metadata according to the current time, provided the starting timestamp was not valid GPS time. It is assumed that the current timestamp is valid GPS time, because otherwise calling this function is not helpful. It operates by calculating the time since the audio recording started using the audio sample rate and quantity of recorded data. It does not allow for leap-seconds in the period between the starting time and the current time.
 
bool utI2S2387_Update (void)
 The step function for this module. This is where audio is written to file.
 
void utI2S2387_EnableLoopback (bool useLoopback, bool crossLink)
 

Detailed Description

utI2S_2387.c handles reading and writing audio to and from the I2S bus connected to the Bluetooth hardware module on the LPC2387, as well as writing recorded audio to a file.

Note that the Bluetooth module sends two copies of one sample when only one 16-bit channel is in use, or two copies of two 8-bit samples when only one 8-bit channel is in use.

Author
Oscar Key
Date
15/01/2012
Todo:

Function de-duplication.

Reduce coupling.

Generalise/abstract some overly specific functions.

Macro Definition Documentation

◆ DAY_MS

#define DAY_MS   86400000

The number of milliseconds in a day.

◆ LMASK

#define LMASK   0xFFFF0000

The bitmask for the 16-bit left channel in the 32-bit I2S FIFO hardware buffer.

◆ LSHIFT

#define LSHIFT   16

The number of places the left sample should be right shifted by to be stored in a 16-bit unsigned integer type.

◆ MAX_CHANNELS

#define MAX_CHANNELS   2

The maximum number of audio channels the current software implementation supports.

◆ MULTIBYTE_IRQ

#define MULTIBYTE_IRQ

Whether or not to clear multiple bytes from the hardware FIFO per interrupt.

◆ RMASK

#define RMASK   0x0000FFFF

The bitmask for the 16-bit rightchannel in the 32-bit I2S FIFO hardware buffer.

◆ RSHIFT

#define RSHIFT   0

The number of places the right sample should be right shifted by to be stored in a 16-bit unsigned integer type.

Function Documentation

◆ GetNChannels()

int GetNChannels ( )

GetNChannels returns the number of channels being used, and is referred to by the wavpack system.

Returns
The number of audio channels the system is operating with.

◆ utI2S2387_AddDeviceAddress()

void utI2S2387_AddDeviceAddress ( const char *  btAddress,
bool  isFirstDevice 
)

Adds a Bluetooth device ID to the current metadata tags. Currently a maximum of two device IDs is supported.

Parameters
btAddressThe null-terminated device ID to add.
isFirstDeviceWhether this is the first or second device ID being added.

◆ utI2S2387_BeginRecording()

void utI2S2387_BeginRecording ( const char *  filename,
UT_DateTime  timestamp,
bool  isGPSTime,
const char *  serial,
const char *  btAddress,
int  recordingSession,
int  useChannels 
)

Start recording audio to a file, with a set of metadata to append when recording is stopped.

Parameters
filenameThe filename to open and write to. Null-terminated.
timestampThe timestamp to store in the metadata. May be updated by utI2S2387_UpdateToGPSTime.
isGPSTimeWhether or not timestamp is the time according the GPS hardware module.
serialThe unit serial (bot ID). Null-terminated.
btAddressThe Bluetooth device ID of the device we are recording audio from. Null-terminated.
recordingSessionThe recording session for this runtime stream.
useChannelsThe number of channels expected over the I2S bus according to higher level logic. Current maximum of two.
Todo:
Enforce argument limits.

◆ utI2S2387_EnableLoopback()

void utI2S2387_EnableLoopback ( bool  useLoopback,
bool  crossLink 
)

Enables or disables the loopback capability, wherein audio received over the I2S bus can be transmitted back across it, so that the Bluetooth hardware sends it back to a headset. If two headsets are connected, the channels can be swapped, linking the two headsets together.

Parameters
useLoopbackWhether or not to send received audion data back over the I2S bus to the unit's Bluetooth hardware module.
crossLinkWhether or not to link headsets so they send to each other via the unit's Bluetooth module, provided there are two headsets.

◆ utI2S2387_EndRecording()

void utI2S2387_EndRecording ( void  )

Stops recording audio to the current file.

◆ utI2S2387_IRQHandler()

__irq void utI2S2387_IRQHandler ( void  )

The interrupt handler run when an interrupt is generated by the I2S RX hardware FIFO.

◆ utI2S2387_Powerup()

void utI2S2387_Powerup ( void  )

Dummy function for completeness and interface satisfaction.

◆ utI2S2387_Start()

void utI2S2387_Start ( void  )

Carries out the necessary pin configuration for the I2S bus between the LPC2387 and the WT32 Bluetooth hardware module to function.

◆ utI2S2387_Stop()

void utI2S2387_Stop ( void  )

Unsets the necessary pins to avoid leakage.

◆ utI2S2387_Update()

bool utI2S2387_Update ( void  )

The step function for this module. This is where audio is written to file.

Returns
Returns true if there were no errors, else false.

◆ utI2S2387_UpdateToGPSTime()

void utI2S2387_UpdateToGPSTime ( UT_DateTime  timestamp)

Adjusts the starting timestamp in the audio metadata according to the current time, provided the starting timestamp was not valid GPS time. It is assumed that the current timestamp is valid GPS time, because otherwise calling this function is not helpful. It operates by calculating the time since the audio recording started using the audio sample rate and quantity of recorded data. It does not allow for leap-seconds in the period between the starting time and the current time.

Parameters
timestampThe current time according to GPS fix data.