Commit 1058c5d9 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Rename safe_add to clamp_add

parent 68590900
PRG = crowbx
OBJ = crowbx.o midi.o dac.o uart.o gate.o poly.o mono.o list.o vibrato.o poly2.o safe_add.o pitch.o pitch_env.o vibrato_rate.o mono2.o voice.o
OBJ = crowbx.o midi.o dac.o uart.o gate.o poly.o mono.o list.o vibrato.o poly2.o clamp_add.o pitch.o pitch_env.o vibrato_rate.o mono2.o voice.o
MCU_TARGET = atmega328p
OPTIMIZE = -O3
......
#include "safe_add.h"
#include "clamp_add.h"
uint16_t safe_add(uint16_t x, int16_t delta) {
uint16_t clamp_add(uint16_t x, int16_t delta) {
if (delta < 0) {
uint16_t sub = -delta;
if (x < sub) {
......
#ifndef CLAMP_ADD_H
#define CLAMP_ADD_H
#include <stdint.h>
uint16_t clamp_add(uint16_t x, int16_t delta);
#endif
#include "dac.h"
#include "safe_add.h"
#include "clamp_add.h"
#include "voice.h"
#include <avr/io.h>
#include <util/delay.h>
......@@ -84,7 +84,7 @@ uint16_t dac_note_pitch(uint8_t v, uint8_t note) {
return 0;
}
return safe_add(
return clamp_add(
d->offset + octave * d->scale,
dac_semitone_offset((note - MIDI_LOWEST) % NUM_SEMITONES));
}
#include "pitch.h"
#include "dac.h"
#include "pitch_env.h"
#include "safe_add.h"
#include "clamp_add.h"
#include "vibrato.h"
#include "voice.h"
......@@ -19,7 +19,7 @@ void pitch_set_note(uint8_t voice, uint8_t note, int16_t detune) {
return;
}
base_pitch[voice] = safe_add(dac_note_pitch(voice, note), detune);
base_pitch[voice] = clamp_add(dac_note_pitch(voice, note), detune);
}
void pitch_set_bend(uint16_t bend) {
......@@ -32,10 +32,10 @@ void pitch_update_clock(uint8_t delta) {
pitch_env_update_clock(delta);
for_each_voice (v) {
uint16_t data = safe_add(base_pitch[v], vibrato_detune());
data = safe_add(data,
uint16_t data = clamp_add(base_pitch[v], vibrato_detune());
data = clamp_add(data,
pitch_env_delta(v) * (float)dac_pitch_delta(5));
data = safe_add(data, bend_data);
data = clamp_add(data, bend_data);
dac_send(dac_command_set(v), data);
}
}
#ifndef SAFE_ADD_H
#define SAFE_ADD_H
#include <stdint.h>
uint16_t safe_add(uint16_t x, int16_t delta);
#endif
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