diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2012-04-26 15:57:07 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2012-04-26 16:04:44 -0400 |
commit | cfc32fe75f51f4feef4d4308220f46c56bceefa3 (patch) | |
tree | 8c5bf11f0067ef655e8e7048ddf97614314808d5 | |
parent | e5c3327cefb4e6f3a9089ad30fd12bb8f40a0658 (diff) | |
download | rockbox-cfc32fe75f51f4feef4d4308220f46c56bceefa3.tar.gz rockbox-cfc32fe75f51f4feef4d4308220f46c56bceefa3.zip |
Adjust some typing in voice_thread.c. Constants are also counts, not sizes.
Change-Id: I05700f6c87c775e98f05323d2ab0550fad8befd7
-rw-r--r-- | apps/voice_thread.c | 36 | ||||
-rw-r--r-- | apps/voice_thread.h | 2 |
2 files changed, 21 insertions, 17 deletions
diff --git a/apps/voice_thread.c b/apps/voice_thread.c index 56d67a2284..3a2436c118 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c | |||
@@ -59,7 +59,7 @@ | |||
59 | latency */ | 59 | latency */ |
60 | #define PRIORITY_VOICE (PRIORITY_PLAYBACK-4) | 60 | #define PRIORITY_VOICE (PRIORITY_PLAYBACK-4) |
61 | 61 | ||
62 | #define VOICE_FRAME_SIZE 320 /* Samples / frame */ | 62 | #define VOICE_FRAME_COUNT 320 /* Samples / frame */ |
63 | #define VOICE_SAMPLE_RATE 16000 /* Sample rate in HZ */ | 63 | #define VOICE_SAMPLE_RATE 16000 /* Sample rate in HZ */ |
64 | #define VOICE_SAMPLE_DEPTH 16 /* Sample depth in bits */ | 64 | #define VOICE_SAMPLE_DEPTH 16 /* Sample depth in bits */ |
65 | 65 | ||
@@ -81,11 +81,11 @@ static struct queue_sender_list voice_queue_sender_list SHAREDBSS_ATTR; | |||
81 | static int quiet_counter SHAREDDATA_ATTR = 0; | 81 | static int quiet_counter SHAREDDATA_ATTR = 0; |
82 | 82 | ||
83 | /* Buffer for decoded samples */ | 83 | /* Buffer for decoded samples */ |
84 | static spx_int16_t voice_output_buf[VOICE_FRAME_SIZE] CACHEALIGN_ATTR; | 84 | static spx_int16_t voice_output_buf[VOICE_FRAME_COUNT] MEM_ALIGN_ATTR; |
85 | 85 | ||
86 | #define VOICE_PCM_FRAME_COUNT ((NATIVE_FREQUENCY*VOICE_FRAME_SIZE + \ | 86 | #define VOICE_PCM_FRAME_COUNT ((NATIVE_FREQUENCY*VOICE_FRAME_COUNT + \ |
87 | VOICE_SAMPLE_RATE) / VOICE_SAMPLE_RATE) | 87 | VOICE_SAMPLE_RATE) / VOICE_SAMPLE_RATE) |
88 | #define VOICE_PCM_FRAME_SIZE (VOICE_PCM_FRAME_COUNT*4) | 88 | #define VOICE_PCM_FRAME_SIZE (VOICE_PCM_FRAME_COUNT*2*sizeof (int16_t)) |
89 | 89 | ||
90 | /* Default number of native-frequency PCM frames to queue - adjust as | 90 | /* Default number of native-frequency PCM frames to queue - adjust as |
91 | necessary per-target */ | 91 | necessary per-target */ |
@@ -93,7 +93,7 @@ static spx_int16_t voice_output_buf[VOICE_FRAME_SIZE] CACHEALIGN_ATTR; | |||
93 | 93 | ||
94 | /* Might have lookahead and be skipping samples, so size is needed */ | 94 | /* Might have lookahead and be skipping samples, so size is needed */ |
95 | static size_t voicebuf_sizes[VOICE_FRAMES]; | 95 | static size_t voicebuf_sizes[VOICE_FRAMES]; |
96 | static uint32_t (* voicebuf)[VOICE_PCM_FRAME_COUNT]; | 96 | static int16_t (* voicebuf)[2*VOICE_PCM_FRAME_COUNT]; |
97 | static unsigned int cur_buf_in, cur_buf_out; | 97 | static unsigned int cur_buf_in, cur_buf_out; |
98 | 98 | ||
99 | /* Voice processing states */ | 99 | /* Voice processing states */ |
@@ -165,7 +165,8 @@ static void voice_pcm_callback(const void **start, size_t *size) | |||
165 | /* Start playback of voice channel if not already playing */ | 165 | /* Start playback of voice channel if not already playing */ |
166 | static void voice_start_playback(void) | 166 | static void voice_start_playback(void) |
167 | { | 167 | { |
168 | if (mixer_channel_status(PCM_MIXER_CHAN_VOICE) != CHANNEL_STOPPED) | 168 | if (mixer_channel_status(PCM_MIXER_CHAN_VOICE) != CHANNEL_STOPPED || |
169 | voice_unplayed_frames() <= 0) | ||
169 | return; | 170 | return; |
170 | 171 | ||
171 | unsigned int i = cur_buf_out % VOICE_FRAMES; | 172 | unsigned int i = cur_buf_out % VOICE_FRAMES; |
@@ -181,7 +182,7 @@ static void voice_stop_playback(void) | |||
181 | } | 182 | } |
182 | 183 | ||
183 | /* Grab a free PCM frame */ | 184 | /* Grab a free PCM frame */ |
184 | static uint32_t * voice_buf_get(void) | 185 | static uint16_t * voice_buf_get(void) |
185 | { | 186 | { |
186 | if (voice_unplayed_frames() >= VOICE_FRAMES) | 187 | if (voice_unplayed_frames() >= VOICE_FRAMES) |
187 | { | 188 | { |
@@ -194,9 +195,13 @@ static uint32_t * voice_buf_get(void) | |||
194 | } | 195 | } |
195 | 196 | ||
196 | /* Commit a frame returned by voice_buf_get and set the actual size */ | 197 | /* Commit a frame returned by voice_buf_get and set the actual size */ |
197 | static void voice_buf_commit(size_t size) | 198 | static void voice_buf_commit(int count) |
198 | { | 199 | { |
199 | voicebuf_sizes[cur_buf_in++ % VOICE_FRAMES] = size; | 200 | if (count > 0) |
201 | { | ||
202 | voicebuf_sizes[cur_buf_in++ % VOICE_FRAMES] = | ||
203 | count * 2 * sizeof (int16_t); | ||
204 | } | ||
200 | } | 205 | } |
201 | 206 | ||
202 | /* Stop any current clip and start playing a new one */ | 207 | /* Stop any current clip and start playing a new one */ |
@@ -382,10 +387,10 @@ static enum voice_state voice_decode(struct voice_thread_data *td) | |||
382 | yield(); | 387 | yield(); |
383 | 388 | ||
384 | /* Output the decoded frame */ | 389 | /* Output the decoded frame */ |
385 | td->count = VOICE_FRAME_SIZE - td->lookahead; | 390 | td->count = VOICE_FRAME_COUNT - td->lookahead; |
386 | td->src[0] = (const char *)&voice_output_buf[td->lookahead]; | 391 | td->src[0] = (const char *)&voice_output_buf[td->lookahead]; |
387 | td->src[1] = NULL; | 392 | td->src[1] = NULL; |
388 | td->lookahead -= MIN(VOICE_FRAME_SIZE, td->lookahead); | 393 | td->lookahead -= MIN(VOICE_FRAME_COUNT, td->lookahead); |
389 | 394 | ||
390 | if (td->count > 0) | 395 | if (td->count > 0) |
391 | return VOICE_STATE_BUFFER_INSERT; | 396 | return VOICE_STATE_BUFFER_INSERT; |
@@ -404,8 +409,7 @@ static enum voice_state voice_buffer_insert(struct voice_thread_data *td) | |||
404 | 409 | ||
405 | if (dest != NULL) | 410 | if (dest != NULL) |
406 | { | 411 | { |
407 | voice_buf_commit(dsp_process(td->dsp, dest, td->src, td->count) | 412 | voice_buf_commit(dsp_process(td->dsp, dest, td->src, td->count)); |
408 | * sizeof (int32_t)); | ||
409 | return VOICE_STATE_DECODE; | 413 | return VOICE_STATE_DECODE; |
410 | } | 414 | } |
411 | 415 | ||
@@ -464,10 +468,10 @@ void voice_thread_set_priority(int priority) | |||
464 | #endif | 468 | #endif |
465 | 469 | ||
466 | /* Initialize voice PCM buffer and return size, allocated from the end */ | 470 | /* Initialize voice PCM buffer and return size, allocated from the end */ |
467 | size_t voicebuf_init(unsigned char *bufend) | 471 | size_t voicebuf_init(void *bufend) |
468 | { | 472 | { |
469 | size_t size = VOICE_FRAMES * VOICE_PCM_FRAME_SIZE; | 473 | size_t size = VOICE_FRAMES * sizeof (voicebuf[0]); |
470 | cur_buf_out = cur_buf_in = 0; | 474 | cur_buf_out = cur_buf_in = 0; |
471 | voicebuf = (uint32_t (*)[VOICE_PCM_FRAME_COUNT])(bufend - size); | 475 | voicebuf = bufend - size; |
472 | return size; | 476 | return size; |
473 | } | 477 | } |
diff --git a/apps/voice_thread.h b/apps/voice_thread.h index 4e4af1fc5c..e88630439b 100644 --- a/apps/voice_thread.h +++ b/apps/voice_thread.h | |||
@@ -39,6 +39,6 @@ void voice_thread_init(void) INIT_ATTR; | |||
39 | void voice_thread_set_priority(int priority); | 39 | void voice_thread_set_priority(int priority); |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | size_t voicebuf_init(unsigned char *bufend); | 42 | size_t voicebuf_init(void *bufend); |
43 | 43 | ||
44 | #endif /* VOICE_THREAD_H */ | 44 | #endif /* VOICE_THREAD_H */ |