90 lines
1.9 KiB
C
90 lines
1.9 KiB
C
// ampler.h
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
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 uint64_t u64;
|
|
|
|
typedef float f32;
|
|
typedef double f64;
|
|
|
|
|
|
#define if if(
|
|
#define while while(
|
|
#define for for(
|
|
#define do )
|
|
|
|
#define or ||
|
|
#define and &&
|
|
|
|
|
|
#define arraylen(a) (sizeof (a) / sizeof ((a)[0]))
|
|
|
|
#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
|
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#define SAMPLE_RATE (44100)
|
|
#define CHANNELS (2)
|
|
#define FRAME_SAMPLES (SAMPLE_RATE / 60)
|
|
|
|
typedef struct Sound_src Sound_src;
|
|
struct Sound_src {
|
|
s8 *tracks[CHANNELS];
|
|
s32 track_len; // size of track buffers, in samples
|
|
f32 pos; // position in samples
|
|
f32 speed; // in samples, per sample, can be negative
|
|
s32 start; // play start in samples
|
|
s32 end; // play end in samples
|
|
s8 name[32]; // includes null terminator
|
|
f32 note_speed; // multiplies with base speed, CANNOT be negative
|
|
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;
|
|
};
|
|
|
|
typedef struct Markov_4 Markov_4;
|
|
struct Markov_4 {
|
|
u8 start;
|
|
u8 chain[256][256];
|
|
u8 lens[256];
|
|
};
|
|
|
|
typedef struct Ampler_state Ampler_state;
|
|
struct Ampler_state {
|
|
u32 size; // in bytes, off this struct
|
|
SDL_AudioDeviceID playdev;
|
|
SDL_AudioDeviceID recdev;
|
|
Sound_src sounds[64];
|
|
s32 played_audio_last_frame;
|
|
Udp_msg messages[64];
|
|
s8 frame_mix[CHANNELS][FRAME_SAMPLES];
|
|
s8 frame_rec[CHANNELS][FRAME_SAMPLES];
|
|
|
|
Markov_4 markov;
|
|
};
|
|
|
|
|
|
void udp_init(Ampler_state *);
|
|
void udp_frame(Ampler_state *);
|
|
void udp_quit(Ampler_state *);
|
|
|
|
|