shorepine / amy

AMY - the Additive Music synthesizer librarY

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`amy-message` Segmentation fault in certain circumstances

octetta opened this issue · comments

Still investigating, but this sequence is 100% repeatable:

$ ./amy-message -d 1
# # amy-message AMY playground -> https://octetta.com
# - uses AMY audio synthesizer library -> https://github.com/bwhitman/amy
# - uses miniaudio v0.11.11 audio playback library -> https://miniaud.io
# - uses bestline history and editing library -> https://github.com/jart/bestline
# OSCS=64
# SAMPLE_RATE=44100
# load history from amy-message-history.txt
# v0w7  ## set osc0 to PCM
# v0p22 ## choose SynthVz patch
# v0b1  ## enable PCM looping
# v0l1  ## trigger with velocity 1
# v0w1  ## change osc0 to pulse wave
# Segmentation fault (core dumped)

For those watching, this can be avoided by resetting osc0 via S0 before changing the oscillator's wave type.

I'll dig into how to prevent this in the codebase, but pointing out until then.

Yeah, seeing that here. Investigating...

* thread #7, name = 'com.apple.audio.IOThread.client', stop reason = EXC_BAD_ACCESS (code=1, address=0x16394)
    frame #0: 0x00000001000088bc amy-message`render_lut(buf=0x0000000100349470, step=22757, skip=0, incoming_amp=0, ending_amp=NaN, lut=0x0000000000000000, lut_size=0) at oscillators.c:102:19
   99  	        //uint16_t base_index = (uint16_t)floor(step);
   100 	        uint32_t base_index = (uint32_t)step;
   101 	        float frac = step - (float)base_index;
-> 102 	        float b = lut[(base_index + 0) & lut_mask];
   103 	        float c = lut[(base_index + 1) & lut_mask];
   104 	#ifdef LINEAR_INTERP
   105 	        // linear interpolation.
Target 0: (amy-message) stopped.```

The bigger issue is that we'd never have called pulse_note_on if we switch waveform types after a note on. So nothing will be set up right to play a pulse wave.

Do we want to support this? It's unclear what a real synth would do if you changed waveforms mid-stream. Reset the oscillator to 0? Stop the note? We should at the least not crash.

suggest fix: line 380 of ../blob/main/src/amy.c should check for a change in WAVE if that voice's velocity is >0, and if there is, trigger the note on logic in line 433 below. This would have the effect of a synth making a new note at the new specified waveform.

OK, i've implemented that fix. Your example and a few tests i ran work for me. Thanks for the report.

With this fix in place, AMY can do some more awful and wonderful stuff, like "wave sequencing".
Here's a little part of a live demo with my console tool:

https://youtu.be/Dy4pd1_UFSo