diff options
Diffstat (limited to 'include/sound.h')
-rw-r--r-- | include/sound.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/include/sound.h b/include/sound.h index f5124aebbd..62fef106ee 100644 --- a/include/sound.h +++ b/include/sound.h @@ -42,4 +42,36 @@ static inline int beep_cancel(void) return sound_card_beep_cancel(sound_card_get_default()); } + +/* + * Synthesizers all have the same prototype, but their implementation + * is replaced with a gain-adjusted square wave if CONFIG_SYNTH_SQUARES=y. + * This is to support PCM beeping on systems, where sine generation may + * spend to much time in the poller. + */ +typedef void synth_t(unsigned freq, s16 amplitude, s16 *stream, + unsigned sample_rate, unsigned nsamples); + +#ifdef CONFIG_SYNTH_SQUARES +#define SYNTH(fn, volume_percent) \ + static inline void fn(unsigned f, s16 amplitude, s16 *s, \ + unsigned r, unsigned n) { \ + synth_t __synth_square; \ + amplitude = amplitude * volume_percent / 100; \ + __synth_square(f, amplitude, s, r, n); \ + } \ + synth_t __##fn +#else +#define SYNTH(fn, volume_percent) \ + static inline void fn(unsigned f, s16 a, s16 *s, \ + unsigned r, unsigned n) { \ + synth_t __##fn; \ + __##fn(f, a, s, r, n); \ + } \ + synth_t __##fn +#endif + +SYNTH(synth_square, 100); /* square wave always has full amplitude */ +SYNTH(synth_sin, 64); /* ∫₀¹ sin(πx) dx ≈ 64% */ + #endif |