/* Generates a constant square wave sound with a given frequency in Hertz for a duration in milliseconds */ void beep_play(unsigned int frequency, unsigned int duration, unsigned int amplitude) { mixer_channel_stop(PCM_MIXER_CHAN_BEEP); if (frequency == 0 || duration == 0 || amplitude == 0) return; if (amplitude > INT16_MAX) amplitude = INT16_MAX; /* Setup the parameters for the square wave generator */ beep_phase = 0; beep_step = 0xffffffffu / NATIVE_FREQUENCY * frequency; beep_count = NATIVE_FREQUENCY / 1000 * duration; #ifdef BEEP_GENERIC beep_amplitude = amplitude; #else /* Optimized routines do XOR with phase sign bit in both channels at once */ beep_amplitude = amplitude | (amplitude << 16); /* Word:|AMP16|AMP16| */ #endif /* If it fits - avoid cb overhead */ const void *start; size_t size; /* Generate first frame here */ beep_get_more(&start, &size); mixer_channel_set_amplitude(PCM_MIXER_CHAN_BEEP, MIX_AMP_UNITY); mixer_channel_play_data(PCM_MIXER_CHAN_BEEP, beep_count ? beep_get_more : NULL, start, size); }
/* Stop the voice channel */ static void voice_stop_playback(void) { mixer_channel_stop(PCM_MIXER_CHAN_VOICE); cur_buf_in = cur_buf_out = 0; }