Digital playback: reduce initial click
stefandrissen opened this issue · comments
When playing back samples, the amplitude varies from a middle point, the middle point is half maximum volume.
Initially, all devices are at "volume" 0, so as soon as playback starts volume jumps from 0 to half maximum volume, resulting in a click.
To reduce the click I tried gradually increasing volume from 0 to half maximum volume in the @buffer.init routines - but this does not seem to be helping and is even making things worse when playing a second mod, watch the ramped click between mod 1 and 2 of EFTPOTRM:
I seem to be doing something a bit silly when initially filling the buffers. There are two buffers, each populated with sample data for two channels:
buffer 1:
- channel 1: 00...77
- channel 2: 00...77
buffer 2:
- channel 1: 00...77
- channel 2: 00...77
When using SAA1099 there are not two discrete channels, the sample data is interleaved for both, channel 2, channel 5, channel 2, channel 5, etc.
Also buffer 2 is played after buffer 1, so there is an additional ramp.
I already commented that it couldn't be solved, but then I had some ideas and it seems to be quite a bit better. I gradually reduced the most time-consuming part of the program to only one OUT instruction, which is only 16T (375000Hz) in the border. Volume now changes from &00 to &88 in 192 levels before envelope control is turned on.
Here is a short break in amplitude, it seems that turning on the envelope first mutes the sound and immediately sets it back to maximum (%001=max.amplitude).
I haven't tested it on a real Sam.
Not everything is visible in the 44100 Hz file, it's just a rough check.
RstSAA_Env_03_pwm12.zip