1
0
Fork 0
forked from len0rd/rockbox

Simplify pcmbuf_beep() a little, should be no functional change but it seems to mysteriously change the PortalPlayer 'keyclick beep of death' problem into a 'barely-there keyclick' problem.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16947 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Steve Bavin 2008-04-03 14:24:37 +00:00
parent 0ab1a3b801
commit b24ed65faf

View file

@ -975,70 +975,59 @@ bool pcmbuf_insert_buffer(char *buf, int count)
in Hertz for a duration in milliseconds. */ in Hertz for a duration in milliseconds. */
void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude)
{ {
unsigned int count = 0, i = 0; unsigned int count = 0;
unsigned int i;
unsigned int interval = NATIVE_FREQUENCY / frequency; unsigned int interval = NATIVE_FREQUENCY / frequency;
unsigned int samples = NATIVE_FREQUENCY / 1000 * duration;
int32_t sample; int32_t sample;
int16_t *buf; int16_t *bufstart;
int16_t *bufptr;
int16_t *pcmbuf_end = (int16_t *)fadebuf; int16_t *pcmbuf_end = (int16_t *)fadebuf;
size_t samples = NATIVE_FREQUENCY / 1000 * duration; bool mix = pcmbuf_read != NULL && pcmbuf_read->link != NULL;
if (pcm_is_playing() && pcmbuf_read != NULL) /* Find the insertion point and set bufstart to the start of it */
if (mix)
{ {
if (pcmbuf_read->link) /* Get the next chunk */
{ char *pcmbuf_mix_buf = pcmbuf_read->link->addr;
/* Get the next chunk */ /* Give 1/8s clearance. */
char *pcmbuf_mix_buf = pcmbuf_read->link->addr; bufstart = (int16_t *)&pcmbuf_mix_buf[NATIVE_FREQUENCY * 4 / 8];
/* Give at least 1/8s clearance. */
buf = (int16_t *)&pcmbuf_mix_buf[NATIVE_FREQUENCY * 4 / 8];
}
else
{
logf("No place to beep");
return;
}
while (i++ < samples)
{
sample = *buf;
*buf++ = clip_sample_16(sample + amplitude);
if (buf > pcmbuf_end)
buf = (int16_t *)audiobuffer;
sample = *buf;
*buf++ = clip_sample_16(sample + amplitude);
/* Toggle square wav side */
if (++count >= interval)
{
count = 0;
amplitude = -amplitude;
}
if (buf > pcmbuf_end)
buf = (int16_t *)audiobuffer;
}
} }
else else
{ {
buf = (int16_t *)audiobuffer; /* Use audiobuffer */
while (i++ < samples) bufstart = (int16_t *)audiobuffer;
{ }
*buf++ = amplitude;
if (buf > pcmbuf_end)
buf = (int16_t *)audiobuffer;
*buf++ = amplitude;
/* Toggle square wav side */ /* Mix square wave into buffer */
if (++count >= interval) bufptr = bufstart;
{ for (i = 0; i < samples; ++i)
count = 0; {
amplitude = -amplitude; sample = mix ? *bufptr : 0;
} *bufptr++ = clip_sample_16(sample + amplitude);
if (buf > pcmbuf_end) if (bufptr > pcmbuf_end)
buf = (int16_t *)audiobuffer; bufptr = (int16_t *)audiobuffer;
sample = mix ? *bufptr : 0;
*bufptr++ = clip_sample_16(sample + amplitude);
if (bufptr > pcmbuf_end)
bufptr = (int16_t *)audiobuffer;
/* Toggle square wave edge */
if (++count >= interval)
{
count = 0;
amplitude = -amplitude;
} }
pcm_play_data(NULL, (unsigned char *)audiobuffer, samples * 4); }
/* Kick off playback if required */
if (!pcm_is_playing())
{
pcm_play_data(NULL, (unsigned char *)bufstart, samples * 4);
} }
} }
/* Returns pcm buffer usage in percents (0 to 100). */ /* Returns pcm buffer usage in percents (0 to 100). */
int pcmbuf_usage(void) int pcmbuf_usage(void)
{ {