Output I2S audio with PIO/DMA

Requires a MAX98357A amplifier and a 2W 8ohms speaker
This commit is contained in:
Vincent Mistler
2022-12-02 17:24:39 +00:00
parent a9f54dc37d
commit 29a04ad832
8 changed files with 285 additions and 31 deletions
+5 -7
View File
@@ -365,19 +365,17 @@ static void update_noise(int16_t *samples)
/**
* SDL2 style audio callback function.
*/
void audio_callback(void *userdata, uint8_t *stream, int len)
void audio_callback(void *userdata, int16_t *stream, size_t len)
{
int16_t *samples = (int16_t *)stream;
/* Appease unused variable warning. */
(void)userdata;
memset(stream, 0, len);
update_square(samples, 0);
update_square(samples, 1);
update_wave(samples);
update_noise(samples);
update_square(stream, 0);
update_square(stream, 1);
update_wave(stream);
update_noise(stream);
}
static void chan_trigger(uint_fast8_t i)
+3 -2
View File
@@ -9,19 +9,20 @@
#include <stdint.h>
#define AUDIO_SAMPLE_RATE 32768
#define AUDIO_SAMPLE_RATE 44100
#define DMG_CLOCK_FREQ 4194304.0
#define SCREEN_REFRESH_CYCLES 70224.0
#define VERTICAL_SYNC (DMG_CLOCK_FREQ/SCREEN_REFRESH_CYCLES)
#define AUDIO_SAMPLES ((unsigned)(AUDIO_SAMPLE_RATE / VERTICAL_SYNC))
#define AUDIO_BUFFER_SIZE_BYTES (AUDIO_SAMPLES*4)
/**
* Fill allocated buffer "data" with "len" number of 32-bit floating point
* samples (native endian order) in stereo interleaved format.
*/
void audio_callback(void *ptr, uint8_t *data, int len);
void audio_callback(void *ptr, int16_t *data, size_t len);
/**
* Read audio register at given address "addr".