// File: /workspace/github_c_makefile_star2_O2/FredTheDino[P]Fog/src/engine/platform/mixer.cpp
// Function: Mixer::Channel::effect(unsigned int, unsigned int)
void Channel::effect(u32 start, u32 len) {
    if (delay) {
        add(&delay.feedback, delay.feedback_target, delay.feedback_delta);
        add(&delay.len_seconds, delay.len_seconds_target, delay.len_seconds_delta);
        if (delay.len_seconds != delay._prev_len_seconds) {
            //TODO(GS) crackling when length is changed while sound is playing
            delay.len = (u32) AUDIO_SAMPLE_RATE * delay.len_seconds * 2;
            delay._prev_len_seconds = delay.len_seconds;
        }
        for (u32 i = 0; i < len; i++) {
            u32 cur_pos = (start + i) % CHANNEL_BUFFER_LENGTH;
            u32 pre_pos = (start + i - delay.len + CHANNEL_BUFFER_LENGTH) % CHANNEL_BUFFER_LENGTH;
            buffer[cur_pos] += buffer[pre_pos] * delay.feedback;
        }
    }
    if (lowpass) {
        lowpass.weight_target = CLAMP(0, 1, lowpass.weight_target);
        add(&lowpass.weight, lowpass.weight_target, lowpass.weight_delta);
        f32 weight = lowpass._SENSITIVITY * pow(2.718,
                log(lowpass.weight * (1+lowpass._SENSITIVITY) / lowpass._SENSITIVITY)) - lowpass._SENSITIVITY;
        for (u32 i = 0; i < len; i += 2) {
            u32 pos = (start + i) % CHANNEL_BUFFER_LENGTH;
            lowpass.sum[0] -= (weight * (lowpass.sum[0] - buffer[pos+0]));
            lowpass.sum[1] -= (weight * (lowpass.sum[1] - buffer[pos+1]));
            buffer[pos+0] = lowpass.sum[0];
            buffer[pos+1] = lowpass.sum[1];
        }
    }
    if (highpass) {
        highpass.weight_target = CLAMP(0, 1, highpass.weight_target);
        add(&highpass.weight, highpass.weight_target, highpass.weight_delta);
        f32 weight = highpass._SENSITIVITY * pow(2.718,
                log(highpass.weight * (1+highpass._SENSITIVITY) / highpass._SENSITIVITY)) - highpass._SENSITIVITY;
        for (u32 i = 0; i < len; i += 2) {
            u32 pos = (start + i) % CHANNEL_BUFFER_LENGTH;
            highpass.sum[0] -= ((1 - weight) * (highpass.sum[0] - buffer[pos+0]));
            highpass.sum[1] -= ((1 - weight) * (highpass.sum[1] - buffer[pos+1]));
            buffer[pos+0] -= highpass.sum[0];
            buffer[pos+1] -= highpass.sum[1];
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebx
movl %esi, %r14d
movq %rdi, %r15
leaq 0x8(%rdi), %r12
movq %r12, %rdi
callq 0x2a82c
testb %al, %al
je 0x23754
movss 0xc(%r15), %xmm0
movss 0x10(%r15), %xmm1
movq %r12, %rdi
callq 0x2363f
leaq 0x18(%r15), %rdi
movss 0x1c(%r15), %xmm0
movss 0x20(%r15), %xmm1
callq 0x2363f
movss 0x18(%r15), %xmm0
ucomiss 0x24(%r15), %xmm0
jne 0x236dd
jnp 0x236fe
movss 0x7b77(%rip), %xmm1     # 0x2b25c
mulss %xmm0, %xmm1
addss %xmm1, %xmm1
cvttss2si %xmm1, %rax
movl %eax, 0x14(%r15)
movss %xmm0, 0x24(%r15)
jmp 0x23702
movl 0x14(%r15), %eax
movq (%r15), %r8
movl %r14d, %ecx
subl %eax, %ecx
addl $0x46500, %ecx          # imm = 0x46500
movl $0x46500, %r9d          # imm = 0x46500
movl %r14d, %esi
movl %ebx, %r10d
movl %ecx, %eax
xorl %edx, %edx
divl %r9d
movl %edx, %edi
movl %esi, %eax
xorl %edx, %edx
divl %r9d
subl $0x1, %r10d
jb 0x23754
movl %edi, %eax
movss (%r8,%rax,4), %xmm0
movl %edx, %eax
mulss (%r12), %xmm0
addss (%r8,%rax,4), %xmm0
movss %xmm0, (%r8,%rax,4)
incl %ecx
incl %esi
jmp 0x2371c
movss 0x78a8(%rip), %xmm2     # 0x2b004
ucomiss 0x30(%r15), %xmm2
movss 0x34(%r15), %xmm1
ja 0x237ad
movss 0x7893(%rip), %xmm0     # 0x2b004
ucomiss %xmm1, %xmm0
ja 0x237ad
movss 0x7886(%rip), %xmm2     # 0x2b004
ucomiss 0x48(%r15), %xmm2
movss 0x4c(%r15), %xmm1
ja 0x2389b
movss 0x786d(%rip), %xmm0     # 0x2b004
ucomiss %xmm1, %xmm0
ja 0x2389b
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%r15), %rdi
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
ja 0x237c4
ucomiss %xmm2, %xmm1
movaps %xmm2, %xmm0
ja 0x237c4
movaps %xmm1, %xmm0
movss %xmm0, 0x34(%r15)
movss 0x38(%r15), %xmm1
callq 0x2363f
movss 0x3c(%r15), %xmm1
cvtss2sd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movss 0x7818(%rip), %xmm0     # 0x2b004
addss %xmm1, %xmm0
mulss 0x30(%r15), %xmm0
divss %xmm1, %xmm0
callq 0x2470
cvtss2sd %xmm0, %xmm1
movsd 0x825d(%rip), %xmm0     # 0x2ba68
callq 0x2220
cvtss2sd 0x3c(%r15), %xmm1
mulsd -0x28(%rbp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
xorps 0x7816(%rip), %xmm0     # 0x2b040
movq (%r15), %rsi
xorl %edi, %edi
movl $0x46500, %r8d          # imm = 0x46500
movl %r14d, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %r8d
cmpl %ebx, %edi
jae 0x23776
movl %edx, %eax
movss 0x28(%r15), %xmm1
movss 0x2c(%r15), %xmm2
movaps %xmm1, %xmm3
subss (%rsi,%rax,4), %xmm3
mulss %xmm0, %xmm3
addss %xmm1, %xmm3
movss %xmm3, 0x28(%r15)
movaps %xmm2, %xmm1
subss 0x4(%rsi,%rax,4), %xmm1
mulss %xmm0, %xmm1
addss %xmm2, %xmm1
movss %xmm1, 0x2c(%r15)
movss %xmm3, (%rsi,%rax,4)
movss 0x2c(%r15), %xmm1
movss %xmm1, 0x4(%rsi,%rax,4)
addl $0x2, %edi
addl $0x2, %ecx
jmp 0x23838
leaq 0x48(%r15), %rdi
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
ja 0x238b2
ucomiss %xmm2, %xmm1
movaps %xmm2, %xmm0
ja 0x238b2
movaps %xmm1, %xmm0
movss %xmm0, 0x4c(%r15)
movss 0x50(%r15), %xmm1
callq 0x2363f
movss 0x54(%r15), %xmm1
cvtss2sd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movaps %xmm1, %xmm0
movss 0x7727(%rip), %xmm2     # 0x2b004
addss %xmm2, %xmm0
mulss 0x48(%r15), %xmm0
divss %xmm1, %xmm0
callq 0x2470
cvtss2sd %xmm0, %xmm1
movsd 0x816c(%rip), %xmm0     # 0x2ba68
callq 0x2220
movss 0x76fb(%rip), %xmm3     # 0x2b004
cvtss2sd 0x54(%r15), %xmm1
mulsd -0x28(%rbp), %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
subss %xmm0, %xmm3
movq (%r15), %rcx
xorps 0x7716(%rip), %xmm3     # 0x2b040
xorl %esi, %esi
movl $0x46500, %edi          # imm = 0x46500
movl %r14d, %eax
xorl %edx, %edx
divl %edi
cmpl %ebx, %esi
jae 0x237a0
movl %edx, %eax
movss 0x40(%r15), %xmm0
movaps %xmm0, %xmm1
subss (%rcx,%rax,4), %xmm1
movss 0x44(%r15), %xmm2
mulss %xmm3, %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x40(%r15)
movaps %xmm2, %xmm0
subss 0x4(%rcx,%rax,4), %xmm0
mulss %xmm3, %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0x44(%r15)
movss (%rcx,%rax,4), %xmm0
movss 0x4(%rcx,%rax,4), %xmm2
subss %xmm1, %xmm0
movss %xmm0, (%rcx,%rax,4)
subss 0x44(%r15), %xmm2
movss %xmm2, 0x4(%rcx,%rax,4)
addl $0x2, %esi
addl $0x2, %r14d
jmp 0x23931