1 /* 2 * Copyright (C) 2016 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #define BTSTACK_FILE__ "sco_demo_util.c" 39 40 /* 41 * sco_demo_util.c - send/receive test data via SCO, used by hfp_*_demo and hsp_*_demo 42 */ 43 44 #include <stdio.h> 45 46 #include "sco_demo_util.h" 47 48 #include "btstack_audio.h" 49 #include "btstack_debug.h" 50 #include "btstack_ring_buffer.h" 51 #include "classic/btstack_cvsd_plc.h" 52 #include "classic/btstack_sbc.h" 53 #include "classic/hfp.h" 54 #include "classic/hfp_msbc.h" 55 56 #ifdef _MSC_VER 57 // ignore deprecated warning for fopen 58 #pragma warning(disable : 4996) 59 #endif 60 61 #ifdef HAVE_POSIX_FILE_IO 62 #include "wav_util.h" 63 #endif 64 65 // test modes 66 #define SCO_DEMO_MODE_SINE 0 67 #define SCO_DEMO_MODE_MICROPHONE 1 68 69 // SCO demo configuration 70 #define SCO_DEMO_MODE SCO_DEMO_MODE_MICROPHONE 71 72 // number of sco packets until 'report' on console 73 #define SCO_REPORT_PERIOD 100 74 75 76 #ifdef HAVE_POSIX_FILE_IO 77 // length and name of wav file on disk 78 #define SCO_WAV_DURATION_IN_SECONDS 15 79 #define SCO_WAV_FILENAME "sco_input.wav" 80 #endif 81 82 83 // pre-buffer for CVSD and mSBC - also defines latency 84 #define SCO_CVSD_PA_PREBUFFER_MS 50 85 #define SCO_MSBC_PA_PREBUFFER_MS 50 86 87 // constants 88 #define NUM_CHANNELS 1 89 #define CVSD_SAMPLE_RATE 8000 90 #define MSBC_SAMPLE_RATE 16000 91 #define BYTES_PER_FRAME 2 92 93 #define CVSD_PA_PREBUFFER_BYTES (SCO_CVSD_PA_PREBUFFER_MS * CVSD_SAMPLE_RATE/1000 * BYTES_PER_FRAME) 94 #define MSBC_PA_PREBUFFER_BYTES (SCO_MSBC_PA_PREBUFFER_MS * MSBC_SAMPLE_RATE/1000 * BYTES_PER_FRAME) 95 96 // output 97 static int audio_output_paused = 0; 98 static uint8_t audio_output_ring_buffer_storage[2*MSBC_PA_PREBUFFER_BYTES]; 99 static btstack_ring_buffer_t audio_output_ring_buffer; 100 101 // input 102 #if SCO_DEMO_MODE == SCO_DEMO_MODE_MICROPHONE 103 #define USE_AUDIO_INPUT 104 #endif 105 static int audio_input_paused = 0; 106 static uint8_t audio_input_ring_buffer_storage[2*8000]; // full second input buffer 107 static btstack_ring_buffer_t audio_input_ring_buffer; 108 109 static int count_sent = 0; 110 static int count_received = 0; 111 static int negotiated_codec = -1; 112 113 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 114 static btstack_sbc_decoder_state_t decoder_state; 115 #endif 116 117 static btstack_cvsd_plc_state_t cvsd_plc_state; 118 119 #define MAX_NUM_MSBC_SAMPLES (16*8) 120 121 int num_samples_to_write; 122 int num_audio_frames; 123 124 #if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE 125 126 unsigned int phase; 127 128 // input signal: pre-computed sine wave, 266 Hz at 16000 kHz 129 static const int16_t sine_int16_at_16000hz[] = { 130 0, 3135, 6237, 9270, 12202, 14999, 17633, 20073, 22294, 24270, 131 25980, 27406, 28531, 29344, 29835, 30000, 29835, 29344, 28531, 27406, 132 25980, 24270, 22294, 20073, 17633, 14999, 12202, 9270, 6237, 3135, 133 0, -3135, -6237, -9270, -12202, -14999, -17633, -20073, -22294, -24270, 134 -25980, -27406, -28531, -29344, -29835, -30000, -29835, -29344, -28531, -27406, 135 -25980, -24270, -22294, -20073, -17633, -14999, -12202, -9270, -6237, -3135, 136 }; 137 138 // 8 kHz samples for CVSD/SCO packets in little endian 139 static void sco_demo_sine_wave_int16_at_8000_hz_host_endian(unsigned int num_samples, int16_t * data){ 140 unsigned int i; 141 for (i=0; i < num_samples; i++){ 142 data[i] = sine_int16_at_16000hz[phase]; 143 // ony use every second sample from 16khz table to get 8khz 144 phase += 2; 145 if (phase >= (sizeof(sine_int16_at_16000hz) / sizeof(int16_t))){ 146 phase = 0; 147 } 148 } 149 } 150 151 // 16 kHz samples for mSBC encoder in host endianess 152 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 153 static void sco_demo_sine_wave_int16_at_16000_hz_host_endian(unsigned int num_samples, int16_t * data){ 154 unsigned int i; 155 for (i=0; i < num_samples; i++){ 156 data[i] = sine_int16_at_16000hz[phase++]; 157 if (phase >= (sizeof(sine_int16_at_16000hz) / sizeof(int16_t))){ 158 phase = 0; 159 } 160 } 161 } 162 #endif 163 #endif 164 165 // Audio Playback / Recording 166 167 static void audio_playback_callback(int16_t * buffer, uint16_t num_samples){ 168 169 uint32_t prebuffer_bytes; 170 switch (negotiated_codec){ 171 case HFP_CODEC_MSBC: 172 prebuffer_bytes = MSBC_PA_PREBUFFER_BYTES; 173 break; 174 case HFP_CODEC_CVSD: 175 default: 176 prebuffer_bytes = CVSD_PA_PREBUFFER_BYTES; 177 break; 178 } 179 180 // fill with silence while paused 181 if (audio_output_paused){ 182 if (btstack_ring_buffer_bytes_available(&audio_output_ring_buffer) < prebuffer_bytes){ 183 memset(buffer, 0, num_samples * BYTES_PER_FRAME); 184 return; 185 } else { 186 // resume playback 187 audio_output_paused = 0; 188 } 189 } 190 191 // get data from ringbuffer 192 uint32_t bytes_read = 0; 193 btstack_ring_buffer_read(&audio_output_ring_buffer, (uint8_t *) buffer, num_samples * BYTES_PER_FRAME, &bytes_read); 194 num_samples -= bytes_read / BYTES_PER_FRAME; 195 buffer += bytes_read / BYTES_PER_FRAME; 196 197 // fill with 0 if not enough 198 if (num_samples){ 199 memset(buffer, 0, num_samples * BYTES_PER_FRAME); 200 audio_output_paused = 1; 201 } 202 } 203 204 #ifdef USE_AUDIO_INPUT 205 static void audio_recording_callback(const int16_t * buffer, uint16_t num_samples){ 206 btstack_ring_buffer_write(&audio_input_ring_buffer, (uint8_t *)buffer, num_samples * 2); 207 } 208 #endif 209 210 // return 1 if ok 211 static int audio_initialize(int sample_rate){ 212 213 // -- output -- // 214 215 // init buffers 216 memset(audio_output_ring_buffer_storage, 0, sizeof(audio_output_ring_buffer_storage)); 217 btstack_ring_buffer_init(&audio_output_ring_buffer, audio_output_ring_buffer_storage, sizeof(audio_output_ring_buffer_storage)); 218 219 // config and setup audio playback 220 const btstack_audio_sink_t * audio_sink = btstack_audio_sink_get_instance(); 221 if (!audio_sink) return 0; 222 223 audio_sink->init(1, sample_rate, &audio_playback_callback); 224 audio_sink->start_stream(); 225 226 audio_output_paused = 1; 227 228 // -- input -- // 229 230 // init buffers 231 memset(audio_input_ring_buffer_storage, 0, sizeof(audio_input_ring_buffer_storage)); 232 btstack_ring_buffer_init(&audio_input_ring_buffer, audio_input_ring_buffer_storage, sizeof(audio_input_ring_buffer_storage)); 233 audio_input_paused = 1; 234 235 #ifdef USE_AUDIO_INPUT 236 // config and setup audio recording 237 const btstack_audio_source_t * audio_source = btstack_audio_source_get_instance(); 238 if (!audio_source) return 0; 239 240 audio_source->init(1, sample_rate, &audio_recording_callback); 241 audio_source->start_stream(); 242 #endif 243 244 return 1; 245 } 246 247 static void audio_terminate(void){ 248 const btstack_audio_sink_t * audio_sink = btstack_audio_sink_get_instance(); 249 if (!audio_sink) return; 250 audio_sink->close(); 251 252 #ifdef USE_AUDIO_INPUT 253 const btstack_audio_source_t * audio_source= btstack_audio_source_get_instance(); 254 if (!audio_source) return; 255 audio_source->close(); 256 #endif 257 } 258 259 260 // CVSD - 8 kHz 261 262 static void sco_demo_init_CVSD(void){ 263 printf("SCO Demo: Init CVSD\n"); 264 265 btstack_cvsd_plc_init(&cvsd_plc_state); 266 267 #ifdef SCO_WAV_FILENAME 268 num_samples_to_write = CVSD_SAMPLE_RATE * SCO_WAV_DURATION_IN_SECONDS; 269 wav_writer_open(SCO_WAV_FILENAME, 1, CVSD_SAMPLE_RATE); 270 #endif 271 272 audio_initialize(CVSD_SAMPLE_RATE); 273 } 274 275 static void sco_demo_receive_CVSD(uint8_t * packet, uint16_t size){ 276 277 int16_t audio_frame_out[128]; // 278 279 if (size > sizeof(audio_frame_out)){ 280 printf("sco_demo_receive_CVSD: SCO packet larger than local output buffer - dropping data.\n"); 281 return; 282 } 283 284 const int audio_bytes_read = size - 3; 285 const int num_samples = audio_bytes_read / BYTES_PER_FRAME; 286 287 // convert into host endian 288 int16_t audio_frame_in[128]; 289 int i; 290 for (i=0;i<num_samples;i++){ 291 audio_frame_in[i] = little_endian_read_16(packet, 3 + i * 2); 292 } 293 294 // treat packet as bad frame if controller does not report 'all good' 295 bool bad_frame = (packet[1] & 0x30) != 0; 296 297 btstack_cvsd_plc_process_data(&cvsd_plc_state, bad_frame, audio_frame_in, num_samples, audio_frame_out); 298 299 #ifdef SCO_WAV_FILENAME 300 // Samples in CVSD SCO packet are in little endian, ready for wav files (take shortcut) 301 const int samples_to_write = btstack_min(num_samples, num_samples_to_write); 302 wav_writer_write_le_int16(samples_to_write, audio_frame_out); 303 num_samples_to_write -= samples_to_write; 304 if (num_samples_to_write == 0){ 305 wav_writer_close(); 306 } 307 #endif 308 309 btstack_ring_buffer_write(&audio_output_ring_buffer, (uint8_t *)audio_frame_out, audio_bytes_read); 310 } 311 312 void sco_demo_fill_payload_CVSD(uint8_t * payload_buffer, uint16_t sco_payload_length){ 313 314 #if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE 315 #define REFILL_SAMPLES 16 316 // re-fill with sine 317 uint16_t samples_free = btstack_ring_buffer_bytes_free(&audio_input_ring_buffer) / 2; 318 while (samples_free > 0){ 319 int16_t samples_buffer[REFILL_SAMPLES]; 320 uint16_t samples_to_add = btstack_min(samples_free, REFILL_SAMPLES); 321 sco_demo_sine_wave_int16_at_8000_hz_host_endian(samples_to_add, samples_buffer); 322 btstack_ring_buffer_write(&audio_input_ring_buffer, (uint8_t *)samples_buffer, samples_to_add * 2); 323 samples_free -= samples_to_add; 324 } 325 #endif 326 327 // resume if pre-buffer is filled 328 if (audio_input_paused){ 329 if (btstack_ring_buffer_bytes_available(&audio_input_ring_buffer) >= CVSD_PA_PREBUFFER_BYTES){ 330 // resume sending 331 audio_input_paused = 0; 332 } 333 } 334 335 uint16_t bytes_to_copy = sco_payload_length; 336 337 // get data from ringbuffer 338 uint16_t pos = 0; 339 if (!audio_input_paused){ 340 uint16_t samples_to_copy = sco_payload_length / 2; 341 uint32_t bytes_read = 0; 342 btstack_ring_buffer_read(&audio_input_ring_buffer, payload_buffer, bytes_to_copy, &bytes_read); 343 // flip 16 on big endian systems 344 // @note We don't use (uint16_t *) casts since all sample addresses are odd which causes crahses on some systems 345 if (btstack_is_big_endian()){ 346 uint16_t i; 347 for (i=0;i<samples_to_copy/2;i+=2){ 348 uint8_t tmp = payload_buffer[i*2]; 349 payload_buffer[i*2] = payload_buffer[i*2+1]; 350 payload_buffer[i*2+1] = tmp; 351 } 352 } 353 bytes_to_copy -= bytes_read; 354 pos += bytes_read; 355 } 356 357 // fill with 0 if not enough 358 if (bytes_to_copy){ 359 memset(payload_buffer + pos, 0, bytes_to_copy); 360 audio_input_paused = 1; 361 } 362 } 363 364 // mSBC - 16 kHz 365 366 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 367 368 static void handle_pcm_data(int16_t * data, int num_samples, int num_channels, int sample_rate, void * context){ 369 UNUSED(context); 370 UNUSED(sample_rate); 371 UNUSED(data); 372 UNUSED(num_samples); 373 UNUSED(num_channels); 374 375 // samples in callback in host endianess, ready for playback 376 btstack_ring_buffer_write(&audio_output_ring_buffer, (uint8_t *)data, num_samples*num_channels*2); 377 378 #ifdef SCO_WAV_FILENAME 379 if (!num_samples_to_write) return; 380 num_samples = btstack_min(num_samples, num_samples_to_write); 381 num_samples_to_write -= num_samples; 382 wav_writer_write_int16(num_samples, data); 383 if (num_samples_to_write == 0){ 384 wav_writer_close(); 385 } 386 #endif /* SCO_WAV_FILENAME */ 387 } 388 389 static void sco_demo_init_mSBC(void){ 390 printf("SCO Demo: Init mSBC\n"); 391 392 btstack_sbc_decoder_init(&decoder_state, SBC_MODE_mSBC, &handle_pcm_data, NULL); 393 hfp_msbc_init(); 394 395 #ifdef SCO_WAV_FILENAME 396 num_samples_to_write = MSBC_SAMPLE_RATE * SCO_WAV_DURATION_IN_SECONDS; 397 wav_writer_open(SCO_WAV_FILENAME, 1, MSBC_SAMPLE_RATE); 398 #endif 399 400 audio_initialize(MSBC_SAMPLE_RATE); 401 } 402 403 static void sco_demo_receive_mSBC(uint8_t * packet, uint16_t size){ 404 btstack_sbc_decoder_process_data(&decoder_state, (packet[1] >> 4) & 3, packet+3, size-3); 405 } 406 407 void sco_demo_fill_payload_mSBC(uint8_t * payload_buffer, uint16_t sco_payload_length){ 408 409 #if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE 410 #define REFILL_SAMPLES 16 411 // re-fill with sine 412 uint16_t samples_free = btstack_ring_buffer_bytes_free(&audio_input_ring_buffer) / 2; 413 while (samples_free > 0){ 414 int16_t samples_buffer[REFILL_SAMPLES]; 415 uint16_t samples_to_add = btstack_min(samples_free, REFILL_SAMPLES); 416 sco_demo_sine_wave_int16_at_16000_hz_host_endian(samples_to_add, samples_buffer); 417 btstack_ring_buffer_write(&audio_input_ring_buffer, (uint8_t *)samples_buffer, samples_to_add * 2); 418 samples_free -= samples_to_add; 419 } 420 #endif 421 422 // resume if pre-buffer is filled 423 if (audio_input_paused){ 424 if (btstack_ring_buffer_bytes_available(&audio_input_ring_buffer) >= MSBC_PA_PREBUFFER_BYTES){ 425 // resume sending 426 audio_input_paused = 0; 427 } 428 } 429 if (!audio_input_paused){ 430 int num_samples = hfp_msbc_num_audio_samples_per_frame(); 431 btstack_assert(num_samples <= MAX_NUM_MSBC_SAMPLES); 432 if (hfp_msbc_can_encode_audio_frame_now() && btstack_ring_buffer_bytes_available(&audio_input_ring_buffer) >= (unsigned int)(num_samples * BYTES_PER_FRAME)){ 433 int16_t sample_buffer[MAX_NUM_MSBC_SAMPLES]; 434 uint32_t bytes_read; 435 btstack_ring_buffer_read(&audio_input_ring_buffer, (uint8_t*) sample_buffer, num_samples * BYTES_PER_FRAME, &bytes_read); 436 hfp_msbc_encode_audio_frame(sample_buffer); 437 num_audio_frames++; 438 } 439 btstack_assert(hfp_msbc_num_bytes_in_stream() >= sco_payload_length); 440 } 441 442 // get data from encoder, fill with 0 if not enough 443 if (audio_input_paused || hfp_msbc_num_bytes_in_stream() < sco_payload_length){ 444 // just send '0's 445 memset(payload_buffer, 0, sco_payload_length); 446 audio_input_paused = 1; 447 } else { 448 hfp_msbc_read_from_stream(payload_buffer, sco_payload_length); 449 } 450 } 451 452 #endif /* ENABLE_HFP_WIDE_BAND_SPEECH */ 453 454 void sco_demo_init(void){ 455 456 #ifdef ENABLE_CLASSIC_LEGACY_CONNECTIONS_FOR_SCO_DEMOS 457 printf("Disable BR/EDR Secure Connctions due to incompatibilities with SCO connections\n"); 458 gap_secure_connections_enable(false); 459 #endif 460 461 // status 462 #if SCO_DEMO_MODE == SCO_DEMO_MODE_MICROPHONE 463 printf("SCO Demo: Sending and receiving audio via btstack_audio.\n"); 464 #endif 465 #if SCO_DEMO_MODE == SCO_DEMO_MODE_SINE 466 if (btstack_audio_sink_get_instance()){ 467 printf("SCO Demo: Sending sine wave, audio output via btstack_audio.\n"); 468 } else { 469 printf("SCO Demo: Sending sine wave, hexdump received data.\n"); 470 } 471 #endif 472 473 // Set SCO for CVSD (mSBC or other codecs automatically use 8-bit transparent mode) 474 hci_set_sco_voice_setting(0x60); // linear, unsigned, 16-bit, CVSD 475 } 476 477 void sco_demo_set_codec(uint8_t codec){ 478 if (negotiated_codec == codec) return; 479 negotiated_codec = codec; 480 481 switch (negotiated_codec){ 482 case HFP_CODEC_CVSD: 483 sco_demo_init_CVSD(); 484 break; 485 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 486 case HFP_CODEC_MSBC: 487 sco_demo_init_mSBC(); 488 break; 489 #endif 490 default: 491 btstack_assert(false); 492 break; 493 } 494 } 495 496 void sco_demo_receive(uint8_t * packet, uint16_t size){ 497 static uint32_t packets = 0; 498 static uint32_t crc_errors = 0; 499 static uint32_t data_received = 0; 500 static uint32_t byte_errors = 0; 501 502 count_received++; 503 504 data_received += size - 3; 505 packets++; 506 if (data_received > 100000){ 507 printf("Summary: data %07u, packets %04u, packet with crc errors %0u, byte errors %04u\n", (unsigned int) data_received, (unsigned int) packets, (unsigned int) crc_errors, (unsigned int) byte_errors); 508 crc_errors = 0; 509 byte_errors = 0; 510 data_received = 0; 511 packets = 0; 512 } 513 514 switch (negotiated_codec){ 515 case HFP_CODEC_CVSD: 516 sco_demo_receive_CVSD(packet, size); 517 break; 518 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 519 case HFP_CODEC_MSBC: 520 sco_demo_receive_mSBC(packet, size); 521 break; 522 #endif 523 default: 524 btstack_assert(false); 525 break; 526 } 527 } 528 529 void sco_demo_send(hci_con_handle_t sco_handle){ 530 531 if (sco_handle == HCI_CON_HANDLE_INVALID) return; 532 533 int sco_packet_length = hci_get_sco_packet_length(); 534 int sco_payload_length = sco_packet_length - 3; 535 536 hci_reserve_packet_buffer(); 537 uint8_t * sco_packet = hci_get_outgoing_packet_buffer(); 538 539 switch (negotiated_codec){ 540 case HFP_CODEC_CVSD: 541 sco_demo_fill_payload_CVSD(&sco_packet[3], sco_payload_length); 542 break; 543 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 544 case HFP_CODEC_MSBC: 545 sco_demo_fill_payload_mSBC(&sco_packet[3], sco_payload_length); 546 break; 547 #endif 548 default: 549 btstack_assert(false); 550 break; 551 } 552 553 // set handle + flags 554 little_endian_store_16(sco_packet, 0, sco_handle); 555 // set len 556 sco_packet[2] = sco_payload_length; 557 // finally send packet 558 hci_send_sco_packet_buffer(sco_packet_length); 559 560 // request another send event 561 hci_request_sco_can_send_now_event(); 562 563 count_sent++; 564 if ((count_sent % SCO_REPORT_PERIOD) == 0) { 565 printf("SCO: sent %u, received %u\n", count_sent, count_received); 566 } 567 } 568 569 void sco_demo_close(void){ 570 printf("SCO demo close\n"); 571 572 printf("SCO demo statistics: "); 573 switch (negotiated_codec){ 574 case HFP_CODEC_CVSD: 575 printf("Used CVSD with PLC, number of proccesed frames: \n - %d good frames, \n - %d bad frames.\n", cvsd_plc_state.good_frames_nr, cvsd_plc_state.bad_frames_nr); 576 break; 577 #ifdef ENABLE_HFP_WIDE_BAND_SPEECH 578 case HFP_CODEC_MSBC: 579 printf("Used mSBC with PLC, number of processed frames: \n - %d good frames, \n - %d zero frames, \n - %d bad frames.\n", decoder_state.good_frames_nr, decoder_state.zero_frames_nr, decoder_state.bad_frames_nr); 580 break; 581 #endif 582 default: 583 btstack_assert(false); 584 break; 585 } 586 587 negotiated_codec = -1; 588 589 #if defined(SCO_WAV_FILENAME) 590 wav_writer_close(); 591 #endif 592 593 audio_terminate(); 594 } 595