Skip to content

Commit

Permalink
amy.c, README: freq=0 is now an alias for freq=263.62.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwe committed Mar 19, 2024
1 parent 80a1777 commit f831390
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ The set "50,0,0,0,1" means that we have a base frequency of 50 Hz, we ignore the

You can use the same breakpoint set to control several things at once. For example, we could include `freq="50,0,0,0,0.125,0"`, which says to modify a base note frequency of 50 Hz from the same breakpoint set as the filter frequency, but scaled down by 1/8th so the initial decay is over 1 octave, not 3. Give it a go!

The note frequency is scaled relative to a zero-point of middle C (MIDI note 60, 261.63 Hz), so to make the oscillator faithfully track the `note` parameter to the note-on event, you need something like `freq="261.63,1"` (which is its default setting before any `freq` parameter is passed). Setting it to `freq="523.26,1"` would make the oscillator always be one octave higher than the `note` MIDI number. Setting `freq="261.3,0.5"` would make the oscillator track the `note` parameter at half an octave per unit, so while `note=60` would still give middle C, `note=72` (C5) would make the oscillator run at F#4, and `note=84` (C6) would be required to get C5 from the oscillator.
The note frequency is scaled relative to a zero-point of middle C (MIDI note 60, 261.63 Hz), so to make the oscillator faithfully track the `note` parameter to the note-on event, you would use something like `freq="261.63,1"` (which is its default setting before any `freq` parameter is passed). Setting it to `freq="523.26,1"` would make the oscillator always be one octave higher than the `note` MIDI number. Setting `freq="261.3,0.5"` would make the oscillator track the `note` parameter at half an octave per unit, so while `note=60` would still give middle C, `note=72` (C5) would make the oscillator run at F#4, and `note=84` (C6) would be required to get C5 from the oscillator.

Actually, the default set of ControlCoefficients for `freq` is "261.63,1,0,0,0,0,1", i.e. a base of middle C, tracking the MIDI note, plus pitch bend (at unit-per-octave). `amp` also has a set of defaults "0,0,1,1,0,0,0", i.e. tracking note-on velocity plus modulation by breakpoint set 0 (if it is doing anything). `amp` is a little special because the individual components are *multiplied* together, instead of added together, for any control inputs with nonzero coefficients. These defaults are set up in [`src/amy.c:reset_osc()`](https://github.com/bwhitman/amy/blob/b1ed189b01e6b908bc19f18a4e0a85761d739807/src/amy.c#L551).
Actually, the default set of ControlCoefficients for `freq` is "261.63,1,0,0,0,0,1", i.e. a base of middle C, tracking the MIDI note, plus pitch bend (at unit-per-octave). Because 261.63 is such an important value, as a special case, setting the first `freq` value to zero is magically rewritten as 261.63, so `freq="0,1,0,0,0,0,1"` also yields the default behavior. `amp` also has a set of defaults `amp="0,0,1,1,0,0,0"`, i.e. tracking note-on velocity plus modulation by breakpoint set 0 (which just tracks the note-on status if it is empty). `amp` is a little special because the individual components are *multiplied* together, instead of added together, for any control inputs with nonzero coefficients. Finally, we add 1.0 to the coefficient-scaled LFO modulator and pitch bend inputs before multiplying them into the amplitude, to allow small variations around identity e.g. for tremolo. These defaults are set up in [`src/amy.c:reset_osc()`](https://github.com/bwhitman/amy/blob/b1ed189b01e6b908bc19f18a4e0a85761d739807/src/amy.c#L551).

We also have LFOs, which are implemented as one oscillator modulating another. You set up the lower-frequency oscillator, then have it control a parameter of another audible oscillator. Let's make the classic 8-bit duty cycle pulse wave modulation, a favorite:

Expand Down
4 changes: 3 additions & 1 deletion src/amy.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ int8_t global_init() {

float logfreq_of_freq(float freq) {
// logfreq is defined as log_2(freq / 8.18 Hz)
if (freq==0) return ZERO_HZ_LOG_VAL;
//if (freq==0) return ZERO_HZ_LOG_VAL;
// Actually, special-case zero to mean middle C, for convenience.
if (freq==0) return 0; // i.e. == logfreq_of_freq(ZERO_LOGFREQ_IN_HZ == 261.63.
return log2f(freq / ZERO_LOGFREQ_IN_HZ);
}

Expand Down

0 comments on commit f831390

Please sign in to comment.