Commit 8c29b80d authored by Jacob Vosmaer's avatar Jacob Vosmaer

Inline vibrato.c

parent 1da1646c
PRG = crowbx
OBJ = crowbx.o midi.o dac.o list.o vibrato.o clamp_add.o pitch.o pitch_env.o vibrato_rate.o voice.o
OBJ = crowbx.o midi.o dac.o list.o clamp_add.o pitch.o pitch_env.o vibrato_rate.o voice.o
MCU_TARGET = atmega328p
OPTIMIZE = -O3
......
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/atomic.h>
#include "array_size.h"
......@@ -12,6 +13,7 @@
#include "pitch_env.h"
#include "uart.h"
#include "vibrato.h"
#include "vibrato_rate.h"
#include "voice.h"
static struct {
......@@ -484,3 +486,40 @@ void mono_control_change(uint8_t ctl, uint8_t val) {
break;
}
}
struct {
uint32_t phase;
int16_t amount;
uint8_t rate;
uint8_t depth;
} vibrato;
void vibrato_set_rate(uint8_t val) { vibrato.rate = val; }
void vibrato_set_depth(uint8_t val) { vibrato.depth = val; }
int16_t vibrato_detune(void) { return vibrato.amount; }
void vibrato_update(uint8_t delta) {
enum { VIB_MID = INT16_MAX >> 1 };
vibrato.phase +=
delta * pgm_read_float(&(vibrato_rate_table[vibrato.rate]));
uint16_t phase16 = vibrato.phase >> 16;
if (phase16 < INT16_MAX) {
vibrato.amount = phase16 - VIB_MID;
} else {
vibrato.amount = phase16 - INT16_MAX;
vibrato.amount = INT16_MAX - vibrato.amount;
vibrato.amount -= VIB_MID;
}
float pitch_factor = dac_pitch_delta(7) / ((float)INT16_MAX);
vibrato.amount *= pitch_factor;
float depth_factor = vibrato.depth / 127.0;
vibrato.amount *= depth_factor;
if (!vibrato.depth) {
vibrato.amount = 0;
}
}
#include "vibrato.h"
#include "dac.h"
#include "vibrato_rate.h"
#include <avr/pgmspace.h>
static uint32_t phase;
static uint8_t rate;
static int16_t vibrato;
static uint8_t depth;
void vibrato_set_rate(uint8_t val) { rate = val; }
void vibrato_set_depth(uint8_t val) { depth = val; }
int16_t vibrato_detune(void) { return vibrato; }
enum { VIB_MID = INT16_MAX >> 1,
};
void vibrato_update(uint8_t delta) {
phase += delta * pgm_read_float(&(vibrato_rate_table[rate]));
uint16_t phase16 = phase >> 16;
if (phase16 < INT16_MAX) {
vibrato = phase16 - VIB_MID;
} else {
vibrato = phase16 - INT16_MAX;
vibrato = INT16_MAX - vibrato;
vibrato -= VIB_MID;
}
float pitch_factor = dac_pitch_delta(7) / ((float)INT16_MAX);
vibrato *= pitch_factor;
float depth_factor = depth / 127.0;
vibrato *= depth_factor;
if (!depth) {
vibrato = 0;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment