Some changes

This commit is contained in:
2025-02-16 17:28:10 +01:00
parent 0fc4040ad7
commit 4d3755e2ce
18 changed files with 562 additions and 80 deletions

55
peripherals/audio.h Normal file
View File

@@ -0,0 +1,55 @@
/*
// Created by bruno on 16.2.2025.
*/
#ifndef RISCB_AUDIO_H
#define RISCB_AUDIO_H
#include <SDL2/SDL.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define SAMPLE_RATE 44100
#define NUM_SYNTH_VOICES 3
#define PCM_BUFFER_SIZE 4096
typedef enum {
WAVE_SINE,
WAVE_SQUARE,
WAVE_SAWTOOTH,
WAVE_TRIANGLE,
WAVE_NOISE
} Waveform;
typedef struct {
uint8_t volume;
uint16_t frequency;
uint8_t phase;
Waveform waveform;
} SynthVoice;
typedef struct {
uint8_t volume;
uint8_t upsample_factor;
uint8_t upsample_count;
uint16_t buffer[PCM_BUFFER_SIZE];
size_t head, tail;
} PcmVoice;
typedef struct {
SynthVoice synthVoices[NUM_SYNTH_VOICES];
PcmVoice pcmVoice;
} AudioData;
int pcm_buffer_empty(PcmVoice *pcm);
int pcm_buffer_full(PcmVoice *pcm);
void pcm_buffer_push(PcmVoice *pcm, uint16_t sample);
uint16_t pcm_buffer_pop(PcmVoice *pcm);
void audio_callback(void *userdata, Uint8 *stream, int len);
#endif //RISCB_AUDIO_H