summaryrefslogtreecommitdiffstats
path: root/apps/pcmbuf.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-02-07 00:51:50 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-02-07 00:51:50 +0000
commitaba6ca0881d1481b4047b2d7834d70ca2eb5c64b (patch)
tree6635b98840dcf4936b3c1ca641c00c32ea1b3e7f /apps/pcmbuf.c
parentdd50c863e60488662dee8f28f7292389ade42bac (diff)
downloadrockbox-aba6ca0881d1481b4047b2d7834d70ca2eb5c64b.tar.gz
rockbox-aba6ca0881d1481b4047b2d7834d70ca2eb5c64b.tar.bz2
rockbox-aba6ca0881d1481b4047b2d7834d70ca2eb5c64b.zip
Fix resampling clicking as much as possible at the moment. 1) Upsampling clicked because of size inaccuracies returned by DSP. Fix by simplifying audio system to use per-channel sample count from codec to pcm buffer. 2) Downsampling affected by 1) and was often starting passed the end of the data when not enough was available to generate an output sample. Fix by clamping input range to last sample in buffer and using the last sample value in the buffer. A perfect fix will require a double buffering scheme on the resampler to sufficient data during small data transients on both ends at all times of the down ratio on input and the up ratio on output.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12218 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/pcmbuf.c')
-rw-r--r--apps/pcmbuf.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c
index f9d60e9b58..e2b1d7f87b 100644
--- a/apps/pcmbuf.c
+++ b/apps/pcmbuf.c
@@ -791,21 +791,20 @@ static bool prepare_insert(size_t length)
return true;
}
-void* pcmbuf_request_buffer(size_t length, size_t *realsize)
+void* pcmbuf_request_buffer(int *count)
{
if (crossfade_init)
crossfade_start();
if (crossfade_active) {
- *realsize = MIN(length, PCMBUF_MIX_CHUNK);
+ *count = MIN(*count, PCMBUF_MIX_CHUNK/4);
return fadebuf;
}
else
{
- if(prepare_insert(length))
+ if(prepare_insert(*count << 2))
{
size_t audiobuffer_index = audiobuffer_pos + audiobuffer_fillpos;
- *realsize = length;
if (pcmbuf_size - audiobuffer_index >= PCMBUF_MIN_CHUNK)
{
/* Usual case, there's space here */
@@ -821,34 +820,31 @@ void* pcmbuf_request_buffer(size_t length, size_t *realsize)
}
else
{
- *realsize = 0;
return NULL;
}
}
}
-void* pcmbuf_request_voice_buffer(size_t length, size_t *realsize, bool mix)
+void* pcmbuf_request_voice_buffer(int *count, bool mix)
{
if (mix)
{
if (pcmbuf_read == NULL)
{
- *realsize = 0;
return NULL;
}
else if (pcmbuf_mix_chunk || pcmbuf_read->link)
{
- *realsize = MIN(length, PCMBUF_MIX_CHUNK);
+ *count = MIN(*count, PCMBUF_MIX_CHUNK/4);
return voicebuf;
}
else
{
- *realsize = 0;
return NULL;
}
}
else
- return pcmbuf_request_buffer(length, realsize);
+ return pcmbuf_request_buffer(count);
}
bool pcmbuf_is_crossfade_active(void)
@@ -856,8 +852,10 @@ bool pcmbuf_is_crossfade_active(void)
return crossfade_active || crossfade_init;
}
-void pcmbuf_write_complete(size_t length)
+void pcmbuf_write_complete(int count)
{
+ size_t length = (size_t)(unsigned int)count << 2;
+
if (crossfade_active)
{
flush_crossfade(fadebuf, length);
@@ -874,8 +872,10 @@ void pcmbuf_write_complete(size_t length)
}
#if 0
-bool pcmbuf_insert_buffer(char *buf, size_t length)
+bool pcmbuf_insert_buffer(char *buf, int count)
{
+ size_t length = (size_t)(unsigned int)count << 2;
+
if (crossfade_active)
{
flush_crossfade(buf, length);
@@ -980,7 +980,7 @@ int pcmbuf_mix_free(void)
return 100;
}
-void pcmbuf_mix_voice(size_t length)
+void pcmbuf_mix_voice(int count)
{
short *ibuf = (short *)voicebuf;
short *obuf;
@@ -998,9 +998,9 @@ void pcmbuf_mix_voice(size_t length)
obuf = (short *)pcmbuf_mix_chunk->addr;
chunk_samples = pcmbuf_mix_chunk->size / 2;
- length /= 2;
+ count <<= 1;
- while (length-- > 0) {
+ while (count-- > 0) {
int sample = *ibuf++;
if (pcmbuf_mix_sample >= chunk_samples)
{