The solution? If your algorithm executes in variable time, save the final output to a temp variable and write it to the output just after the microframe synchronization. It's probably a good practice to adopt in general; it doesn't cost much (one instruction and one storage longword) , does no harm for deterministic effects, and avoids the potential for jitter noise in non-deterministic effects.
The implementation goes in 4 places, like this:
- Code: Select all
_frame_sync rdlong current_microframe, p_frame_counter
cmp previous_microframe, current_microframe wz
if_z jmp #_frame_sync 'If current_microframe = previoius_microframe
'Verify sync, and report an overrun condition if it has occurred.
'
'NOTE: An overrun condition is reported to the OS by writing a non-zero value to the "overrun detect" field in the
' SYSTEM_STATE block. The code below writes the value of current_microframe in order to conserve code space,
' achieve portability, and limit execution time. That value will be non-zero 99.9999999767169% of the time,
' which is sufficiently reliable for overrun reporting
'
add previous_microframe, #1
cmp previous_microframe, current_microframe wz
if_nz wrlong current_microframe, p_ss_overrun_detect
mov previous_microframe, current_microframe 'previous_microframe = current_microframe
'------------------------------------
'Get audio in sample and write audio out sample
'------------------------------------
wrlong pending_audio_out, p_socket_audio_out '<<<<<<<<<< MODIFICATION
rdlong audio_in_sample, p_socket_audio_in
'------------------------------------
'Bypass
'------------------------------------
'Read bypass state
rdlong r1, p_socket_bypass
cmp SIGNAL_TRUE, r1 wc, wz
'Update on/off indication
if_c_or_z mov r2, 0
if_nc_and_nz mov r2, SIGNAL_TRUE
wrlong r2, p_socket_on
'If bypassed, then just pass audio through
if_c_or_z mov pending_audio_out, audio_in_sample '<<<<<<<<<< MODIFICATION
if_c_or_z jmp #_frame_sync
.
. (rest of effect code)
.
'------------------------------------
'Store output
'------------------------------------
mov pending_audio_out, x '<<<<<<<<<< MODIFICATION
'Done Distortion
jmp #_frame_sync
.
. (more code and definitions)
.
pending_audio_out res 1 '<<<<<<<<<< MODIFICATION
