summaryrefslogtreecommitdiff
path: root/apps/beep.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/beep.c')
-rw-r--r--apps/beep.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/apps/beep.c b/apps/beep.c
index 8ac7ccf224..25b5e0e391 100644
--- a/apps/beep.c
+++ b/apps/beep.c
@@ -21,10 +21,10 @@
21#include "config.h" 21#include "config.h"
22#include "system.h" 22#include "system.h"
23#include "settings.h" 23#include "settings.h"
24#include "dsp_core.h" /* for NATIVE_FREQUENCY */
25#include "pcm.h" 24#include "pcm.h"
26#include "pcm_mixer.h" 25#include "pcm_mixer.h"
27#include "misc.h" 26#include "misc.h"
27#include "fixedpoint.h"
28 28
29/** Beep generation, CPU optimized **/ 29/** Beep generation, CPU optimized **/
30#include "asm/beep.c" 30#include "asm/beep.c"
@@ -39,8 +39,10 @@ static uint32_t beep_amplitude; /* Amplitude of square wave generator */
39#endif 39#endif
40static int beep_count; /* Number of samples remaining to generate */ 40static int beep_count; /* Number of samples remaining to generate */
41 41
42/* Reserve enough static space for keyclick to fit */ 42#define BEEP_COUNT(fs, duration) ((fs) / 1000 * (duration))
43#define BEEP_BUF_COUNT (NATIVE_FREQUENCY / 1000 * KEYCLICK_DURATION) 43
44/* Reserve enough static space for keyclick to fit in worst case */
45#define BEEP_BUF_COUNT BEEP_COUNT(PLAY_SAMPR_MAX, KEYCLICK_DURATION)
44static int16_t beep_buf[BEEP_BUF_COUNT*2] IBSS_ATTR __attribute__((aligned(4))); 46static int16_t beep_buf[BEEP_BUF_COUNT*2] IBSS_ATTR __attribute__((aligned(4)));
45 47
46/* Callback to generate the beep frames - also don't want inlining of 48/* Callback to generate the beep frames - also don't want inlining of
@@ -75,9 +77,10 @@ void beep_play(unsigned int frequency, unsigned int duration,
75 amplitude = INT16_MAX; 77 amplitude = INT16_MAX;
76 78
77 /* Setup the parameters for the square wave generator */ 79 /* Setup the parameters for the square wave generator */
80 uint32_t fout = mixer_get_frequency();
78 beep_phase = 0; 81 beep_phase = 0;
79 beep_step = 0xffffffffu / NATIVE_FREQUENCY * frequency; 82 beep_step = fp_div(frequency, fout, 32);
80 beep_count = NATIVE_FREQUENCY / 1000 * duration; 83 beep_count = BEEP_COUNT(fout, duration);
81 84
82#ifdef BEEP_GENERIC 85#ifdef BEEP_GENERIC
83 beep_amplitude = amplitude; 86 beep_amplitude = amplitude;