summaryrefslogtreecommitdiffstats
path: root/apps/voice_thread.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-01-21 23:22:37 +0100
committerThomas Martitz <kugel@rockbox.org>2014-02-02 19:40:39 +0100
commite5eb74592eeff013d818ff0c56692b220dd53fbc (patch)
treee954624b31806dc57f59c8d755d866c6abc9f8f9 /apps/voice_thread.c
parentaf02a674c539ee76260be543c000637ffa6ce2af (diff)
downloadrockbox-e5eb74592eeff013d818ff0c56692b220dd53fbc.tar.gz
rockbox-e5eb74592eeff013d818ff0c56692b220dd53fbc.tar.bz2
rockbox-e5eb74592eeff013d818ff0c56692b220dd53fbc.zip
talk/voice: Reduce the size of the commit buffer.
The voice engine can now request more voice data during decoding, it does not require the entire clip to be available before start of decoding anymore. Therefore the commit buffer does not need to hold an entire voice clip anymore, and can be made greatly smaller. Change-Id: I3eca9026448e725b9b8d0dae1efca0ad185371da
Diffstat (limited to 'apps/voice_thread.c')
-rw-r--r--apps/voice_thread.c25
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 @@
latency */
#define PRIORITY_VOICE (PRIORITY_PLAYBACK-4)
+/* A speex frame generally consists of 20ms of audio
+ * (http://www.speex.org/docs/manual/speex-manual/node10.html)
+ * for wideband mode this results in 320 samples of decoded PCM.
+ */
#define VOICE_FRAME_COUNT 320 /* Samples / frame */
#define VOICE_SAMPLE_RATE 16000 /* Sample rate in HZ */
#define VOICE_SAMPLE_DEPTH 16 /* Sample depth in bits */
+/* The max. wideband bitrate is 42.4 kbps
+ * (http://www.speex.org/docs/manual/speex-manual/node11.html). For 20ms
+ * this gives a maximum of 106 bytes for an encoded speex frame */
+#define VOICE_MAX_ENCODED_FRAME_SIZE 106
/* Voice thread variables */
static unsigned int voice_thread_id = 0;
@@ -449,6 +457,23 @@ static enum voice_state voice_decode(struct voice_thread_data *td)
}
else
{
+ if (td->vi.size > VOICE_MAX_ENCODED_FRAME_SIZE
+ && td->bits.charPtr > (td->vi.size - VOICE_MAX_ENCODED_FRAME_SIZE)
+ && td->vi.get_more != NULL)
+ {
+ /* request more data _before_ running out of data (requesting
+ * more after the fact prevents speex from successful decoding)
+ * place a hint telling the callback how much of the
+ * previous buffer we have consumed such that it can rewind
+ * as necessary */
+ int bitPtr = td->bits.bitPtr;
+ td->vi.size = td->bits.charPtr;
+ td->vi.get_more(&td->vi.start, &td->vi.size);
+ speex_bits_set_bit_buffer(&td->bits, (void *)td->vi.start,
+ td->vi.size);
+ td->bits.bitPtr = bitPtr;
+ }
+
yield();
/* Output the decoded frame */