Formatting

This commit is contained in:
neauoire 2023-10-20 11:54:25 -04:00
parent c4ec4a6340
commit 87d6798593
3 changed files with 242 additions and 229 deletions

View File

@ -55,6 +55,8 @@ typedef struct AudioChannel {
AudioChannel channel[POLYPHONY];
/* clang-format off */
const float tuning[109] = {
0.00058853f, 0.00062352f, 0.00066060f, 0.00069988f, 0.00074150f,
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,
};
/* clang-format on */
void
env_on(Envelope *env) {
env_on(Envelope *env)
{
env->stage = ENV_ATTACK;
env->vol = 0.0f;
if(env->a > 0) {
@ -101,13 +106,14 @@ env_on(Envelope *env) {
}
void
env_off(Envelope *env) {
env_off(Envelope *env)
{
env->stage = ENV_RELEASE;
}
void
note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 vol,
Uint8 attack, Uint8 decay, Uint8 sustain, Uint8 release, Uint8 pitch, bool loop) {
note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 vol, Uint8 attack, Uint8 decay, Uint8 sustain, Uint8 release, Uint8 pitch, bool loop)
{
channel->duration = duration > 0 ? duration : len / 44.1f;
channel->vol_l = (vol >> 4) / 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
note_off(AudioChannel *channel, Uint16 duration) {
note_off(AudioChannel *channel, Uint16 duration)
{
channel->duration = duration;
env_off(&channel->sample.env);
}
void
env_advance(Envelope *env) {
env_advance(Envelope *env)
{
switch(env->stage) {
case ENV_ATTACK: {
env->vol += env->a;
@ -177,7 +185,8 @@ env_advance(Envelope *env) {
}
float
interpolate_sample(Uint8 *data, Uint16 len, float pos) {
interpolate_sample(Uint8 *data, Uint16 len, float pos)
{
#if INTERPOL_METHOD == 0
return data[(int)pos];
@ -211,7 +220,8 @@ interpolate_sample(Uint8 *data, Uint16 len, float pos) {
}
Sint16
next_sample(Sample *sample) {
next_sample(Sample *sample)
{
if(sample->pos >= sample->len) {
if(sample->loop == 0) {
sample->data = 0;
@ -232,7 +242,8 @@ next_sample(Sample *sample) {
}
void
audio_handler(void *ctx, Uint8 *out_stream, int len) {
audio_handler(void *ctx, Uint8 *out_stream, int len)
{
Sint16 *stream = (Sint16 *)out_stream;
memset(stream, 0x00, len);
@ -305,11 +316,13 @@ audio_start(int idx, Uint8 *d, Uxn *u)
}
Uint8
audio_get_vu(int instance) {
audio_get_vu(int instance)
{
return channel[instance].sample.env.vol * 255.0f;
}
Uint16
audio_get_position(int instance) {
audio_get_position(int instance)
{
return channel[instance].sample.pos;
}