Formatting
This commit is contained in:
parent
c4ec4a6340
commit
87d6798593
|
@ -55,6 +55,8 @@ typedef struct AudioChannel {
|
||||||
|
|
||||||
AudioChannel channel[POLYPHONY];
|
AudioChannel channel[POLYPHONY];
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
const float tuning[109] = {
|
const float tuning[109] = {
|
||||||
0.00058853f, 0.00062352f, 0.00066060f, 0.00069988f, 0.00074150f,
|
0.00058853f, 0.00062352f, 0.00066060f, 0.00069988f, 0.00074150f,
|
||||||
0.00078559f, 0.00083230f, 0.00088179f, 0.00093423f, 0.00098978f,
|
0.00078559f, 0.00083230f, 0.00088179f, 0.00093423f, 0.00098978f,
|
||||||
|
@ -80,8 +82,11 @@ const float tuning[109] = {
|
||||||
0.25338348f, 0.26845044f, 0.28441334f, 0.30132544f,
|
0.25338348f, 0.26845044f, 0.28441334f, 0.30132544f,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
void
|
void
|
||||||
env_on(Envelope *env) {
|
env_on(Envelope *env)
|
||||||
|
{
|
||||||
env->stage = ENV_ATTACK;
|
env->stage = ENV_ATTACK;
|
||||||
env->vol = 0.0f;
|
env->vol = 0.0f;
|
||||||
if(env->a > 0) {
|
if(env->a > 0) {
|
||||||
|
@ -101,13 +106,14 @@ env_on(Envelope *env) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
env_off(Envelope *env) {
|
env_off(Envelope *env)
|
||||||
|
{
|
||||||
env->stage = ENV_RELEASE;
|
env->stage = ENV_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 vol,
|
note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 vol, Uint8 attack, Uint8 decay, Uint8 sustain, Uint8 release, Uint8 pitch, bool loop)
|
||||||
Uint8 attack, Uint8 decay, Uint8 sustain, Uint8 release, Uint8 pitch, bool loop) {
|
{
|
||||||
channel->duration = duration > 0 ? duration : len / 44.1f;
|
channel->duration = duration > 0 ? duration : len / 44.1f;
|
||||||
channel->vol_l = (vol >> 4) / 15.0f;
|
channel->vol_l = (vol >> 4) / 15.0f;
|
||||||
channel->vol_r = (vol & 0xf) / 15.0f;
|
channel->vol_r = (vol & 0xf) / 15.0f;
|
||||||
|
@ -141,13 +147,15 @@ note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 v
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
note_off(AudioChannel *channel, Uint16 duration) {
|
note_off(AudioChannel *channel, Uint16 duration)
|
||||||
|
{
|
||||||
channel->duration = duration;
|
channel->duration = duration;
|
||||||
env_off(&channel->sample.env);
|
env_off(&channel->sample.env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
env_advance(Envelope *env) {
|
env_advance(Envelope *env)
|
||||||
|
{
|
||||||
switch(env->stage) {
|
switch(env->stage) {
|
||||||
case ENV_ATTACK: {
|
case ENV_ATTACK: {
|
||||||
env->vol += env->a;
|
env->vol += env->a;
|
||||||
|
@ -177,7 +185,8 @@ env_advance(Envelope *env) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
interpolate_sample(Uint8 *data, Uint16 len, float pos) {
|
interpolate_sample(Uint8 *data, Uint16 len, float pos)
|
||||||
|
{
|
||||||
#if INTERPOL_METHOD == 0
|
#if INTERPOL_METHOD == 0
|
||||||
return data[(int)pos];
|
return data[(int)pos];
|
||||||
|
|
||||||
|
@ -211,7 +220,8 @@ interpolate_sample(Uint8 *data, Uint16 len, float pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Sint16
|
Sint16
|
||||||
next_sample(Sample *sample) {
|
next_sample(Sample *sample)
|
||||||
|
{
|
||||||
if(sample->pos >= sample->len) {
|
if(sample->pos >= sample->len) {
|
||||||
if(sample->loop == 0) {
|
if(sample->loop == 0) {
|
||||||
sample->data = 0;
|
sample->data = 0;
|
||||||
|
@ -232,7 +242,8 @@ next_sample(Sample *sample) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
audio_handler(void *ctx, Uint8 *out_stream, int len) {
|
audio_handler(void *ctx, Uint8 *out_stream, int len)
|
||||||
|
{
|
||||||
Sint16 *stream = (Sint16 *)out_stream;
|
Sint16 *stream = (Sint16 *)out_stream;
|
||||||
memset(stream, 0x00, len);
|
memset(stream, 0x00, len);
|
||||||
|
|
||||||
|
@ -305,11 +316,13 @@ audio_start(int idx, Uint8 *d, Uxn *u)
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint8
|
Uint8
|
||||||
audio_get_vu(int instance) {
|
audio_get_vu(int instance)
|
||||||
|
{
|
||||||
return channel[instance].sample.env.vol * 255.0f;
|
return channel[instance].sample.env.vol * 255.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16
|
Uint16
|
||||||
audio_get_position(int instance) {
|
audio_get_position(int instance)
|
||||||
|
{
|
||||||
return channel[instance].sample.pos;
|
return channel[instance].sample.pos;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue