2021-12-19 22:44:48 +00:00
|
|
|
// ampler.h
|
|
|
|
|
2021-12-21 04:35:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <SDL2/SDL.h>
|
2021-12-19 22:44:48 +00:00
|
|
|
|
2021-12-20 02:06:02 +00:00
|
|
|
|
2021-12-19 22:44:48 +00:00
|
|
|
typedef int8_t s8;
|
|
|
|
typedef int16_t s16;
|
|
|
|
typedef int32_t s32;
|
|
|
|
|
|
|
|
typedef uint8_t u8;
|
|
|
|
typedef uint16_t u16;
|
|
|
|
typedef uint32_t u32;
|
|
|
|
|
|
|
|
typedef float f32;
|
|
|
|
typedef double f64;
|
|
|
|
|
|
|
|
|
2021-12-21 04:35:09 +00:00
|
|
|
#define if if(
|
|
|
|
#define while while(
|
|
|
|
#define for for(
|
|
|
|
#define do )
|
|
|
|
|
|
|
|
#define or ||
|
2021-12-19 22:44:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define arraylen(a) (sizeof (a) / sizeof ((a)[0]))
|
|
|
|
|
2021-12-22 23:20:51 +00:00
|
|
|
#define foreach_ptr(TYPE, N, ARRAY) \
|
|
|
|
for int N##_i = 0; N##_i == 0; N##_i = 1 do \
|
|
|
|
for TYPE *N = &((ARRAY)[N##_i]); N != NULL; N = NULL do \
|
|
|
|
for ; N##_i < arraylen(ARRAY); N##_i += 1, N = &((ARRAY)[N##_i]) do
|
|
|
|
|
2021-12-19 22:44:48 +00:00
|
|
|
#define SAMPLE_RATE (44100)
|
|
|
|
#define CHANNELS (2)
|
|
|
|
#define FRAME_SAMPLES (SAMPLE_RATE / 60)
|
|
|
|
|
2021-12-20 02:06:02 +00:00
|
|
|
typedef struct Sound_src Sound_src;
|
|
|
|
struct Sound_src {
|
2021-12-21 01:37:24 +00:00
|
|
|
s8 *tracks[CHANNELS];
|
2021-12-20 02:06:02 +00:00
|
|
|
s32 len; // in samples
|
|
|
|
f32 pos; // position in samples
|
|
|
|
f32 speed; // in samples, per sample, can be negative
|
2021-12-22 23:20:51 +00:00
|
|
|
enum { SND_FREE = 0, SND_STOPPED, SND_PLAYING, SND_LOOPING, } state;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct Udp_msg Udp_msg;
|
|
|
|
struct Udp_msg {
|
|
|
|
s8 text[32]; // includes null terminator
|
|
|
|
enum { MSG_FREE = 0, MSG_TRIGGER, } state;
|
2021-12-20 02:06:02 +00:00
|
|
|
};
|
|
|
|
|
2021-12-19 22:44:48 +00:00
|
|
|
typedef struct Ampler_state Ampler_state;
|
|
|
|
struct Ampler_state {
|
2021-12-20 00:03:14 +00:00
|
|
|
u32 size; // in bytes, off this struct
|
2021-12-19 22:44:48 +00:00
|
|
|
SDL_AudioDeviceID playdev;
|
2021-12-20 02:06:02 +00:00
|
|
|
Sound_src sounds[64];
|
|
|
|
s32 played_audio_last_frame;
|
2021-12-22 23:20:51 +00:00
|
|
|
Udp_msg messages[64];
|
2021-12-19 22:44:48 +00:00
|
|
|
};
|
|
|
|
|
2021-12-21 04:35:09 +00:00
|
|
|
|
|
|
|
void udp_init(Ampler_state *);
|
|
|
|
void udp_frame(Ampler_state *);
|
|
|
|
void udp_quit(Ampler_state *);
|
|
|
|
|
|
|
|
|