// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %r14d
movq %rdi, %r15
movss 0x18(%rdi), %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm2, %xmm0
movss 0x8(%rdi), %xmm0
ja 0x2623c
movss 0x1c(%r15), %xmm1
ucomiss %xmm2, %xmm1
ja 0x2623c
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
ja 0x2623c
movss 0xc(%r15), %xmm3
ucomiss %xmm1, %xmm3
jbe 0x26354
movss 0xc(%r15), %xmm1
movss 0x10(%r15), %xmm3
ucomiss %xmm2, %xmm3
jbe 0x2625c
ucomiss %xmm0, %xmm1
jbe 0x2625c
addss %xmm3, %xmm0
minss %xmm1, %xmm0
jmp 0x2626e
ucomiss %xmm3, %xmm2
jbe 0x26274
ucomiss %xmm1, %xmm0
jbe 0x26274
addss %xmm3, %xmm0
maxss %xmm1, %xmm0
movss %xmm0, 0x8(%r15)
movss 0x1c(%r15), %xmm1
movss 0x20(%r15), %xmm0
ucomiss %xmm2, %xmm0
jbe 0x2629a
movss 0x18(%r15), %xmm3
ucomiss %xmm3, %xmm1
jbe 0x2629a
addss %xmm3, %xmm0
minss %xmm1, %xmm0
jmp 0x262b2
ucomiss %xmm0, %xmm2
jbe 0x262b8
movss 0x18(%r15), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x262b8
addss %xmm2, %xmm0
maxss %xmm1, %xmm0
movss %xmm0, 0x18(%r15)
movss 0x18(%r15), %xmm0
ucomiss 0x24(%r15), %xmm0
jne 0x262c7
jnp 0x262e6
movss 0x9f95(%rip), %xmm1     # 0x30264
mulss %xmm0, %xmm1
addss %xmm1, %xmm1
cvttss2si %xmm1, %rax
movl %eax, 0x14(%r15)
movss %xmm0, 0x24(%r15)
testl %ebx, %ebx
je 0x26354
movq (%r15), %rax
movl %r14d, %ecx
subl 0x14(%r15), %ecx
addl $0x46500, %ecx          # imm = 0x46500
movl $0xe90452d5, %edx       # imm = 0xE90452D5
movl %r14d, %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(%r15), %xmm0
addss (%rax,%r10,4), %xmm0
movss %xmm0, (%rax,%r10,4)
incl %ecx
incl %esi
decl %edi
jne 0x26304
movss 0x9ca8(%rip), %xmm1     # 0x30004
ucomiss 0x30(%r15), %xmm1
ja 0x26376
movss 0x9c99(%rip), %xmm0     # 0x30004
ucomiss 0x34(%r15), %xmm0
jbe 0x264c0
movss 0x34(%r15), %xmm3
xorps %xmm2, %xmm2
ucomiss %xmm3, %xmm2
xorps %xmm0, %xmm0
ja 0x26392
ucomiss %xmm1, %xmm3
movaps %xmm1, %xmm0
ja 0x26392
movaps %xmm3, %xmm0
movss %xmm0, 0x34(%r15)
movss 0x38(%r15), %xmm1
ucomiss %xmm2, %xmm1
jbe 0x263b8
movss 0x30(%r15), %xmm2
ucomiss %xmm2, %xmm0
jbe 0x263b8
addss %xmm2, %xmm1
minss %xmm0, %xmm1
jmp 0x263d3
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x263d9
movss 0x30(%r15), %xmm2
ucomiss %xmm0, %xmm2
jbe 0x263d9
addss %xmm2, %xmm1
maxss %xmm0, %xmm1
movss %xmm1, 0x30(%r15)
movss 0x3c(%r15), %xmm1
movss 0x9c1d(%rip), %xmm0     # 0x30004
addss %xmm1, %xmm0
mulss 0x30(%r15), %xmm0
movss %xmm1, -0x1c(%rbp)
divss %xmm1, %xmm0
callq 0x2470
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0xa692(%rip), %xmm0     # 0x30aa0
callq 0x2220
testl %ebx, %ebx
je 0x264c0
xorps %xmm1, %xmm1
cvtss2sd -0x1c(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x3c(%r15), %xmm2
mulsd %xmm0, %xmm1
subsd %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
xorps 0x9bfe(%rip), %xmm0     # 0x30040
movq (%r15), %rax
xorl %ecx, %ecx
movl $0xe90452d5, %edx       # imm = 0xE90452D5
movl %r14d, %esi
movl %esi, %edi
imulq %rdx, %rdi
shrq $0x32, %rdi
imull $0x46500, %edi, %edi    # imm = 0x46500
movl %r14d, %r8d
subl %edi, %r8d
addl %ecx, %r8d
movss 0x28(%r15), %xmm1
movaps %xmm1, %xmm2
subss (%rax,%r8,4), %xmm2
movss 0x2c(%r15), %xmm3
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x28(%r15)
movaps %xmm3, %xmm1
subss 0x4(%rax,%r8,4), %xmm1
mulss %xmm0, %xmm1
addss %xmm3, %xmm1
movss %xmm1, 0x2c(%r15)
movss %xmm2, (%rax,%r8,4)
movss 0x2c(%r15), %xmm1
movss %xmm1, 0x4(%rax,%r8,4)
addl $0x2, %ecx
addl $0x2, %esi
cmpl %ebx, %ecx
jb 0x2644f
movss 0x9b3c(%rip), %xmm1     # 0x30004
ucomiss 0x48(%r15), %xmm1
ja 0x264e2
movss 0x9b2d(%rip), %xmm0     # 0x30004
ucomiss 0x4c(%r15), %xmm0
jbe 0x26640
movss 0x4c(%r15), %xmm3
xorps %xmm2, %xmm2
ucomiss %xmm3, %xmm2
xorps %xmm0, %xmm0
ja 0x264fe
ucomiss %xmm1, %xmm3
movaps %xmm1, %xmm0
ja 0x264fe
movaps %xmm3, %xmm0
movss %xmm0, 0x4c(%r15)
movss 0x50(%r15), %xmm1
ucomiss %xmm2, %xmm1
jbe 0x26524
movss 0x48(%r15), %xmm2
ucomiss %xmm2, %xmm0
jbe 0x26524
addss %xmm2, %xmm1
minss %xmm0, %xmm1
jmp 0x2653f
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x26545
movss 0x48(%r15), %xmm2
ucomiss %xmm0, %xmm2
jbe 0x26545
addss %xmm2, %xmm1
maxss %xmm0, %xmm1
movss %xmm1, 0x48(%r15)
movss 0x54(%r15), %xmm1
movss 0x9ab1(%rip), %xmm0     # 0x30004
addss %xmm1, %xmm0
mulss 0x48(%r15), %xmm0
movss %xmm1, -0x1c(%rbp)
divss %xmm1, %xmm0
callq 0x2470
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movsd 0xa526(%rip), %xmm0     # 0x30aa0
callq 0x2220
testl %ebx, %ebx
je 0x26640
xorps %xmm1, %xmm1
cvtss2sd -0x1c(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x54(%r15), %xmm2
mulsd %xmm0, %xmm1
subsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss 0x9a58(%rip), %xmm0     # 0x30004
subss %xmm1, %xmm0
xorps 0x9a89(%rip), %xmm0     # 0x30040
movq (%r15), %rax
xorl %ecx, %ecx
movl $0xe90452d5, %edx       # imm = 0xE90452D5
movl %r14d, %esi
movl %esi, %edi
imulq %rdx, %rdi
shrq $0x32, %rdi
imull $0x46500, %edi, %r8d    # imm = 0x46500
movl %r14d, %edi
subl %r8d, %edi
addl %ecx, %edi
movss 0x40(%r15), %xmm1
movaps %xmm1, %xmm2
subss (%rax,%rdi,4), %xmm2
movss 0x44(%r15), %xmm3
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x40(%r15)
movaps %xmm3, %xmm1
subss 0x4(%rax,%rdi,4), %xmm1
mulss %xmm0, %xmm1
addss %xmm3, %xmm1
movss %xmm1, 0x44(%r15)
movss (%rax,%rdi,4), %xmm1
movss 0x4(%rax,%rdi,4), %xmm3
subss %xmm2, %xmm1
movss %xmm1, (%rax,%rdi,4)
subss 0x44(%r15), %xmm3
movss %xmm3, 0x4(%rax,%rdi,4)
addl $0x2, %ecx
addl $0x2, %esi
cmpl %ebx, %ecx
jb 0x265c4
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop