Commit acccd7a9 authored by josch's avatar josch

Adds support for 14 bit HIFI mode as an alternative to STANDARD_PLUS mode; adapts the description.

parent dab9dacc
/* `fmsynth` is a little instrument using frequency modulation for sound synthesis.
Sound synthesis happens digitally on an Arduino board using the [Mozzi sonification library](https://sensorium.github.io/Mozzi/) from Tim Barrass.
Sound synthesis happens digitally on an Arduino board using the
[Mozzi sonification library](https://sensorium.github.io/Mozzi/)
written by Tim Barrass.
Features of `fmsynth`:
* FM synthesis with 2 operators (carrier and modulator)
* ADSR envelope on modulator amplitude
* ADSR envelopes on both operators
* audio signal with 14 bit depth and 32768 Hz sampling rate
* MIDI for monophonic note input
* knobs to control some parameters
For good quality AUDIO_MODE should be STANDARD_PLUS at least and
AUDIO_RATE set to 32768 in mozzi_config.h within the Mozzi library directory.
For best audio quality, change Mozzi/mozzi_config.h:
* #define AUDIO_MODE HIFI
* #define AUDIO_RATE 32768
This Arduino sketch is made by Josch 2020, CC by-nc-sa.
......@@ -102,8 +106,8 @@ void updateControl(){
carrierEnv.update();
modulatorEnv.update();
carrier_gain = carrierEnv.next();
modulator_gain = modulatorEnv.next();
carrier_gain = carrierEnv.next(); // writing Q8n0 into Q24n8 -> values from 0 to 1
modulator_gain = modulatorEnv.next(); // writing Q8n0 into Q0n8 -> values from 0 to 1
}
......@@ -111,7 +115,11 @@ int updateAudio(){
Q15n16 envelopedModulator = modulator_gain * static_cast<Q23n8>(modulatorOsc.next()); // Q0n8 * Q23n8 -> Q15n16
Q15n16 mudulation = Q15n16_to_Q23n8(envelopedModulator) * mod_index; // Q23n8 * Q8n8 -> Q15n16
return Q23n8_to_Q15n0(carrier_gain * carrierOsc.phMod(mudulation)); // Q24n8 * Q7n0 -> Q23n8
#if AUDIO_MODE==HIFI
return static_cast<Q15n0>(carrier_gain * carrierOsc.phMod(mudulation)) >> 2; // Q24n8 * Q7n0 -> Q23n8 of which Q7n8 are used; bring it to 14 bit signed
#else
return Q23n8_to_Q15n0(carrier_gain * carrierOsc.phMod(mudulation)); // Q24n8 * Q7n0 -> Q23n8 of which Q7n8 are used; bring it to 16 bit signed of which lower 8 bit are used
#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