prefix lc3-related enums, types and files with btstack

This commit is contained in:
Matthias Ringwald 2022-04-20 18:57:07 +02:00
parent df9a25ac84
commit 2fd68da21a
9 changed files with 114 additions and 112 deletions

View File

@ -36,8 +36,8 @@
*
*/
#ifndef LC3_H
#define LC3_H
#ifndef BTSTACK_LC3_H
#define BTSTACK_LC3_H
#include <stdint.h>
@ -48,9 +48,9 @@ extern "C" {
/* API_START */
typedef enum {
LC3_FRAME_DURATION_10000US,
LC3_FRAME_DURATION_7500US
} lc3_frame_duration_t;
BTSTACK_LC3_FRAME_DURATION_10000US,
BTSTACK_LC3_FRAME_DURATION_7500US
} btstack_lc3_frame_duration_t;
typedef struct {
@ -62,7 +62,7 @@ typedef struct {
* @param context
* @return status
*/
uint8_t (*configure)(void * context, uint32_t sample_rate, lc3_frame_duration_t frame_duration);
uint8_t (*configure)(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration);
/**
* Get number of octets per LC3 frame for bitrate
@ -93,7 +93,7 @@ typedef struct {
uint8_t (*decode)(void * context, const uint8_t *bytes, uint16_t byte_count, uint8_t BFI,
int16_t* pcm_out, uint16_t pcm_out_size, uint8_t * BEC_detect);
} lc3_decoder_t;
} btstack_lc3_decoder_t;
typedef struct {
/**
@ -104,7 +104,7 @@ typedef struct {
* @param context
* @return status
*/
uint8_t (*configure)(void * context, uint32_t sample_rate, lc3_frame_duration_t frame_duration);
uint8_t (*configure)(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration);
/**
* Get bitrate from number of octets per LC3 frame
@ -131,7 +131,7 @@ typedef struct {
*/
uint8_t (*encode)(void * context, const int16_t* pcm_in, uint8_t *bytes, uint16_t byte_count);
} lc3_encoder_t;
} btstack_lc3_encoder_t;
/* API_END */

View File

@ -29,6 +29,8 @@
*
*/
#define BTSTACK_FILE__ "btstack_lc3_ehima.c"
/**
* @title LC3 EHIMA Wrapper
*/
@ -38,14 +40,14 @@
#ifdef HAVE_LC3_EHIMA
#include "lc3_ehima.h"
#include "btstack_lc3_ehima.h"
#include <Lc3Config.hpp>
#include <Lc3Decoder.hpp>
#include <Lc3Encoder.hpp>
/* Decoder implementation */
static uint8_t lc3_decoder_ehima_configure(void * context, uint32_t sample_rate, lc3_frame_duration_t frame_duration){
static uint8_t lc3_decoder_ehima_configure(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration){
lc3_decoder_ehima_t * instance = static_cast<lc3_decoder_ehima_t*>(context);
// free decoder if it exists
@ -61,10 +63,10 @@ static uint8_t lc3_decoder_ehima_configure(void * context, uint32_t sample_rate,
// map frame duration
Lc3Config::FrameDuration duration;
switch (frame_duration) {
case LC3_FRAME_DURATION_7500US:
case BTSTACK_LC3_FRAME_DURATION_7500US:
duration = Lc3Config::FrameDuration::d7p5ms;
break;
case LC3_FRAME_DURATION_10000US:
case BTSTACK_LC3_FRAME_DURATION_10000US:
duration = Lc3Config::FrameDuration::d10ms;
break;
default:
@ -95,21 +97,21 @@ static uint8_t lc3_decoder_ehima_decode(void * context, const uint8_t *bytes, ui
return ERROR_CODE_SUCCESS;
}
static const lc3_decoder_t l3c_decoder_ehima_instance = {
static const btstack_lc3_decoder_t l3c_decoder_ehima_instance = {
lc3_decoder_ehima_configure,
lc3_decoder_ehima_get_number_octets_for_bitrate,
lc3_decoder_ehima_get_number_samples_per_frame,
lc3_decoder_ehima_decode
};
const lc3_decoder_t * lc3_decoder_ehima_init_instance(lc3_decoder_ehima_t * context){
const btstack_lc3_decoder_t * lc3_decoder_ehima_init_instance(lc3_decoder_ehima_t * context){
memset(context, 0, sizeof(lc3_decoder_ehima_t));
return &l3c_decoder_ehima_instance;
}
/* Encoder implementation */
static uint8_t lc3_encoder_ehima_configure(void * context, uint32_t sample_rate, lc3_frame_duration_t frame_duration){
static uint8_t lc3_encoder_ehima_configure(void * context, uint32_t sample_rate, btstack_lc3_frame_duration_t frame_duration){
lc3_encoder_ehima_t * instance = static_cast<lc3_encoder_ehima_t*>(context);
// free decoder if it exists
@ -125,10 +127,10 @@ static uint8_t lc3_encoder_ehima_configure(void * context, uint32_t sample_rate,
// map frame duration
Lc3Config::FrameDuration duration;
switch (frame_duration) {
case LC3_FRAME_DURATION_7500US:
case BTSTACK_LC3_FRAME_DURATION_7500US:
duration = Lc3Config::FrameDuration::d7p5ms;
break;
case LC3_FRAME_DURATION_10000US:
case BTSTACK_LC3_FRAME_DURATION_10000US:
duration = Lc3Config::FrameDuration::d10ms;
break;
default:
@ -162,14 +164,14 @@ static uint8_t lc3_encoder_ehima_encode(void * context, const int16_t* pcm_in, u
return ERROR_CODE_SUCCESS;
}
static const lc3_encoder_t l3c_encoder_ehima_instance = {
static const btstack_lc3_encoder_t l3c_encoder_ehima_instance = {
lc3_encoder_ehima_configure,
lc3_encoder_ehima_get_bitrate_for_number_of_octets,
lc3_encoder_ehima_get_number_samples_per_frame,
lc3_encoder_ehima_encode
};
const lc3_encoder_t * lc3_encoder_ehima_init_instance(lc3_encoder_ehima_t * context){
const btstack_lc3_encoder_t * lc3_encoder_ehima_init_instance(lc3_encoder_ehima_t * context){
memset(context, 0, sizeof(lc3_decoder_ehima_t));
return &l3c_encoder_ehima_instance;
}

View File

@ -33,11 +33,11 @@
* @title LC3 EHIMA Implementation
*/
#ifndef LC3_EHIMA_H
#define LC3_EHIMA_H
#ifndef BTSTACK_LC3_EHIMA_H
#define BTSTACK_LC3_EHIMA_H
#include <stdint.h>
#include "lc3.h"
#include "btstack_lc3.h"
#if defined __cplusplus
extern "C" {
@ -46,32 +46,32 @@ extern "C" {
/* API_START */
typedef struct {
void * decoder;
uint32_t sample_rate;
lc3_frame_duration_t frame_duration;
void * decoder;
uint32_t sample_rate;
btstack_lc3_frame_duration_t frame_duration;
} lc3_decoder_ehima_t;
typedef struct {
void * encoder;
uint32_t sample_rate;
lc3_frame_duration_t frame_duration;
void * encoder;
uint32_t sample_rate;
btstack_lc3_frame_duration_t frame_duration;
} lc3_encoder_ehima_t;
/**
* Init LC3 Decoder Instance
* @param context for EHIMA LC3 decoder
*/
const lc3_decoder_t * lc3_decoder_ehima_init_instance(lc3_decoder_ehima_t * context);
const btstack_lc3_decoder_t * lc3_decoder_ehima_init_instance(lc3_decoder_ehima_t * context);
/**
* Init LC3 Decoder Instance
* @param context for EHIMA LC3 decoder
*/
const lc3_encoder_t * lc3_encoder_ehima_init_instance(lc3_encoder_ehima_t * context);
const btstack_lc3_encoder_t * lc3_encoder_ehima_init_instance(lc3_encoder_ehima_t * context);
/* API_END */
#if defined __cplusplus
}
#endif
#endif // LC3_EHIMA_H
#endif // BTSTACK_LC3_EHIMA_H

View File

@ -52,8 +52,8 @@
#include "btstack_util.h"
#include "btstack_debug.h"
#include "lc3.h"
#include "lc3_ehima.h"
#include "btstack_lc3.h"
#include "btstack_lc3_ehima.h"
#define MAX_NUM_CHANNELS 2
#define MAX_SAMPLES_PER_FRAME 480
@ -119,13 +119,13 @@ int main (int argc, const char * argv[]){
}
// pick frame duration
lc3_frame_duration_t duration2;
btstack_lc3_frame_duration_t duration2;
switch (frame_us) {
case 7500:
duration2 = LC3_FRAME_DURATION_7500US;
duration2 = BTSTACK_LC3_FRAME_DURATION_7500US;
break;
case 10000:
duration2 = LC3_FRAME_DURATION_10000US;
duration2 = BTSTACK_LC3_FRAME_DURATION_10000US;
break;
default:
return -10;
@ -134,7 +134,7 @@ int main (int argc, const char * argv[]){
// init decoder
uint8_t channel;
lc3_decoder_ehima_t decoder_contexts[MAX_NUM_CHANNELS];
const lc3_decoder_t * lc3_decoder;
const btstack_lc3_decoder_t * lc3_decoder;
for (channel = 0 ; channel < num_channels ; channel++){
lc3_decoder_ehima_t * decoder_context = &decoder_contexts[channel];
lc3_decoder = lc3_decoder_ehima_init_instance(decoder_context);

View File

@ -52,8 +52,8 @@
#include "btstack_util.h"
#include "btstack_debug.h"
#include "lc3.h"
#include "lc3_ehima.h"
#include "btstack_lc3.h"
#include "btstack_lc3_ehima.h"
#define MAX_NUM_CHANNELS 2
#define MAX_SAMPLES_PER_FRAME 480
@ -81,11 +81,11 @@ int main (int argc, const char * argv[]){
const char * wav_filename = argv[argv_pos++];
const char * lc3_filename = argv[argv_pos++];
lc3_frame_duration_t frame_duration;
btstack_lc3_frame_duration_t frame_duration;
if (strcmp(argv[argv_pos], "10") == 0){
frame_duration = LC3_FRAME_DURATION_10000US;
frame_duration = BTSTACK_LC3_FRAME_DURATION_10000US;
} else if (strcmp(argv[argv_pos], "7.5") == 0){
frame_duration = LC3_FRAME_DURATION_7500US;
frame_duration = BTSTACK_LC3_FRAME_DURATION_7500US;
} else {
printf("Invalid frame duration %s, must be either 7.5 or 10\n", argv[2]);
return -10;
@ -111,7 +111,7 @@ int main (int argc, const char * argv[]){
// init decoder
uint8_t channel;
lc3_encoder_ehima_t encoder_contexts[MAX_NUM_CHANNELS];
const lc3_encoder_t * lc3_encoder;
const btstack_lc3_encoder_t * lc3_encoder;
for (channel = 0 ; channel < num_channels ; channel++){
lc3_encoder_ehima_t * encoder_context = &encoder_contexts[channel];
lc3_encoder = lc3_encoder_ehima_init_instance(encoder_context);
@ -127,7 +127,7 @@ int main (int argc, const char * argv[]){
FILE * lc3_file = fopen(lc3_filename, "wb");
if (!lc3_file) return 1;
uint16_t frame_duration_100us = (frame_duration == LC3_FRAME_DURATION_10000US) ? 100 : 75;
uint16_t frame_duration_100us = (frame_duration == BTSTACK_LC3_FRAME_DURATION_10000US) ? 100 : 75;
uint8_t header[18];
little_endian_store_16(header, 0, 0xcc1c);
@ -145,7 +145,7 @@ int main (int argc, const char * argv[]){
printf("LC3 file: %s\n", lc3_filename);
printf("Samplerate: %u Hz\n", sampling_frequency_hz);
printf("Channels: %u\n", num_channels);
printf("Frame duration: %s ms\n", (frame_duration == LC3_FRAME_DURATION_10000US) ? "10" : "7.5");
printf("Frame duration: %s ms\n", (frame_duration == BTSTACK_LC3_FRAME_DURATION_10000US) ? "10" : "7.5");
printf("Bitrate: %u\n", bitrate);
printf("Samples per Frame: %u\n", number_samples_per_frame);

View File

@ -66,8 +66,8 @@
#include "gap.h"
#include "hci.h"
#include "hci_cmd.h"
#include "lc3.h"
#include "lc3_ehima.h"
#include "btstack_lc3.h"
#include "btstack_lc3_ehima.h"
#include "wav_util.h"
// max config
@ -145,13 +145,13 @@ static uint32_t lc3_frames;
// lc3 codec config
static uint32_t sampling_frequency_hz;
static lc3_frame_duration_t frame_duration;
static btstack_lc3_frame_duration_t frame_duration;
static uint16_t number_samples_per_frame;
static uint16_t octets_per_frame;
static uint8_t num_bis;
// lc3 decoder
static const lc3_decoder_t * lc3_decoder;
static const btstack_lc3_decoder_t * lc3_decoder;
static lc3_decoder_ehima_t decoder_contexts[MAX_NUM_BIS];
static int16_t pcm[MAX_NUM_BIS * MAX_SAMPLES_PER_FRAME];
@ -197,7 +197,7 @@ static void open_lc3_file(void) {
printf("LC3 binary file: %s\n", filename_lc3);
// calc bps
uint16_t frame_duration_100us = (frame_duration == LC3_FRAME_DURATION_7500US) ? 75 : 100;
uint16_t frame_duration_100us = (frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US) ? 75 : 100;
uint32_t bits_per_second = (uint32_t) octets_per_frame * num_bis * 8 * 10000 / frame_duration_100us;
// write header for floating point implementation
@ -291,8 +291,8 @@ static void handle_periodic_advertisement(const uint8_t * packet, uint16_t size)
break;
case 0x02: // 0 = 7.5, 1 = 10 ms
frame_duration_index = codec_specific_configuration[codec_offset+1];
frame_duration = (frame_duration_index == 0) ? LC3_FRAME_DURATION_7500US : LC3_FRAME_DURATION_10000US;
printf(" - frame duration[%u]: %s ms\n", i, (frame_duration == LC3_FRAME_DURATION_7500US) ? "7.5" : "10");
frame_duration = (frame_duration_index == 0) ? BTSTACK_LC3_FRAME_DURATION_7500US : BTSTACK_LC3_FRAME_DURATION_10000US;
printf(" - frame duration[%u]: %s ms\n", i, (frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US) ? "7.5" : "10");
break;
case 0x04: // octets per coding frame
octets_per_frame = little_endian_read_16(codec_specific_configuration, codec_offset+1);

View File

@ -54,8 +54,8 @@
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"
#include "lc3.h"
#include "lc3_ehima.h"
#include "btstack_lc3.h"
#include "btstack_lc3_ehima.h"
#include "hxcmod.h"
#include "mods/mod.h"
@ -234,13 +234,13 @@ static btstack_timer_source_t send_timer;
// lc3 codec config
static uint32_t sampling_frequency_hz;
static lc3_frame_duration_t frame_duration;
static btstack_lc3_frame_duration_t frame_duration;
static uint16_t number_samples_per_frame;
static uint16_t octets_per_frame;
static uint8_t num_bis = 1;
// lc3 encoder
static const lc3_encoder_t * lc3_encoder;
static const btstack_lc3_encoder_t * lc3_encoder;
static lc3_encoder_ehima_t encoder_contexts[MAX_NUM_BIS];
static int16_t pcm[MAX_NUM_BIS * MAX_SAMPLES_PER_FRAME];
static uint32_t time_generation_ms;
@ -281,54 +281,54 @@ static struct {
uint8_t num_variants;
struct {
const char * name;
lc3_frame_duration_t frame_duration;
btstack_lc3_frame_duration_t frame_duration;
uint16_t octets_per_frame;
} variants[6];
} codec_configurations[] = {
{
8000, 0x01, 2,
{
{ "8_1", LC3_FRAME_DURATION_7500US, 26},
{ "8_2", LC3_FRAME_DURATION_10000US, 30}
{ "8_1", BTSTACK_LC3_FRAME_DURATION_7500US, 26},
{ "8_2", BTSTACK_LC3_FRAME_DURATION_10000US, 30}
}
},
{
16000, 0x03, 2,
{
{ "16_1", LC3_FRAME_DURATION_7500US, 30},
{ "16_2", LC3_FRAME_DURATION_10000US, 40}
{ "16_1", BTSTACK_LC3_FRAME_DURATION_7500US, 30},
{ "16_2", BTSTACK_LC3_FRAME_DURATION_10000US, 40}
}
},
{
24000, 0x05, 2,
{
{ "24_1", LC3_FRAME_DURATION_7500US, 45},
{ "24_2", LC3_FRAME_DURATION_10000US, 60}
{ "24_1", BTSTACK_LC3_FRAME_DURATION_7500US, 45},
{ "24_2", BTSTACK_LC3_FRAME_DURATION_10000US, 60}
}
},
{
32000, 0x06, 2,
{
{ "32_1", LC3_FRAME_DURATION_7500US, 60},
{ "32_2", LC3_FRAME_DURATION_10000US, 80}
{ "32_1", BTSTACK_LC3_FRAME_DURATION_7500US, 60},
{ "32_2", BTSTACK_LC3_FRAME_DURATION_10000US, 80}
}
},
{
44100, 0x07, 2,
{
{ "441_1", LC3_FRAME_DURATION_7500US, 97},
{ "441_2", LC3_FRAME_DURATION_10000US, 130}
{ "441_1", BTSTACK_LC3_FRAME_DURATION_7500US, 97},
{ "441_2", BTSTACK_LC3_FRAME_DURATION_10000US, 130}
}
},
{
48000, 0x08, 6,
{
{ "48_1", LC3_FRAME_DURATION_7500US, 75},
{ "48_2", LC3_FRAME_DURATION_10000US, 100},
{ "48_3", LC3_FRAME_DURATION_7500US, 90},
{ "48_4", LC3_FRAME_DURATION_10000US, 120},
{ "48_5", LC3_FRAME_DURATION_7500US, 117},
{ "48_6", LC3_FRAME_DURATION_10000US, 155}
{ "48_1", BTSTACK_LC3_FRAME_DURATION_7500US, 75},
{ "48_2", BTSTACK_LC3_FRAME_DURATION_10000US, 100},
{ "48_3", BTSTACK_LC3_FRAME_DURATION_7500US, 90},
{ "48_4", BTSTACK_LC3_FRAME_DURATION_10000US, 120},
{ "48_5", BTSTACK_LC3_FRAME_DURATION_7500US, 117},
{ "48_6", BTSTACK_LC3_FRAME_DURATION_10000US, 155}
}
},
};
@ -340,7 +340,7 @@ static void print_config(void) {
codec_configurations[menu_sampling_frequency].variants[menu_variant].name,
num_bis,
codec_configurations[menu_sampling_frequency].samplingrate_hz,
codec_configurations[menu_sampling_frequency].variants[menu_variant].frame_duration == LC3_FRAME_DURATION_7500US ? "7.5" : "10",
codec_configurations[menu_sampling_frequency].variants[menu_variant].frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? "7.5" : "10",
codec_configurations[menu_sampling_frequency].variants[menu_variant].octets_per_frame,
audio_source == AUDIO_SOURCE_SINE ? "Sine" : "Modplayer");
}
@ -355,7 +355,7 @@ static void setup_lc3_encoder(void){
number_samples_per_frame = lc3_encoder->get_number_samples_per_frame(&encoder_contexts[0]);
btstack_assert(number_samples_per_frame <= MAX_SAMPLES_PER_FRAME);
printf("LC3 Encoder config: %u hz, frame duration %s ms, num samples %u, num octets %u\n",
sampling_frequency_hz, frame_duration == LC3_FRAME_DURATION_7500US ? "7.5" : "10",
sampling_frequency_hz, frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? "7.5" : "10",
number_samples_per_frame, octets_per_frame);
}
@ -638,10 +638,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
if (sampling_frequency_hz == 44100){
framed_pdus = 1;
// same config as for 48k -> frame is longer by 48/44.1
frame_duration_us = frame_duration == LC3_FRAME_DURATION_7500US ? 8163 : 10884;
frame_duration_us = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 8163 : 10884;
} else {
framed_pdus = 0;
frame_duration_us = frame_duration == LC3_FRAME_DURATION_7500US ? 7500 : 10000;
frame_duration_us = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 7500 : 10000;
}
hci_send_cmd(&hci_le_create_big, 0, adv_handle, num_bis, frame_duration_us, octets_per_frame, 0x1F, 2, 2, 0, framed_pdus, 0, broadcast_code);
}
@ -733,11 +733,11 @@ static void stdin_process(char c){
// update BASEs
periodic_adv_data_1[17] = codec_configurations[menu_sampling_frequency].samplingrate_index;
periodic_adv_data_1[20] = (frame_duration == LC3_FRAME_DURATION_7500US) ? 0 : 1;
periodic_adv_data_1[20] = (frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US) ? 0 : 1;
little_endian_store_16(periodic_adv_data_1, 23, octets_per_frame);
periodic_adv_data_2[17] = codec_configurations[menu_sampling_frequency].samplingrate_index;
periodic_adv_data_2[20] = (frame_duration == LC3_FRAME_DURATION_7500US) ? 0 : 1;
periodic_adv_data_2[20] = (frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US) ? 0 : 1;
little_endian_store_16(periodic_adv_data_2, 23, octets_per_frame);
// setup mod player

View File

@ -68,8 +68,8 @@
#include "gap.h"
#include "hci.h"
#include "hci_cmd.h"
#include "lc3.h"
#include "lc3_ehima.h"
#include "btstack_lc3.h"
#include "btstack_lc3_ehima.h"
#include "wav_util.h"
// max config
@ -148,13 +148,13 @@ static uint32_t lc3_frames;
// lc3 codec config
static uint32_t sampling_frequency_hz;
static lc3_frame_duration_t frame_duration;
static btstack_lc3_frame_duration_t frame_duration;
static uint16_t number_samples_per_frame;
static uint16_t octets_per_frame;
static uint8_t num_channels;
// lc3 decoder
static const lc3_decoder_t * lc3_decoder;
static const btstack_lc3_decoder_t * lc3_decoder;
static lc3_decoder_ehima_t decoder_contexts[MAX_CHANNELS];
static int16_t pcm[MAX_CHANNELS * MAX_SAMPLES_PER_FRAME];
@ -200,7 +200,7 @@ static void open_lc3_file(void) {
printf("LC3 binary file: %s\n", filename_lc3);
// calc bps
uint16_t frame_duration_100us = (frame_duration == LC3_FRAME_DURATION_7500US) ? 75 : 100;
uint16_t frame_duration_100us = (frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US) ? 75 : 100;
uint32_t bits_per_second = (uint32_t) octets_per_frame * num_channels * 8 * 10000 / frame_duration_100us;
// write header for floating point implementation
@ -330,7 +330,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
// sampling frequency
sampling_frequency_hz = 1000 * data[5];
// frame duration
frame_duration = data[6] == 0 ? LC3_FRAME_DURATION_7500US : LC3_FRAME_DURATION_10000US;
frame_duration = data[6] == 0 ? BTSTACK_LC3_FRAME_DURATION_7500US : BTSTACK_LC3_FRAME_DURATION_10000US;
// octets per frame
octets_per_frame = data[7];
// done
@ -413,10 +413,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
if (sampling_frequency_hz == 44100){
framed_pdus = 1;
// same config as for 48k -> frame is longer by 48/44.1
frame_duration_us = frame_duration == LC3_FRAME_DURATION_7500US ? 8163 : 10884;
frame_duration_us = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 8163 : 10884;
} else {
framed_pdus = 0;
frame_duration_us = frame_duration == LC3_FRAME_DURATION_7500US ? 7500 : 10000;
frame_duration_us = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 7500 : 10000;
}
printf("Send: LE Set CIG Parameters\n");

View File

@ -56,8 +56,8 @@
#include "hci.h"
#include "hci_cmd.h"
#include "hci_dump.h"
#include "lc3.h"
#include "lc3_ehima.h"
#include "btstack_lc3.h"
#include "btstack_lc3_ehima.h"
#include "hxcmod.h"
#include "mods/mod.h"
@ -151,13 +151,13 @@ static btstack_timer_source_t send_timer;
// lc3 codec config
static uint32_t sampling_frequency_hz;
static lc3_frame_duration_t frame_duration;
static btstack_lc3_frame_duration_t frame_duration;
static uint16_t number_samples_per_frame;
static uint16_t octets_per_frame;
static uint8_t num_channels = 1;
// lc3 encoder
static const lc3_encoder_t * lc3_encoder;
static const btstack_lc3_encoder_t * lc3_encoder;
static lc3_encoder_ehima_t encoder_contexts[MAX_CHANNELS];
static int16_t pcm[MAX_CHANNELS * MAX_SAMPLES_PER_FRAME];
static uint32_t time_generation_ms;
@ -198,54 +198,54 @@ static struct {
uint8_t num_variants;
struct {
const char * name;
lc3_frame_duration_t frame_duration;
btstack_lc3_frame_duration_t frame_duration;
uint16_t octets_per_frame;
} variants[6];
} codec_configurations[] = {
{
8000, 0x01, 2,
{
{ "8_1", LC3_FRAME_DURATION_7500US, 26},
{ "8_2", LC3_FRAME_DURATION_10000US, 30}
{ "8_1", BTSTACK_LC3_FRAME_DURATION_7500US, 26},
{ "8_2", BTSTACK_LC3_FRAME_DURATION_10000US, 30}
}
},
{
16000, 0x03, 2,
{
{ "16_1", LC3_FRAME_DURATION_7500US, 30},
{ "16_2", LC3_FRAME_DURATION_10000US, 40}
{ "16_1", BTSTACK_LC3_FRAME_DURATION_7500US, 30},
{ "16_2", BTSTACK_LC3_FRAME_DURATION_10000US, 40}
}
},
{
24000, 0x05, 2,
{
{ "24_1", LC3_FRAME_DURATION_7500US, 45},
{ "24_2", LC3_FRAME_DURATION_10000US, 60}
{ "24_1", BTSTACK_LC3_FRAME_DURATION_7500US, 45},
{ "24_2", BTSTACK_LC3_FRAME_DURATION_10000US, 60}
}
},
{
32000, 0x06, 2,
{
{ "32_1", LC3_FRAME_DURATION_7500US, 60},
{ "32_2", LC3_FRAME_DURATION_10000US, 80}
{ "32_1", BTSTACK_LC3_FRAME_DURATION_7500US, 60},
{ "32_2", BTSTACK_LC3_FRAME_DURATION_10000US, 80}
}
},
{
44100, 0x07, 2,
{
{ "441_1", LC3_FRAME_DURATION_7500US, 97},
{ "441_2", LC3_FRAME_DURATION_10000US, 130}
{ "441_1", BTSTACK_LC3_FRAME_DURATION_7500US, 97},
{ "441_2", BTSTACK_LC3_FRAME_DURATION_10000US, 130}
}
},
{
48000, 0x08, 6,
{
{ "48_1", LC3_FRAME_DURATION_7500US, 75},
{ "48_2", LC3_FRAME_DURATION_10000US, 100},
{ "48_3", LC3_FRAME_DURATION_7500US, 90},
{ "48_4", LC3_FRAME_DURATION_10000US, 120},
{ "48_5", LC3_FRAME_DURATION_7500US, 117},
{ "48_6", LC3_FRAME_DURATION_10000US, 155}
{ "48_1", BTSTACK_LC3_FRAME_DURATION_7500US, 75},
{ "48_2", BTSTACK_LC3_FRAME_DURATION_10000US, 100},
{ "48_3", BTSTACK_LC3_FRAME_DURATION_7500US, 90},
{ "48_4", BTSTACK_LC3_FRAME_DURATION_10000US, 120},
{ "48_5", BTSTACK_LC3_FRAME_DURATION_7500US, 117},
{ "48_6", BTSTACK_LC3_FRAME_DURATION_10000US, 155}
}
},
};
@ -257,7 +257,7 @@ static void print_config(void) {
codec_configurations[menu_sampling_frequency].variants[menu_variant].name,
num_channels,
codec_configurations[menu_sampling_frequency].samplingrate_hz,
codec_configurations[menu_sampling_frequency].variants[menu_variant].frame_duration == LC3_FRAME_DURATION_7500US ? "7.5" : "10",
codec_configurations[menu_sampling_frequency].variants[menu_variant].frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? "7.5" : "10",
codec_configurations[menu_sampling_frequency].variants[menu_variant].octets_per_frame,
audio_source == AUDIO_SOURCE_SINE ? "Sine" : "Modplayer");
}
@ -272,7 +272,7 @@ static void setup_lc3_encoder(void){
number_samples_per_frame = lc3_encoder->get_number_samples_per_frame(&encoder_contexts[0]);
btstack_assert(number_samples_per_frame <= MAX_SAMPLES_PER_FRAME);
printf("LC3 Encoder config: %u hz, frame duration %s ms, num samples %u, num octets %u\n",
sampling_frequency_hz, frame_duration == LC3_FRAME_DURATION_7500US ? "7.5" : "10",
sampling_frequency_hz, frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? "7.5" : "10",
number_samples_per_frame, octets_per_frame);
}
@ -690,7 +690,7 @@ static void stdin_process(char c){
adv_data[5] = 0; // flags
adv_data[6] = num_channels;
adv_data[7] = sampling_frequency_hz / 1000;
adv_data[8] = frame_duration == LC3_FRAME_DURATION_7500US ? 0 : 1;
adv_data[8] = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 0 : 1;
adv_data[9] = octets_per_frame;
// setup advertisements