mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 09:08:06 +00:00
test/lc3: convert bitrate <-> num octets per frame locally
This commit is contained in:
parent
12154a1a9a
commit
9b77781f6e
@ -132,6 +132,10 @@ int main (int argc, const char * argv[]){
|
||||
}
|
||||
|
||||
uint16_t number_samples_per_frame = btstack_lc3_samples_per_frame(sample_rate_hz, duration2);
|
||||
if (number_samples_per_frame > MAX_SAMPLES_PER_FRAME) {
|
||||
printf("number samples per frame %u too large\n", number_samples_per_frame);
|
||||
return -10;
|
||||
}
|
||||
|
||||
// init decoder
|
||||
uint8_t channel;
|
||||
@ -143,29 +147,24 @@ int main (int argc, const char * argv[]){
|
||||
lc3_decoder->configure(decoder_context, sample_rate_hz, duration2, number_samples_per_frame);
|
||||
}
|
||||
|
||||
// calc num octets from bitrate
|
||||
uint32_t bitrate_per_channel = bitrate / num_channels;
|
||||
uint16_t bytes_per_frame = lc3_decoder->get_number_octets_for_bitrate(&decoder_contexts[0], bitrate_per_channel);
|
||||
|
||||
// fix bitrate for 8_1
|
||||
uint16_t bytes_per_frame = 0;
|
||||
if ((sample_rate_hz == 8000) && (bitrate_per_channel == 27700)){
|
||||
// fix bitrate for 8_1
|
||||
bitrate_per_channel = 27734;
|
||||
bitrate = bitrate_per_channel * num_channels;
|
||||
bytes_per_frame = 26;
|
||||
}
|
||||
|
||||
// fix bitrate for 441_1 and 441_2
|
||||
if (sample_rate_hz == 44100){
|
||||
} else if (sample_rate_hz == 44100){
|
||||
// fix bitrate for 441_1 and 441_2
|
||||
if ((frame_us == 7500) && (bitrate_per_channel == 95000)) {
|
||||
bitrate = 95060;
|
||||
}
|
||||
if ((frame_us == 10000) && (bitrate_per_channel == 95500)) {
|
||||
bytes_per_frame = 130;
|
||||
}
|
||||
}
|
||||
|
||||
if (number_samples_per_frame > MAX_SAMPLES_PER_FRAME) {
|
||||
printf("number samples per frame %u too large\n", number_samples_per_frame);
|
||||
return -10;
|
||||
} else {
|
||||
bytes_per_frame = bitrate_per_channel / (10000 / (frame_us/100)) / 8;
|
||||
}
|
||||
|
||||
// print format
|
||||
|
@ -117,11 +117,31 @@ int main (int argc, const char * argv[]){
|
||||
lc3_encoder = btstack_lc3_encoder_google_init_instance(encoder_context);
|
||||
lc3_encoder->configure(encoder_context, sampling_frequency_hz, frame_duration, number_samples_per_frame);
|
||||
}
|
||||
uint32_t bitrate_per_channel = lc3_encoder->get_bitrate_for_number_of_octets(&encoder_contexts[0], bytes_per_frame);
|
||||
uint32_t bitrate = bitrate_per_channel * num_channels;
|
||||
|
||||
if (number_samples_per_frame > MAX_SAMPLES_PER_FRAME) return -10;
|
||||
|
||||
// calc bitrate from num octets
|
||||
uint32_t bitrate_per_channel = ((uint32_t) bytes_per_frame * 80000) / (btstack_lc3_frame_duration_in_us(frame_duration) / 100);
|
||||
// fix bitrate for 8_1
|
||||
if ((sampling_frequency_hz == 8000) && (frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US)) {
|
||||
bitrate_per_channel = 27734;
|
||||
}
|
||||
// fix bitrate for 441_1 and 441_2
|
||||
if (sampling_frequency_hz == 44100){
|
||||
switch(frame_duration){
|
||||
case BTSTACK_LC3_FRAME_DURATION_7500US:
|
||||
bitrate_per_channel = 95060;
|
||||
break;
|
||||
case BTSTACK_LC3_FRAME_DURATION_10000US:
|
||||
bitrate_per_channel = 95500;
|
||||
break;
|
||||
default:
|
||||
btstack_unreachable();
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint32_t bitrate = bitrate_per_channel * num_channels;
|
||||
|
||||
// create lc3 file and write header for floating point implementation
|
||||
FILE * lc3_file = fopen(lc3_filename, "wb");
|
||||
if (!lc3_file) return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user