// File: /workspace/github_c_makefile_star2_O3/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 %rbx
pushq %rax
movl %edx, %ebx
movq %rdi, %r14
movss 0x18(%rdi), %xmm0
xorps %xmm4, %xmm4
ucomiss %xmm4, %xmm0
movl %esi, %r15d
movss 0x1c(%rdi), %xmm1
movss 0x8(%rdi), %xmm2
movss 0xc(%rdi), %xmm3
ja 0x25ea2
ucomiss %xmm4, %xmm1
ja 0x25ea2
xorps %xmm5, %xmm5
ucomiss %xmm5, %xmm2
ja 0x25ea2
ucomiss %xmm5, %xmm3
jbe 0x25fa2
movss 0x10(%r14), %xmm5
ucomiss %xmm4, %xmm5
jbe 0x25ebc
ucomiss %xmm2, %xmm3
jbe 0x25ebc
addss %xmm5, %xmm2
minss %xmm3, %xmm2
jmp 0x25ece
ucomiss %xmm5, %xmm4
jbe 0x25ed4
ucomiss %xmm3, %xmm2
jbe 0x25ed4
addss %xmm5, %xmm2
maxss %xmm3, %xmm2
movss %xmm2, 0x8(%r14)
movss 0x20(%r14), %xmm2
xorps %xmm3, %xmm3
ucomiss %xmm3, %xmm2
jbe 0x25ef1
ucomiss %xmm0, %xmm1
jbe 0x25ef1
addss %xmm0, %xmm2
minss %xmm1, %xmm2
jmp 0x25f03
ucomiss %xmm2, %xmm3
jbe 0x25f0c
ucomiss %xmm1, %xmm0
jbe 0x25f0c
addss %xmm0, %xmm2
maxss %xmm1, %xmm2
movaps %xmm2, %xmm0
movss %xmm2, 0x18(%r14)
ucomiss 0x24(%r14), %xmm0
jne 0x25f15
jnp 0x25f34
movss 0xa347(%rip), %xmm1     # 0x30264
mulss %xmm0, %xmm1
addss %xmm1, %xmm1
cvttss2si %xmm1, %rax
movl %eax, 0x14(%r14)
movss %xmm0, 0x24(%r14)
testl %ebx, %ebx
je 0x25fa2
movq (%r14), %rax
movl %r15d, %ecx
subl 0x14(%r14), %ecx
addl $0x46500, %ecx          # imm = 0x46500
movl $0xe90452d5, %edx       # imm = 0xE90452D5
movl %r15d, %esi
movl %ebx, %edi
movl %ecx, %r8d
imulq %rdx, %r8
shrq $0x32, %r8
imull $0x46500, %r8d, %r8d    # imm = 0x46500
movl %ecx, %r9d
subl %r8d, %r9d
movl %esi, %r8d
imulq %rdx, %r8
shrq $0x32, %r8
imull $0x46500, %r8d, %r8d    # imm = 0x46500
movl %esi, %r10d
subl %r8d, %r10d
movss (%rax,%r9,4), %xmm0
mulss 0x8(%r14), %xmm0
addss (%rax,%r10,4), %xmm0
movss %xmm0, (%rax,%r10,4)
incl %ecx
incl %esi
decl %edi
jne 0x25f52
movss 0x30(%r14), %xmm1
movss 0x34(%r14), %xmm2
movss 0xa04e(%rip), %xmm3     # 0x30004
ucomiss %xmm1, %xmm3
ja 0x25fcc
movss 0xa041(%rip), %xmm0     # 0x30004
ucomiss %xmm2, %xmm0
jbe 0x26105
xorps %xmm4, %xmm4
ucomiss %xmm2, %xmm4
xorps %xmm0, %xmm0
ja 0x25fe2
ucomiss %xmm3, %xmm2
movaps %xmm3, %xmm0
ja 0x25fe2
movaps %xmm2, %xmm0
movss %xmm0, 0x34(%r14)
movss 0x38(%r14), %xmm2
ucomiss %xmm4, %xmm2
jbe 0x26002
ucomiss %xmm1, %xmm0
jbe 0x26002
addss %xmm1, %xmm2
minss %xmm0, %xmm2
jmp 0x26017
xorps %xmm3, %xmm3
ucomiss %xmm2, %xmm3
jbe 0x26020
ucomiss %xmm0, %xmm1
jbe 0x26020
addss %xmm1, %xmm2
maxss %xmm0, %xmm2
movaps %xmm2, %xmm1
movss %xmm2, 0x30(%r14)
movss 0x3c(%r14), %xmm2
movss 0x9fd6(%rip), %xmm0     # 0x30004
addss %xmm2, %xmm0
mulss %xmm1, %xmm0
movss %xmm2, -0x1c(%rbp)
divss %xmm2, %xmm0
callq 0x2470
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0xaa3d(%rip), %xmm0     # 0x30a90
callq 0x2220
testl %ebx, %ebx
je 0x26105
xorps %xmm1, %xmm1
cvtss2sd -0x1c(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x3c(%r14), %xmm2
mulsd %xmm0, %xmm1
subsd %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movq (%r14), %rax
xorps 0x9fb6(%rip), %xmm0     # 0x30040
movss 0x2c(%r14), %xmm1
xorl %ecx, %ecx
movl $0xe90452d5, %edx       # imm = 0xE90452D5
movl %r15d, %esi
movl %esi, %edi
imulq %rdx, %rdi
shrq $0x32, %rdi
imull $0x46500, %edi, %edi    # imm = 0x46500
movl %r15d, %r8d
subl %edi, %r8d
addl %ecx, %r8d
movss 0x28(%r14), %xmm2
movaps %xmm2, %xmm3
subss (%rax,%r8,4), %xmm3
mulss %xmm0, %xmm3
addss %xmm2, %xmm3
movss %xmm3, 0x28(%r14)
movaps %xmm1, %xmm2
subss 0x4(%rax,%r8,4), %xmm2
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x2c(%r14)
movss %xmm3, (%rax,%r8,4)
movss 0x2c(%r14), %xmm1
movss %xmm1, 0x4(%rax,%r8,4)
addl $0x2, %ecx
addl $0x2, %esi
cmpl %ebx, %ecx
jb 0x2609a
movss 0x48(%r14), %xmm1
movss 0x4c(%r14), %xmm2
movss 0x9eeb(%rip), %xmm3     # 0x30004
ucomiss %xmm1, %xmm3
ja 0x2612f
movss 0x9ede(%rip), %xmm0     # 0x30004
ucomiss %xmm2, %xmm0
jbe 0x2627c
xorps %xmm4, %xmm4
ucomiss %xmm2, %xmm4
xorps %xmm0, %xmm0
ja 0x26145
ucomiss %xmm3, %xmm2
movaps %xmm3, %xmm0
ja 0x26145
movaps %xmm2, %xmm0
movss %xmm0, 0x4c(%r14)
movss 0x50(%r14), %xmm2
ucomiss %xmm4, %xmm2
jbe 0x26165
ucomiss %xmm1, %xmm0
jbe 0x26165
addss %xmm1, %xmm2
minss %xmm0, %xmm2
jmp 0x2617a
xorps %xmm3, %xmm3
ucomiss %xmm2, %xmm3
jbe 0x26183
ucomiss %xmm0, %xmm1
jbe 0x26183
addss %xmm1, %xmm2
maxss %xmm0, %xmm2
movaps %xmm2, %xmm1
movss %xmm2, 0x48(%r14)
movss 0x54(%r14), %xmm2
movss 0x9e73(%rip), %xmm0     # 0x30004
addss %xmm2, %xmm0
mulss %xmm1, %xmm0
movss %xmm2, -0x1c(%rbp)
divss %xmm2, %xmm0
callq 0x2470
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0xa8da(%rip), %xmm0     # 0x30a90
callq 0x2220
testl %ebx, %ebx
je 0x2627c
xorps %xmm1, %xmm1
cvtss2sd -0x1c(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x54(%r14), %xmm2
mulsd %xmm0, %xmm1
subsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss 0x9e1c(%rip), %xmm0     # 0x30004
subss %xmm1, %xmm0
xorps 0x9e4d(%rip), %xmm0     # 0x30040
movq (%r14), %rax
xorl %ecx, %ecx
movl $0xe90452d5, %edx       # imm = 0xE90452D5
movl %r15d, %esi
movl %esi, %edi
imulq %rdx, %rdi
shrq $0x32, %rdi
imull $0x46500, %edi, %r8d    # imm = 0x46500
movl %r15d, %edi
subl %r8d, %edi
addl %ecx, %edi
movss 0x40(%r14), %xmm1
movaps %xmm1, %xmm2
subss (%rax,%rdi,4), %xmm2
movss 0x44(%r14), %xmm3
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x40(%r14)
movaps %xmm3, %xmm1
subss 0x4(%rax,%rdi,4), %xmm1
mulss %xmm0, %xmm1
addss %xmm3, %xmm1
movss %xmm1, 0x44(%r14)
movss (%rax,%rdi,4), %xmm1
movss 0x4(%rax,%rdi,4), %xmm3
subss %xmm2, %xmm1
movss %xmm1, (%rax,%rdi,4)
subss 0x44(%r14), %xmm3
movss %xmm3, 0x4(%rax,%rdi,4)
addl $0x2, %ecx
addl $0x2, %esi
cmpl %ebx, %ecx
jb 0x26200
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop