More progress on audio and rendering

This commit is contained in:
2025-06-02 18:04:15 +02:00
parent 84805b92cb
commit 0c3e2aa730
14 changed files with 569 additions and 264 deletions

View File

@@ -9,9 +9,18 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "../tiles/tile.h"
#define SAMPLE_RATE 44100
#define NUM_SYNTH_VOICES 256
#define SMOOTHING_FACTOR 0.001f
typedef struct {
float timeSec; // When to trigger this event
uint8_t type; // 0 = Note On, 1 = Note Off
uint8_t note;
uint8_t velocity;
} MidiEvent;
typedef enum Waveform {
WAVE_SINE,
@@ -23,16 +32,18 @@ typedef enum Waveform {
typedef struct SynthVoice {
Waveform waveform;
uint8_t phase;
double phase;
uint16_t frequency;
uint8_t volume;
SDL_Rect sourceRect;
MiniRect sourceRect;
float smoothedAmp; // a float that holds the exponentially smoothed amplitude
} SynthVoice;
typedef struct AudioData {
SynthVoice synthVoices[NUM_SYNTH_VOICES];
SDL_Rect *playerRect;
float maxPanDistance;
uint64_t totalSamples;
} AudioData;
extern AudioData audioData;
@@ -41,4 +52,6 @@ void audio_callback(void *userdata, Uint8 *stream, int len);
uint16_t getAvailableChannel();
void load_midi_file(const char *path);
#endif //RISCB_AUDIO_H