This repository has been archived on 2017-07-22. You can view files and clone it, but cannot push or open issues/pull-requests.
jlsampler/sound.h

54 lines
1.2 KiB
C

#ifndef config_HEADER_
#define config_HEADER_
#include <stdint.h>
#include "const.h"
#include "sample.h"
#include "soundconfig.h"
// Playing sample states.
#define PS_ON 0 // Undamped.
#define PS_OFF 1 // Damped because key off and sustain off.
#define PS_CUT 2 // Damped because cut by other key.
typedef struct {
Sample *sample;
int state;
int idx;
double amp;
double tau;
} PlayingSample;
typedef struct {
// Configuration
SoundConfig conf;
// Whether or not the key is depressed.
bool key_down;
// Samples
uint8_t num_layers;
uint8_t num_vars[MAX_LAYERS];
uint8_t rr_idx[MAX_LAYERS];
Sample samples[MAX_LAYERS][MAX_VARS];
// Playing samples
int32_t buf_size;
int32_t num_free;
PlayingSample *ps_free[MAX_PLAYING];
float *amp_buf;
int32_t num_playing;
PlayingSample *ps_playing[MAX_PLAYING];
} Sound;
void sound_init(Sound *sound);
void sound_load_samples(Sound *sound, int32_t buf_size);
void sound_trigger(Sound *sound, double velocity);
void sound_cut(Sound *sound);
void sound_write_buffer(Sound *sound, float *L, float *R);
void sound_free(Sound *sound);
#endif