2023-06-07 23:40:48 +00:00
|
|
|
#include "audio"
|
|
|
|
#include <generated/csr.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#ifdef CSR_AUDIO_BASE
|
|
|
|
// Set all oscillators to (0Hz, sawtooth)
|
|
|
|
void reset_audio(void) {
|
2023-06-25 11:15:05 +00:00
|
|
|
for (int i = 0; i < 32; i++) {
|
2023-06-07 23:40:48 +00:00
|
|
|
audio_osc_write(i);
|
|
|
|
audio_tf_write(0);
|
|
|
|
audio_wav_write(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set oscillator `osc` to waveform `wave`
|
2023-06-08 00:37:59 +00:00
|
|
|
void set_wave(uint32_t osc, uint32_t wave) {
|
2023-06-07 23:40:48 +00:00
|
|
|
audio_osc_write(osc);
|
|
|
|
audio_wav_write(wave);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set oscillator `osc` to frequency `freq`Hz
|
2023-06-08 00:37:59 +00:00
|
|
|
void set_freq(uint32_t osc, uint32_t freq) {
|
2023-06-07 23:40:48 +00:00
|
|
|
audio_osc_write(osc);
|
2023-06-08 00:25:02 +00:00
|
|
|
audio_tf_write(freq);
|
2023-06-07 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set oscillator `osc` to waveform `wave` at frequency `freq`Hz
|
2023-06-08 00:37:59 +00:00
|
|
|
void audio(uint32_t osc, uint32_t wave, uint32_t freq) {
|
2023-06-07 23:40:48 +00:00
|
|
|
audio_osc_write(osc);
|
|
|
|
audio_wav_write(wave);
|
2023-06-08 00:25:02 +00:00
|
|
|
audio_tf_write(freq);
|
2023-06-07 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set oscillator `osc` to waveform `wave` at frequency `freq`Hz for `ms` milliseconds
|
2023-06-08 00:37:59 +00:00
|
|
|
void timed_freq(uint32_t osc, uint32_t freq, unsigned int ms) {
|
2023-06-07 23:40:48 +00:00
|
|
|
audio_osc_write(osc);
|
2023-06-08 00:25:02 +00:00
|
|
|
audio_tf_write(freq);
|
2023-06-07 23:40:48 +00:00
|
|
|
busy_wait(ms);
|
|
|
|
audio_tf_write(0);
|
|
|
|
}
|
|
|
|
#endif
|