diff options
| author | Michael Sevakis <jethead71@rockbox.org> | 2008-12-07 00:07:47 +0000 |
|---|---|---|
| committer | Michael Sevakis <jethead71@rockbox.org> | 2008-12-07 00:07:47 +0000 |
| commit | 89da4328a07c8736c42843607a3f3bf91c17601d (patch) | |
| tree | cbd5d6580b2c62dad5830c043d9284ff15cf7bdf /apps | |
| parent | 3648e8705402ce5a0af2125987f12c884b540eea (diff) | |
| download | rockbox-89da4328a07c8736c42843607a3f3bf91c17601d.zip rockbox-89da4328a07c8736c42843607a3f3bf91c17601d.tar.gz rockbox-89da4328a07c8736c42843607a3f3bf91c17601d.tar.bz2 rockbox-89da4328a07c8736c42843607a3f3bf91c17601d.tar.xz | |
Meg F/X can beep and click using a hardware timer so let us try it out. To match things up better, fix PCM beeping to give correct frequency (and get a pointer wrap bug too). Do some minor adjustments to compensate for corrections.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19355 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/action.c | 2 | ||||
| -rw-r--r-- | apps/pcmbuf.c | 27 | ||||
| -rw-r--r-- | apps/playback.c | 4 |
3 files changed, 15 insertions, 18 deletions
diff --git a/apps/action.c b/apps/action.c index 5ceeeb8..5f845ab 100644 --- a/apps/action.c +++ b/apps/action.c @@ -130,7 +130,7 @@ static int get_action_worker(int context, int timeout, /* Produce keyclick */ if (global_settings.keyclick && !(button & BUTTON_REL)) if (!(button & BUTTON_REPEAT) || global_settings.keyclick_repeats) - pcmbuf_beep(5000, 2, 2500*global_settings.keyclick); + pcmbuf_beep(4000, 2, 2500*global_settings.keyclick); #endif if ((context != last_context) && ((last_button & BUTTON_REL) == 0)) diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 61c6c45..c7db4d3 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c @@ -954,14 +954,15 @@ bool pcmbuf_insert_buffer(char *buf, int count) } #endif +#ifndef HAVE_HARDWARE_BEEP /* Generates a constant square wave sound with a given frequency in Hertz for a duration in milliseconds. */ void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) { - unsigned int count = 0; - unsigned int i; - unsigned int interval = NATIVE_FREQUENCY / frequency; - unsigned int samples = NATIVE_FREQUENCY / 1000 * duration; + int i; + unsigned int step = 0xffffffffu / NATIVE_FREQUENCY * frequency; + int32_t phase = 0; + int samples = NATIVE_FREQUENCY / 1000 * duration; int32_t sample; int16_t *bufstart; int16_t *bufptr; @@ -986,21 +987,17 @@ void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) bufptr = bufstart; for (i = 0; i < samples; ++i) { + int32_t amp = (phase >> 31) ^ (int32_t)amplitude; sample = mix ? *bufptr : 0; - *bufptr++ = clip_sample_16(sample + amplitude); - if (bufptr > pcmbuf_end) + *bufptr++ = clip_sample_16(sample + amp); + if (bufptr >= pcmbuf_end) bufptr = (int16_t *)audiobuffer; sample = mix ? *bufptr : 0; - *bufptr++ = clip_sample_16(sample + amplitude); - if (bufptr > pcmbuf_end) + *bufptr++ = clip_sample_16(sample + amp); + if (bufptr >= pcmbuf_end) bufptr = (int16_t *)audiobuffer; - /* Toggle square wave edge */ - if (++count >= interval) - { - count = 0; - amplitude = -amplitude; - } + phase += step; } /* Kick off playback if required */ @@ -1009,7 +1006,7 @@ void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude) pcm_play_data(NULL, (unsigned char *)bufstart, samples * 4); } } - +#endif /* HAVE_HARDWARE_BEEP */ /* Returns pcm buffer usage in percents (0 to 100). */ int pcmbuf_usage(void) diff --git a/apps/playback.c b/apps/playback.c index b21a3c1..50c4017 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -694,7 +694,7 @@ static void audio_skip(int direction) if (playlist_check(ci.new_track + wps_offset + direction)) { if (global_settings.beep) - pcmbuf_beep(5000, 100, 2500*global_settings.beep); + pcmbuf_beep(2000, 100, 2500*global_settings.beep); LOGFQUEUE("audio > audio Q_AUDIO_SKIP %d", direction); queue_post(&audio_queue, Q_AUDIO_SKIP, direction); @@ -706,7 +706,7 @@ static void audio_skip(int direction) { /* No more tracks. */ if (global_settings.beep) - pcmbuf_beep(1000, 100, 1000*global_settings.beep); + pcmbuf_beep(1000, 100, 1500*global_settings.beep); } } |