58 lines
1.1 KiB
C
58 lines
1.1 KiB
C
/*
|
|
// 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>
|
|
#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,
|
|
WAVE_SQUARE,
|
|
WAVE_SAWTOOTH,
|
|
WAVE_TRIANGLE,
|
|
WAVE_NOISE
|
|
} Waveform;
|
|
|
|
typedef struct SynthVoice {
|
|
Waveform waveform;
|
|
double phase;
|
|
uint16_t frequency;
|
|
uint8_t volume;
|
|
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;
|
|
|
|
void audio_callback(void *userdata, Uint8 *stream, int len);
|
|
|
|
uint16_t getAvailableChannel();
|
|
|
|
void load_midi_file(const char *path);
|
|
|
|
#endif //RISCB_AUDIO_H
|