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