// File: /workspace/github_c_makefile_star2_O3/baines[P]MiniGBS/audio.c
// Function: update_wave
void update_wave(void){
	struct chan* c = chans + 2;
	if(!c->powered) return;

	float freq = 4194304.0f / (float)((2048 - c->freq) << 5);
	set_note_freq(c, freq);

	c->freq_inc *= 16.0f;

	for(int i = 0; i < nsamples; i+=2){
		update_len(c);

		if(c->enabled){
			float pos = 0.0f;
			float prev_pos = 0.0f;
			float sample = 0.0f;

			c->sample = wave_sample(c->val, c->volume);

			while(update_freq(c, &pos)){
				c->val = (c->val + 1) & 31;
				sample += ((pos - prev_pos) / c->freq_inc) * (float)c->sample;
				c->sample = wave_sample(c->val, c->volume);
				prev_pos = pos;
			}
			sample += ((pos - prev_pos) / c->freq_inc) * (float)c->sample;

			if(c->volume > 0){
				float diff = (float[]){ 7.5f, 3.75f, 1.5f }[c->volume - 1];
				sample = hipass(c, (sample - diff) / 7.5f);

				if(!muted[c-chans]){
					samples[i+0] += sample * 0.25f * c->on_left * vol_l;
					samples[i+1] += sample * 0.25f * c->on_right * vol_r;
				}
			}
		}
	}
}

// Assembly:
cmpb $0x1, 0x8ce4(%rip)      # 0x11691
jne 0x8cb6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movzwl 0x8cd4(%rip), %eax      # 0x1169c
shll $0x5, %eax
movl $0x10000, %ecx          # imm = 0x10000
subl %eax, %ecx
cvtsi2ss %ecx, %xmm1
movss 0x48ba(%rip), %xmm0     # 0xd298
divss %xmm1, %xmm0
movaps %xmm0, %xmm1
divss 0x489f(%rip), %xmm1     # 0xd28c
movss %xmm1, 0x8caf(%rip)     # 0x116a4
divss 0x4893(%rip), %xmm0     # 0xd290
callq 0x51f0
divss 0x8b9a(%rip), %xmm0     # 0x115a4
callq 0x50d0
cvttss2si %xmm0, %eax
cmpl $-0x2f, %eax
movl $0xffffffd0, %ecx       # imm = 0xFFFFFFD0
cmovgel %eax, %ecx
addl $0x30, %ecx
movl %ecx, 0x8c85(%rip)      # 0x116ac
movss 0x8c75(%rip), %xmm0     # 0x116a4
mulss 0x4871(%rip), %xmm0     # 0xd2a8
movss %xmm0, 0x8c65(%rip)     # 0x116a4
movq 0x8d2a(%rip), %r14      # 0x11770
testq %r14, %r14
je 0x8ca8
movss 0x8b49(%rip), %xmm0     # 0x115a0
movss %xmm0, 0xc(%rsp)
movb 0x8b46(%rip), %bpl      # 0x115aa
movq 0x8d15(%rip), %r15      # 0x11780
movss 0x8d15(%rip), %xmm0     # 0x11788
movss 0x8cfd(%rip), %xmm1     # 0x11778
unpcklps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movaps %xmm1, 0x20(%rsp)
leaq 0x8c06(%rip), %rbx      # 0x11690
leaq 0x89af(%rip), %r13      # 0x11440
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x8587
xorps %xmm7, %xmm7
movss 0x47ed(%rip), %xmm6     # 0xd294
movss 0x35ad(%rip), %xmm5     # 0xc05c
cmpb $0x1, 0x8bda(%rip)      # 0x11690
jne 0x8c9b
movl 0x8be6(%rip), %esi      # 0x116a8
movl 0x8bcc(%rip), %eax      # 0x11694
movq (%r13), %rdx
movl %esi, %ecx
shrl $0x1f, %ecx
addl %esi, %ecx
sarl %ecx
movslq %ecx, %rcx
movb 0xff30(%rdx,%rcx), %cl
movl %ecx, %edi
andb $0xf, %dil
shrb $0x4, %cl
testb $0x1, %sil
movzbl %cl, %ecx
movzbl %dil, %edi
cmovel %ecx, %edi
leal -0x1(%rax), %ecx
movzbl %dil, %edi
shrl %cl, %edi
movl %eax, %ecx
subl $0x1, %ecx
movl $0x0, %r8d
cmovbl %r8d, %edi
movss 0x8b8e(%rip), %xmm0     # 0x116a4
movb %dil, 0x8bdf(%rip)      # 0x116fc
movss 0x8b7b(%rip), %xmm2     # 0x116a0
addss %xmm0, %xmm2
movss %xmm2, 0x8b6f(%rip)     # 0x116a0
xorps %xmm3, %xmm3
ucomiss %xmm5, %xmm2
jbe 0x8be9
xorps %xmm1, %xmm1
xorps %xmm4, %xmm4
movl $0x0, 0x8b53(%rip)      # 0x116a0
leal 0x1(%rsi), %r9d
andl $0x1f, %r9d
movl %r9d, 0x8b4c(%rip)      # 0x116a8
movl %r9d, %r8d
shrl %r8d
movb 0xff30(%rdx,%r8), %r8b
movl %r8d, %r10d
andb $0xf, %r10b
shrb $0x4, %r8b
testb $0x1, %sil
movzbl %r10b, %esi
movzbl %r8b, %r8d
cmovel %esi, %r8d
movzbl %r8b, %r8d
shrl %cl, %r8d
testl %eax, %eax
addss %xmm6, %xmm2
movaps %xmm0, %xmm3
subss %xmm2, %xmm3
movaps %xmm3, %xmm2
subss %xmm4, %xmm2
movsbl %dil, %esi
xorps %xmm4, %xmm4
cvtsi2ss %esi, %xmm4
divss %xmm0, %xmm2
mulss %xmm2, %xmm4
cmovel %eax, %r8d
addss %xmm4, %xmm1
movb %r8b, 0x8b3a(%rip)      # 0x116fc
movaps %xmm0, %xmm2
subss %xmm3, %xmm2
ucomiss %xmm5, %xmm2
addss %xmm7, %xmm2
movss %xmm2, 0x8ac8(%rip)     # 0x116a0
movaps %xmm3, %xmm4
movl %r8d, %edi
movl %r9d, %esi
ja 0x8b43
jmp 0x8bef
movl %edi, %r8d
xorps %xmm1, %xmm1
testl %eax, %eax
jle 0x8c9b
movaps %xmm0, %xmm2
subss %xmm3, %xmm2
divss %xmm0, %xmm2
movsbl %r8b, %eax
xorps %xmm3, %xmm3
cvtsi2ss %eax, %xmm3
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
movsd 0x46b3(%rip), %xmm0     # 0xd2d0
movsd %xmm0, 0x10(%rsp)
movl $0x3fc00000, 0x18(%rsp) # imm = 0x3FC00000
movl %ecx, %eax
subss 0x10(%rsp,%rax,4), %xmm3
divss 0x4671(%rip), %xmm3     # 0xd2ac
movaps %xmm3, %xmm0
subss 0x8aa2(%rip), %xmm0     # 0x116e8
movaps %xmm0, %xmm1
mulss 0xc(%rsp), %xmm1
subss %xmm1, %xmm3
movss %xmm3, 0x8a8d(%rip)     # 0x116e8
testb $0x1, %bpl
jne 0x8c9b
mulss 0x463b(%rip), %xmm0     # 0xd2a4
movzwl 0x8a22(%rip), %eax      # 0x11692
movd %eax, %xmm1
xorps %xmm2, %xmm2
punpcklbw %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3],xmm1[4],xmm2[4],xmm1[5],xmm2[5],xmm1[6],xmm2[6],xmm1[7],xmm2[7]
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
cvtdq2ps %xmm1, %xmm1
unpcklps %xmm0, %xmm0            # xmm0 = xmm0[0,0,1,1]
mulps %xmm1, %xmm0
mulps 0x20(%rsp), %xmm0
movsd (%r15,%r12,4), %xmm1
addps %xmm0, %xmm1
movlps %xmm1, (%r15,%r12,4)
addq $0x2, %r12
cmpq %r12, %r14
ja 0x8a94
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq