// File: /workspace/github_c_makefile_star2_O0/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
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x40(%rbp)
addq $0x8, %rdi
callq 0x438c0
cmpb $0x0, %al
je 0x344c9
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movss 0xc(%rax), %xmm0
movss 0x10(%rax), %xmm1
callq 0x342e0
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
addq $0x10, %rdi
movss 0x1c(%rax), %xmm0
movss 0x20(%rax), %xmm1
callq 0x342e0
movq -0x40(%rbp), %rax
movss 0x18(%rax), %xmm0
ucomiss 0x24(%rax), %xmm0
jne 0x34426
jp 0x34426
jmp 0x34451
movq -0x40(%rbp), %rax
movss 0x18(%rax), %xmm0
movss 0x10e15(%rip), %xmm1    # 0x4524c
mulss %xmm1, %xmm0
addss %xmm0, %xmm0
cvttss2si %xmm0, %rcx
movl %ecx, 0x14(%rax)
movss 0x18(%rax), %xmm0
movss %xmm0, 0x24(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x344c7
movq -0x40(%rbp), %rcx
movl -0xc(%rbp), %eax
addl -0x14(%rbp), %eax
movl $0x46500, %esi          # imm = 0x46500
xorl %edx, %edx
divl %esi
movl %edx, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl -0x14(%rbp), %eax
subl 0x14(%rcx), %eax
addl $0x46500, %eax          # imm = 0x46500
movl $0x46500, %ecx          # imm = 0x46500
xorl %edx, %edx
divl %ecx
movq -0x40(%rbp), %rax
movl %edx, -0x1c(%rbp)
movq (%rax), %rcx
movl -0x1c(%rbp), %edx
movss (%rcx,%rdx,4), %xmm0
movss 0x8(%rax), %xmm2
movq (%rax), %rax
movl -0x18(%rbp), %ecx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x34458
jmp 0x344c9
movq -0x40(%rbp), %rdi
addq $0x28, %rdi
callq 0x43930
cmpb $0x0, %al
je 0x346b0
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
ucomiss 0x34(%rax), %xmm0
jbe 0x344f5
xorps %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x34532
movq -0x40(%rbp), %rax
movss 0x34(%rax), %xmm0
movss 0x10b02(%rip), %xmm1    # 0x45008
ucomiss %xmm1, %xmm0
jbe 0x3451a
movss 0x10af5(%rip), %xmm0    # 0x45008
movss %xmm0, -0x48(%rbp)
jmp 0x34528
movq -0x40(%rbp), %rax
movss 0x34(%rax), %xmm0
movss %xmm0, -0x48(%rbp)
movss -0x48(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x40(%rbp), %rax
movss -0x44(%rbp), %xmm0
movss %xmm0, 0x34(%rax)
movq %rax, %rdi
addq $0x28, %rdi
addq $0x8, %rdi
movss 0x34(%rax), %xmm0
movss 0x38(%rax), %xmm1
callq 0x342e0
movq -0x40(%rbp), %rax
movss 0x3c(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movss 0x30(%rax), %xmm0
movss 0x10a8f(%rip), %xmm1    # 0x45008
addss 0x3c(%rax), %xmm1
mulss %xmm1, %xmm0
divss 0x3c(%rax), %xmm0
callq 0x439a0
movaps %xmm0, %xmm1
movsd 0x114d1(%rip), %xmm0    # 0x45a68
callq 0x43970
movq -0x40(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x50(%rbp), %xmm0
movss 0x3c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x346ae
movl -0xc(%rbp), %eax
addl -0x24(%rbp), %eax
movl $0x46500, %ecx          # imm = 0x46500
xorl %edx, %edx
divl %ecx
movq -0x40(%rbp), %rax
movl %edx, -0x28(%rbp)
movss -0x20(%rbp), %xmm0
movss 0x28(%rax), %xmm2
movq (%rax), %rcx
movl -0x28(%rbp), %edx
addl $0x0, %edx
movl %edx, %edx
subss (%rcx,%rdx,4), %xmm2
movss 0x28(%rax), %xmm1
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x28(%rax)
movss -0x20(%rbp), %xmm0
movss 0x2c(%rax), %xmm2
movq (%rax), %rcx
movl -0x28(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
subss (%rcx,%rdx,4), %xmm2
movss 0x2c(%rax), %xmm1
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x2c(%rax)
movss 0x28(%rax), %xmm0
movq (%rax), %rcx
movl -0x28(%rbp), %edx
addl $0x0, %edx
movl %edx, %edx
movss %xmm0, (%rcx,%rdx,4)
movss 0x2c(%rax), %xmm0
movq (%rax), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movss %xmm0, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
jmp 0x345e0
jmp 0x346b0
movq -0x40(%rbp), %rdi
addq $0x40, %rdi
callq 0x439c0
cmpb $0x0, %al
je 0x348b9
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
ucomiss 0x4c(%rax), %xmm0
jbe 0x346dc
xorps %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
jmp 0x34719
movq -0x40(%rbp), %rax
movss 0x4c(%rax), %xmm0
movss 0x1091b(%rip), %xmm1    # 0x45008
ucomiss %xmm1, %xmm0
jbe 0x34701
movss 0x1090e(%rip), %xmm0    # 0x45008
movss %xmm0, -0x58(%rbp)
jmp 0x3470f
movq -0x40(%rbp), %rax
movss 0x4c(%rax), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movq -0x40(%rbp), %rax
movss -0x54(%rbp), %xmm0
movss %xmm0, 0x4c(%rax)
movq %rax, %rdi
addq $0x40, %rdi
addq $0x8, %rdi
movss 0x4c(%rax), %xmm0
movss 0x50(%rax), %xmm1
callq 0x342e0
movq -0x40(%rbp), %rax
movss 0x54(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movss 0x48(%rax), %xmm0
movss 0x108a8(%rip), %xmm1    # 0x45008
addss 0x54(%rax), %xmm1
mulss %xmm1, %xmm0
divss 0x54(%rax), %xmm0
callq 0x439a0
movaps %xmm0, %xmm1
movsd 0x112ea(%rip), %xmm0    # 0x45a68
callq 0x43970
movq -0x40(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x60(%rbp), %xmm0
movss 0x54(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x348b7
movl -0xc(%rbp), %eax
addl -0x30(%rbp), %eax
movl $0x46500, %ecx          # imm = 0x46500
xorl %edx, %edx
divl %ecx
movq -0x40(%rbp), %rax
movl %edx, -0x34(%rbp)
movss 0x10817(%rip), %xmm0    # 0x45008
subss -0x2c(%rbp), %xmm0
movss 0x40(%rax), %xmm2
movq (%rax), %rcx
movl -0x34(%rbp), %edx
addl $0x0, %edx
movl %edx, %edx
subss (%rcx,%rdx,4), %xmm2
movss 0x40(%rax), %xmm1
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x40(%rax)
movss 0x107d5(%rip), %xmm0    # 0x45008
subss -0x2c(%rbp), %xmm0
movss 0x44(%rax), %xmm2
movq (%rax), %rcx
movl -0x34(%rbp), %edx
addl $0x1, %edx
movl %edx, %edx
subss (%rcx,%rdx,4), %xmm2
movss 0x44(%rax), %xmm1
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x44(%rax)
movss 0x40(%rax), %xmm1
movq (%rax), %rcx
movl -0x34(%rbp), %edx
addl $0x0, %edx
movl %edx, %edx
movss (%rcx,%rdx,4), %xmm0
subss %xmm1, %xmm0
movss %xmm0, (%rcx,%rdx,4)
movss 0x44(%rax), %xmm1
movq (%rax), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movss (%rax,%rcx,4), %xmm0
subss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x347c7
jmp 0x348b9
addq $0x60, %rsp
popq %rbp
retq
nop