uTrack
|
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) |
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.
Function de-duplication.
Reduce coupling.
Generalise/abstract some overly specific functions.
#define DAY_MS 86400000 |
The number of milliseconds in a day.
#define LMASK 0xFFFF0000 |
The bitmask for the 16-bit left channel in the 32-bit I2S FIFO hardware buffer.
#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.
#define MAX_CHANNELS 2 |
The maximum number of audio channels the current software implementation supports.
#define MULTIBYTE_IRQ |
Whether or not to clear multiple bytes from the hardware FIFO per interrupt.
#define RMASK 0x0000FFFF |
The bitmask for the 16-bit rightchannel in the 32-bit I2S FIFO hardware buffer.
#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.
int GetNChannels | ( | ) |
GetNChannels returns the number of channels being used, and is referred to by the wavpack system.
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.
btAddress | The null-terminated device ID to add. |
isFirstDevice | Whether this is the first or second device ID being added. |
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.
filename | The filename to open and write to. Null-terminated. |
timestamp | The timestamp to store in the metadata. May be updated by utI2S2387_UpdateToGPSTime. |
isGPSTime | Whether or not timestamp is the time according the GPS hardware module. |
serial | The unit serial (bot ID). Null-terminated. |
btAddress | The Bluetooth device ID of the device we are recording audio from. Null-terminated. |
recordingSession | The recording session for this runtime stream. |
useChannels | The number of channels expected over the I2S bus according to higher level logic. Current maximum of two. |
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.
useLoopback | Whether or not to send received audion data back over the I2S bus to the unit's Bluetooth hardware module. |
crossLink | Whether or not to link headsets so they send to each other via the unit's Bluetooth module, provided there are two headsets. |
void utI2S2387_EndRecording | ( | void | ) |
Stops recording audio to the current file.
__irq void utI2S2387_IRQHandler | ( | void | ) |
The interrupt handler run when an interrupt is generated by the I2S RX hardware FIFO.
void utI2S2387_Powerup | ( | void | ) |
Dummy function for completeness and interface satisfaction.
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.
void utI2S2387_Stop | ( | void | ) |
Unsets the necessary pins to avoid leakage.
bool utI2S2387_Update | ( | void | ) |
The step function for this module. This is where audio is written to file.
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.
timestamp | The current time according to GPS fix data. |