feature: Add High-Resolution LC3 plus mode

Duplicate interfaces for HR mode

spec: Remove intermediate quantized table

fix: legacy lc3_frame_bytes() and lc3_resolve_bitrate()

Cosmetic: rename fast_xxx math function to lc3_xxx
This commit is contained in:
Antoine Soulier
2023-12-21 15:42:08 -08:00
parent 149cb6537e
commit daa580235e
46 changed files with 4518 additions and 1149 deletions

View File

@@ -124,25 +124,32 @@ extern "C" {
/**
* Limitations
* - On the bitrate, in bps, of a stream
* - On the bitrate, in bps (48 KHz, 10ms frame size)
* - On the size of the frames in bytes
* - On the number of samples by frames
*/
#define LC3_MIN_BITRATE 16000
#define LC3_MAX_BITRATE 320000
#define LC3_MAX_HR_BITRATE 500000
#define LC3_MIN_FRAME_BYTES 20
#define LC3_MAX_FRAME_BYTES 400
#define LC3_MAX_HR_FRAME_BYTES 625
#define LC3_MIN_FRAME_SAMPLES __LC3_NS( 2500, 8000)
#define LC3_MAX_FRAME_SAMPLES __LC3_NS(10000, 48000)
#define LC3_MIN_FRAME_SAMPLES LC3_NS( 2500, 8000)
#define LC3_MAX_FRAME_SAMPLES LC3_NS(10000, 48000)
#define LC3_MAX_HR_FRAME_SAMPLES LC3_NS(10000, 96000)
/**
* Parameters check
* LC3_CHECK_DT_US(us) True when frame duration in us is suitable
* LC3_CHECK_SR_HZ(sr) True when samplerate in Hz is suitable
*
* LC3_CHECK_HR_SR_HZ(hrmode, sr)
* True when samplerate in Hz is suitable, according to the
* selection of the high-resolution mode `hrmode`.
*/
#define LC3_CHECK_DT_US(us) \
@@ -153,6 +160,9 @@ extern "C" {
( ((sr) == 8000) || ((sr) == 16000) || ((sr) == 24000) || \
((sr) == 32000) || ((sr) == 48000) )
#define LC3_CHECK_HR_SR_HZ(hrmode, sr) \
( (hrmode) ? ((sr) == 48000) || ((sr) == 96000) : LC3_CHECK_SR_HZ(sr) )
/**
* PCM Sample Format
@@ -197,51 +207,71 @@ typedef LC3_DECODER_MEM_T(10000, 48000) lc3_decoder_mem_48k_t;
/**
* Return the number of PCM samples in a frame
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* return Number of PCM samples, -1 on bad parameters
*/
int lc3_hr_frame_samples(bool hrmode, int dt_us, int sr_hz);
int lc3_frame_samples(int dt_us, int sr_hz);
/**
* Return the size of frames, from bitrate
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* bitrate Target bitrate in bit per second
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* bitrate Target bitrate in bit per second, 0 or `INT_MAX` returns
* respectively the minimum and maximum allowed size.
* return The floor size in bytes of the frames, -1 on bad parameters
*/
int lc3_hr_frame_bytes(bool hrmode, int dt_us, int sr_hz, int bitrate);
int lc3_frame_bytes(int dt_us, int bitrate);
/**
* Resolve the bitrate, from the size of frames
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* nbytes Size in bytes of the frames
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* nbytes Size in bytes of the frames, 0 or `INT_MAX` returns
* respectively the minimum and maximum allowed bitrate.
* return The according bitrate in bps, -1 on bad parameters
*/
int lc3_hr_resolve_bitrate(bool hrmode, int dt_us, int sr_hz, int nbytes);
int lc3_resolve_bitrate(int dt_us, int nbytes);
/**
* Return algorithmic delay, as a number of samples
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* return Number of algorithmic delay samples, -1 on bad parameters
*/
int lc3_hr_delay_samples(bool hrmode, int dt_us, int sr_hz);
int lc3_delay_samples(int dt_us, int sr_hz);
/**
* Return size needed for an encoder
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* return Size of then encoder in bytes, 0 on bad parameters
*
* The `sr_hz` parameter is the samplerate of the PCM input stream,
* and will match `sr_pcm_hz` of `lc3_setup_encoder()`.
* and will match `sr_pcm_hz` of `lc3_hr_setup_encoder()`.
*/
unsigned lc3_hr_encoder_size(bool hrmode, int dt_us, int sr_hz);
unsigned lc3_encoder_size(int dt_us, int sr_hz);
/**
* Setup encoder
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* sr_pcm_hz Input samplerate, downsampling option of input, or 0
* mem Encoder memory space, aligned to pointer type
* return Encoder as an handle, NULL on bad parameters
@@ -252,6 +282,9 @@ unsigned lc3_encoder_size(int dt_us, int sr_hz);
* samplerate `sr_hz`. The size of the context needed, given by
* `lc3_encoder_size()` will be set accordingly to `sr_pcm_hz`.
*/
lc3_encoder_t lc3_hr_setup_encoder(bool hrmode,
int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
lc3_encoder_t lc3_setup_encoder(
int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
@@ -269,19 +302,23 @@ int lc3_encode(lc3_encoder_t encoder, enum lc3_pcm_format fmt,
/**
* Return size needed for an decoder
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* return Size of then decoder in bytes, 0 on bad parameters
*
* The `sr_hz` parameter is the samplerate of the PCM output stream,
* and will match `sr_pcm_hz` of `lc3_setup_decoder()`.
*/
unsigned lc3_hr_decoder_size(bool hrmode, int dt_us, int sr_hz);
unsigned lc3_decoder_size(int dt_us, int sr_hz);
/**
* Setup decoder
* hrmode Enable High-Resolution mode (48000 and 96000 samplerates)
* dt_us Frame duration in us, 2500, 5000, 7500 or 10000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000 or 48000
* sr_hz Samplerate in Hz, 8000, 16000, 24000, 32000, 48000 or 96000
* sr_pcm_hz Output samplerate, upsampling option of output (or 0)
* mem Decoder memory space, aligned to pointer type
* return Decoder as an handle, NULL on bad parameters
@@ -292,6 +329,9 @@ unsigned lc3_decoder_size(int dt_us, int sr_hz);
* samplerate `sr_hz`. The size of the context needed, given by
* `lc3_decoder_size()` will be set accordingly to `sr_pcm_hz`.
*/
lc3_decoder_t lc3_hr_setup_decoder(bool hrmode,
int dt_us, int sr_hz, int sr_pcm_hz, void *mem);
lc3_decoder_t lc3_setup_decoder(
int dt_us, int sr_hz, int sr_pcm_hz, void *mem);