diff options
Diffstat (limited to 'apps/voice_thread.c')
-rw-r--r-- | apps/voice_thread.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/apps/voice_thread.c b/apps/voice_thread.c index 72ecb3741e..dcb7eef224 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c | |||
@@ -63,9 +63,17 @@ | |||
63 | latency */ | 63 | latency */ |
64 | #define PRIORITY_VOICE (PRIORITY_PLAYBACK-4) | 64 | #define PRIORITY_VOICE (PRIORITY_PLAYBACK-4) |
65 | 65 | ||
66 | /* A speex frame generally consists of 20ms of audio | ||
67 | * (http://www.speex.org/docs/manual/speex-manual/node10.html) | ||
68 | * for wideband mode this results in 320 samples of decoded PCM. | ||
69 | */ | ||
66 | #define VOICE_FRAME_COUNT 320 /* Samples / frame */ | 70 | #define VOICE_FRAME_COUNT 320 /* Samples / frame */ |
67 | #define VOICE_SAMPLE_RATE 16000 /* Sample rate in HZ */ | 71 | #define VOICE_SAMPLE_RATE 16000 /* Sample rate in HZ */ |
68 | #define VOICE_SAMPLE_DEPTH 16 /* Sample depth in bits */ | 72 | #define VOICE_SAMPLE_DEPTH 16 /* Sample depth in bits */ |
73 | /* The max. wideband bitrate is 42.4 kbps | ||
74 | * (http://www.speex.org/docs/manual/speex-manual/node11.html). For 20ms | ||
75 | * this gives a maximum of 106 bytes for an encoded speex frame */ | ||
76 | #define VOICE_MAX_ENCODED_FRAME_SIZE 106 | ||
69 | 77 | ||
70 | /* Voice thread variables */ | 78 | /* Voice thread variables */ |
71 | static unsigned int voice_thread_id = 0; | 79 | static unsigned int voice_thread_id = 0; |
@@ -449,6 +457,23 @@ static enum voice_state voice_decode(struct voice_thread_data *td) | |||
449 | } | 457 | } |
450 | else | 458 | else |
451 | { | 459 | { |
460 | if (td->vi.size > VOICE_MAX_ENCODED_FRAME_SIZE | ||
461 | && td->bits.charPtr > (td->vi.size - VOICE_MAX_ENCODED_FRAME_SIZE) | ||
462 | && td->vi.get_more != NULL) | ||
463 | { | ||
464 | /* request more data _before_ running out of data (requesting | ||
465 | * more after the fact prevents speex from successful decoding) | ||
466 | * place a hint telling the callback how much of the | ||
467 | * previous buffer we have consumed such that it can rewind | ||
468 | * as necessary */ | ||
469 | int bitPtr = td->bits.bitPtr; | ||
470 | td->vi.size = td->bits.charPtr; | ||
471 | td->vi.get_more(&td->vi.start, &td->vi.size); | ||
472 | speex_bits_set_bit_buffer(&td->bits, (void *)td->vi.start, | ||
473 | td->vi.size); | ||
474 | td->bits.bitPtr = bitPtr; | ||
475 | } | ||
476 | |||
452 | yield(); | 477 | yield(); |
453 | 478 | ||
454 | /* Output the decoded frame */ | 479 | /* Output the decoded frame */ |