summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/pcmbuf.c40
-rw-r--r--apps/voice_thread.c2
2 files changed, 21 insertions, 21 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index ebb058cf87..e9102b2a73 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -47,8 +47,10 @@
47 non-fatal) */ 47 non-fatal) */
48#define PCMBUF_MIN_CHUNK 4096 /* We try to never feed a chunk smaller than 48#define PCMBUF_MIN_CHUNK 4096 /* We try to never feed a chunk smaller than
49 this to the DMA */ 49 this to the DMA */
50#define PCMBUF_MIX_CHUNK 8192 /* This is the maximum size of one packet 50#define CROSSFADE_BUFSIZE 8192 /* Size of the crossfade buffer */
51 for mixing (crossfade or voice) */ 51#define AUX_BUFSIZE 512 /* Size of the aux buffer; can be 512 if no
52 resampling or timestretching is allowed in
53 the aux channel, must be 2048 otherwise */
52 54
53/* number of bytes played per second (sample rate * 2 channels * 2 bytes/sample) */ 55/* number of bytes played per second (sample rate * 2 channels * 2 bytes/sample) */
54#define BYTERATE (NATIVE_FREQUENCY * 4) 56#define BYTERATE (NATIVE_FREQUENCY * 4)
@@ -64,7 +66,7 @@
64 * by the driver code. */ 66 * by the driver code. */
65struct chunkdesc 67struct chunkdesc
66{ 68{
67 void *addr; 69 unsigned char *addr;
68 size_t size; 70 size_t size;
69 struct chunkdesc* link; 71 struct chunkdesc* link;
70 /* true if last chunk in the track */ 72 /* true if last chunk in the track */
@@ -376,7 +378,7 @@ void *pcmbuf_request_buffer(int *count)
376 /* crossfade has begun, put the new track samples in fadebuf */ 378 /* crossfade has begun, put the new track samples in fadebuf */
377 if (crossfade_active) 379 if (crossfade_active)
378 { 380 {
379 *count = MIN(*count, PCMBUF_MIX_CHUNK/4); 381 *count = MIN(*count, CROSSFADE_BUFSIZE/4);
380 return fadebuf; 382 return fadebuf;
381 } 383 }
382 else 384 else
@@ -464,9 +466,9 @@ size_t pcmbuf_init(unsigned char *bufend)
464 pcmbuf_size = get_next_required_pcmbuf_size(); 466 pcmbuf_size = get_next_required_pcmbuf_size();
465 write_chunk = (struct chunkdesc *)pcmbuf_bufend - 467 write_chunk = (struct chunkdesc *)pcmbuf_bufend -
466 NUM_CHUNK_DESCS(pcmbuf_size); 468 NUM_CHUNK_DESCS(pcmbuf_size);
467 voicebuf = (char *)write_chunk - PCMBUF_MIX_CHUNK; 469 voicebuf = (char *)write_chunk - AUX_BUFSIZE;
468#ifdef HAVE_CROSSFADE 470#ifdef HAVE_CROSSFADE
469 fadebuf = voicebuf - PCMBUF_MIX_CHUNK; 471 fadebuf = voicebuf - CROSSFADE_BUFSIZE;
470 pcmbuffer = fadebuf - pcmbuf_size; 472 pcmbuffer = fadebuf - pcmbuf_size;
471#else 473#else
472 pcmbuffer = voicebuf - pcmbuf_size; 474 pcmbuffer = voicebuf - pcmbuf_size;
@@ -623,14 +625,12 @@ static void pcmbuf_pcm_callback(unsigned char** start, size_t* size)
623 } 625 }
624 626
625 { 627 {
626 /* Send the new chunk to the PCM */ 628 /* Send the new chunk to the DMA */
627 if(read_chunk) 629 if(read_chunk)
628 { 630 {
629 size_t current_size = read_chunk->size; 631 last_chunksize = read_chunk->size;
630 632 pcmbuf_unplayed_bytes -= last_chunksize;
631 pcmbuf_unplayed_bytes -= current_size; 633 *size = last_chunksize;
632 last_chunksize = current_size;
633 *size = current_size;
634 *start = read_chunk->addr; 634 *start = read_chunk->addr;
635 } 635 }
636 else 636 else
@@ -654,7 +654,7 @@ void pcmbuf_play_start(void)
654 last_chunksize = read_chunk->size; 654 last_chunksize = read_chunk->size;
655 pcmbuf_unplayed_bytes -= last_chunksize; 655 pcmbuf_unplayed_bytes -= last_chunksize;
656 pcm_play_data(pcmbuf_pcm_callback, 656 pcm_play_data(pcmbuf_pcm_callback,
657 (unsigned char *)read_chunk->addr, last_chunksize); 657 read_chunk->addr, last_chunksize);
658 } 658 }
659} 659}
660 660
@@ -715,7 +715,7 @@ static size_t find_chunk(size_t length, struct chunkdesc **chunk)
715 length -= (*chunk)->size; 715 length -= (*chunk)->size;
716 *chunk = (*chunk)->link; 716 *chunk = (*chunk)->link;
717 } 717 }
718 return length / 2; 718 return length;
719} 719}
720 720
721/* Returns the number of bytes _NOT_ mixed/faded */ 721/* Returns the number of bytes _NOT_ mixed/faded */
@@ -808,7 +808,7 @@ static void crossfade_start(void)
808 * so find the right chunk and sample to start the crossfade */ 808 * so find the right chunk and sample to start the crossfade */
809 { 809 {
810 crossfade_sample = find_chunk(crossfade_rem - crossfade_need, 810 crossfade_sample = find_chunk(crossfade_rem - crossfade_need,
811 &crossfade_chunk); 811 &crossfade_chunk) / 2;
812 crossfade_rem = crossfade_need; 812 crossfade_rem = crossfade_need;
813 } 813 }
814 else 814 else
@@ -842,7 +842,7 @@ static void crossfade_start(void)
842 842
843 /* Find the right chunk and sample to start fading out */ 843 /* Find the right chunk and sample to start fading out */
844 fade_out_delay += crossfade_sample * 2; 844 fade_out_delay += crossfade_sample * 2;
845 fade_out_sample = find_chunk(fade_out_delay, &fade_out_chunk); 845 fade_out_sample = find_chunk(fade_out_delay, &fade_out_chunk) / 2;
846 846
847 while (fade_out_rem > 0) 847 while (fade_out_rem > 0)
848 { 848 {
@@ -869,7 +869,7 @@ static void crossfade_start(void)
869 869
870 /* Find the right chunk and sample to start fading in */ 870 /* Find the right chunk and sample to start fading in */
871 fade_in_delay += crossfade_sample * 2; 871 fade_in_delay += crossfade_sample * 2;
872 crossfade_sample = find_chunk(fade_in_delay, &crossfade_chunk); 872 crossfade_sample = find_chunk(fade_in_delay, &crossfade_chunk) / 2;
873 logf("crossfade_start done!"); 873 logf("crossfade_start done!");
874} 874}
875 875
@@ -1020,7 +1020,7 @@ void *pcmbuf_request_voice_buffer(int *count)
1020 else if (pcmbuf_usage() >= 10 && pcmbuf_mix_free() >= 30 && 1020 else if (pcmbuf_usage() >= 10 && pcmbuf_mix_free() >= 30 &&
1021 (mix_chunk || read_chunk->link)) 1021 (mix_chunk || read_chunk->link))
1022 { 1022 {
1023 *count = MIN(*count, PCMBUF_MIX_CHUNK/4); 1023 *count = MIN(*count, AUX_BUFSIZE/4);
1024 return voicebuf; 1024 return voicebuf;
1025 } 1025 }
1026 else 1026 else
@@ -1072,7 +1072,7 @@ void pcmbuf_write_voice_complete(int count)
1072 if (!mix_chunk) 1072 if (!mix_chunk)
1073 return; 1073 return;
1074 pcmbuf_mix_sample = 0; 1074 pcmbuf_mix_sample = 0;
1075 obuf = mix_chunk->addr; 1075 obuf = (int16_t *)mix_chunk->addr;
1076 chunk_samples = mix_chunk->size / 2; 1076 chunk_samples = mix_chunk->size / 2;
1077 } 1077 }
1078 sample += obuf[pcmbuf_mix_sample] >> 2; 1078 sample += obuf[pcmbuf_mix_sample] >> 2;
@@ -1088,7 +1088,7 @@ size_t pcmbuf_free(void)
1088{ 1088{
1089 if (read_chunk != NULL) 1089 if (read_chunk != NULL)
1090 { 1090 {
1091 void *read = read_chunk->addr; 1091 void *read = (void *)read_chunk->addr;
1092 void *write = &pcmbuffer[pcmbuffer_pos + pcmbuffer_fillpos]; 1092 void *write = &pcmbuffer[pcmbuffer_pos + pcmbuffer_fillpos];
1093 if (read < write) 1093 if (read < write)
1094 return (size_t)(read - write) + pcmbuf_size; 1094 return (size_t)(read - write) + pcmbuf_size;
diff --git a/apps/voice_thread.c b/apps/voice_thread.c
index a65ec566d1..05e2017b0b 100644
--- a/apps/voice_thread.c
+++ b/apps/voice_thread.c
@@ -256,7 +256,7 @@ static void voice_message(struct voice_thread_data *td)
256 return; 256 return;
257 257
258 case Q_VOICE_STOP: 258 case Q_VOICE_STOP:
259 LOGFQUEUE("voice < Q_VOICE_STOP: %ld", td->ev.data); 259 LOGFQUEUE("voice < Q_VOICE_STOP: %ld", (long)td->ev.data);
260 260
261 if (td->ev.data != 0 && !playback_is_playing()) 261 if (td->ev.data != 0 && !playback_is_playing())
262 { 262 {