summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--examples/test.c4
-rw-r--r--mmband/README.md5
-rw-r--r--mmband/api/instrument.h2
-rw-r--r--mmband/instrument.c20
-rw-r--r--mmband/synthesizer_current_progress.zipbin0 -> 3678 bytes
-rw-r--r--mmband/waves/waveform.h2
7 files changed, 25 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c564c75..35c254f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.12)
+cmake_minimum_required(VERSION 2.8...3.12)
project(mmband VERSION 0.1)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
diff --git a/examples/test.c b/examples/test.c
index 05c5114..0fd994a 100644
--- a/examples/test.c
+++ b/examples/test.c
@@ -46,7 +46,7 @@ int main (void) {
ins_set_carrier(instrument, OSC_SINE);
ins_set_modulator(instrument, OSC_SINE);
ins_set_carrier_amplitude(instrument, 0.25);
- ins_set_modulator_amplitude(instrument, 0.25);
+ ins_set_modulator_amplitude(instrument, 0.85);
ins_set_frequency_mult(instrument, 3.0);
adsr_ref adsr = adsr_new();
@@ -111,7 +111,7 @@ int main (void) {
}
//float env = adsr_tick(adsr, SAMPLE_RATE);
- float ins = ins_tick(instrument, SAMPLE_RATE);
+ float ins = ins_tick(instrument, ALGORITHM_FREQUENCY, SAMPLE_RATE);
buffer[j][0] = ins;// * env;
buffer[j][1] = ins;// * env;
}
diff --git a/mmband/README.md b/mmband/README.md
new file mode 100644
index 0000000..e3bad16
--- /dev/null
+++ b/mmband/README.md
@@ -0,0 +1,5 @@
+# Synthesizer Project (mmband)
+
+I was studying some basic acoustics and FM synthesis, so I'm currently working on attempting to design one from the ground up. I'm hoping to eventually support several models of synthesis and composing instruments like you can on multiple-modulator synthesizers.
+
+It's still in the early stages, but it's structured into an external headers folder (api), a waveforms folder (waves), and the instrument implementation (instrument.c).
diff --git a/mmband/api/instrument.h b/mmband/api/instrument.h
index 3190d10..b9c62a3 100644
--- a/mmband/api/instrument.h
+++ b/mmband/api/instrument.h
@@ -42,6 +42,6 @@ MMAPI void ins_set_modulator_amplitude (instrument_ref instrument,
MMAPI void ins_set_frequency_mult (instrument_ref instrument, float mult);
MMAPI void ins_set_frequency (instrument_ref instrument, float frequency);
-MMAPI float ins_tick (instrument_ref instrument, int sample_rate);
+MMAPI float ins_tick (instrument_ref instrument, enum algorithm alg, int sample_rate);
#endif
diff --git a/mmband/instrument.c b/mmband/instrument.c
index 2ec9821..c3b82bc 100644
--- a/mmband/instrument.c
+++ b/mmband/instrument.c
@@ -1,6 +1,5 @@
#include <math.h>
#include <stdlib.h>
-#include <stdio.h>
#include <mmband/api/instrument.h>
#include <mmband/api/adsr.h>
@@ -49,7 +48,20 @@ float osc_tick (struct oscillation *osc, int sample_rate) {
// Currently default to ring modulation
// TODO: add others
-float modulate (struct oscillation *carrier, struct oscillation *modulator, int sample_rate) {
+float modulate (struct oscillation *carrier, struct oscillation *modulator, enum algorithm alg, int sample_rate) {
+ switch (alg) {
+ case ALGORITHM_NONE:
+ return osc_tick(carrier, sample_rate);
+ break;
+ case ALGORITHM_RING:
+ return osc_tick(carrier, sample_rate) * osc_tick(modulator, sample_rate);
+ break;
+ case ALGORITHM_FREQUENCY:
+ carrier->frequency = carrier->frequency + osc_tick(modulator, sample_rate);
+ return osc_tick(carrier, sample_rate);
+ break;
+ }
+
return osc_tick(carrier, sample_rate) * osc_tick(modulator, sample_rate);
}
@@ -106,6 +118,6 @@ void ins_set_frequency (instrument_ref instrument, float frequency) {
instrument->modulator.frequency = frequency * instrument->frequency_mult;
}
-float ins_tick (instrument_ref instrument, int sample_rate) {
- return modulate(&instrument->carrier, &instrument->modulator, sample_rate);
+float ins_tick (instrument_ref instrument, enum algorithm alg, int sample_rate) {
+ return modulate(&instrument->carrier, &instrument->modulator, alg, sample_rate);
}
diff --git a/mmband/synthesizer_current_progress.zip b/mmband/synthesizer_current_progress.zip
new file mode 100644
index 0000000..79eee23
--- /dev/null
+++ b/mmband/synthesizer_current_progress.zip
Binary files differ
diff --git a/mmband/waves/waveform.h b/mmband/waves/waveform.h
index cb7128c..df18e36 100644
--- a/mmband/waves/waveform.h
+++ b/mmband/waves/waveform.h
@@ -1,8 +1,6 @@
#ifndef MMBAND_WAVEFORM_H
#define MMBAND_WAVEFORM_H
-#include <mmband/api/lib.h>
-
typedef float wave_function (float);
wave_function none;