// File: /workspace/github_c_makefile_star2_O1/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, 0x8bf6(%rip)      # 0x11691
jne 0x8dd7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movzwl 0x8be6(%rip), %eax      # 0x1169c
shll $0x5, %eax
movl $0x10000, %ecx          # imm = 0x10000
subl %eax, %ecx
cvtsi2ss %ecx, %xmm1
movss 0x479c(%rip), %xmm0     # 0xd268
divss %xmm1, %xmm0
movaps %xmm0, %xmm1
divss 0x4781(%rip), %xmm1     # 0xd25c
movss %xmm1, 0x8bc1(%rip)     # 0x116a4
divss 0x4775(%rip), %xmm0     # 0xd260
callq 0x51f0
divss 0x8aac(%rip), %xmm0     # 0x115a4
callq 0x50d0
cvttss2si %xmm0, %eax
cmpl $-0x2f, %eax
movl $0xffffffd0, %ecx       # imm = 0xFFFFFFD0
cmovgel %eax, %ecx
addl $0x30, %ecx
movl %ecx, 0x8b97(%rip)      # 0x116ac
movss 0x8b87(%rip), %xmm0     # 0x116a4
mulss 0x4753(%rip), %xmm0     # 0xd278
movss %xmm0, 0x8b77(%rip)     # 0x116a4
movq 0x8c3c(%rip), %r14      # 0x11770
testq %r14, %r14
je 0x8dc9
movss 0x8a5b(%rip), %xmm0     # 0x115a0
movss %xmm0, 0x8(%rsp)
movb 0x8a58(%rip), %bpl      # 0x115aa
movss 0x8c1e(%rip), %xmm0     # 0x11778
movss %xmm0, 0x4(%rsp)
movq 0x8c19(%rip), %r15      # 0x11780
movss 0x8c19(%rip), %xmm0     # 0x11788
movss %xmm0, (%rsp)
leaq 0x8b15(%rip), %rbx      # 0x11690
leaq 0x88be(%rip), %r13      # 0x11440
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x863a
movss 0x46ce(%rip), %xmm8     # 0xd264
movss 0x346e(%rip), %xmm7     # 0xc00c
cmpb $0x1, 0x8aeb(%rip)      # 0x11690
jne 0x8dbc
movl 0x8af7(%rip), %esi      # 0x116a8
movslq 0x8adc(%rip), %rax      # 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
movzbl %dil, %edi
leaq -0x1(%rax), %rcx
shrl %cl, %edi
testq %rax, %rax
movl $0x0, %r8d
cmovel %r8d, %edi
movss 0x8a9f(%rip), %xmm0     # 0x116a4
movb %dil, 0x8af0(%rip)      # 0x116fc
movss 0x8a8c(%rip), %xmm2     # 0x116a0
addss %xmm0, %xmm2
ucomiss %xmm7, %xmm2
movaps %xmm2, %xmm3
addss %xmm8, %xmm3
movaps %xmm0, %xmm1
jbe 0x8c2c
subss %xmm3, %xmm1
movaps %xmm7, %xmm3
cmpltss %xmm2, %xmm3
andnps %xmm2, %xmm3
movss %xmm3, 0x8a61(%rip)     # 0x116a0
xorps %xmm4, %xmm4
xorps %xmm2, %xmm2
jbe 0x8cfa
xorps %xmm5, %xmm5
movl %esi, %r8d
leal 0x1(%r8), %esi
andl $0x1f, %esi
movl %esi, 0x8a4a(%rip)      # 0x116a8
movl %esi, %r9d
shrl %r9d
movb 0xff30(%rdx,%r9), %r9b
movl %r9d, %r10d
andb $0xf, %r10b
shrb $0x4, %r9b
testb $0x1, %r8b
movzbl %r10b, %r8d
movzbl %r9b, %r9d
cmovel %r8d, %r9d
movzbl %r9b, %r8d
shrl %cl, %r8d
movaps %xmm1, %xmm4
testl %eax, %eax
cmovel %eax, %r8d
movb %r8b, 0x8a5e(%rip)      # 0x116fc
movaps %xmm0, %xmm6
subss %xmm1, %xmm6
addss %xmm3, %xmm6
ucomiss %xmm7, %xmm6
movaps %xmm6, %xmm3
addss %xmm8, %xmm3
movaps %xmm0, %xmm1
jbe 0x8cbd
subss %xmm3, %xmm1
movaps %xmm4, %xmm3
subss %xmm5, %xmm3
divss %xmm0, %xmm3
movsbl %dil, %edi
xorps %xmm5, %xmm5
cvtsi2ss %edi, %xmm5
mulss %xmm3, %xmm5
addss %xmm5, %xmm2
movaps %xmm7, %xmm3
cmpltss %xmm6, %xmm3
andnps %xmm6, %xmm3
movss %xmm3, 0x89b2(%rip)     # 0x116a0
movaps %xmm4, %xmm5
movl %r8d, %edi
ja 0x8c4e
testl %eax, %eax
jle 0x8dbc
subss %xmm4, %xmm1
movzbl 0x89ef(%rip), %ecx      # 0x116fc
xorps %xmm3, %xmm3
cvtsi2ss %ecx, %xmm3
divss %xmm0, %xmm1
mulss %xmm1, %xmm3
addss %xmm2, %xmm3
movabsq $0x4070000040f00000, %rcx # imm = 0x4070000040F00000
movq %rcx, 0xc(%rsp)
movl $0x3fc00000, 0x14(%rsp) # imm = 0x3FC00000
subss 0x8(%rsp,%rax,4), %xmm3
divss 0x4537(%rip), %xmm3     # 0xd27c
movaps %xmm3, %xmm0
subss 0x8998(%rip), %xmm0     # 0x116e8
movaps %xmm0, %xmm1
mulss 0x8(%rsp), %xmm1
subss %xmm1, %xmm3
movss %xmm3, 0x8983(%rip)     # 0x116e8
testb $0x1, %bpl
jne 0x8dbc
movsbl 0x8920(%rip), %eax      # 0x11692
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss 0x44f3(%rip), %xmm0     # 0xd274
mulss %xmm0, %xmm1
mulss 0x4(%rsp), %xmm1
addss (%r15,%r12,4), %xmm1
movss %xmm1, (%r15,%r12,4)
movsbl 0x88f5(%rip), %eax      # 0x11693
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
mulss %xmm0, %xmm1
mulss (%rsp), %xmm1
addss 0x4(%r15,%r12,4), %xmm1
movss %xmm1, 0x4(%r15,%r12,4)
addq $0x2, %r12
cmpq %r12, %r14
ja 0x8b85
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq