// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
leaq 0xb461(%rip), %rax      # 0x16a80
addq $0xe0, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x1(%rax)
jne 0xb638
jmp 0xb8df
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %ecx
movl $0x800, %eax            # imm = 0x800
subl %ecx, %eax
shll $0x5, %eax
cvtsi2ss %eax, %xmm1
movss 0x6232(%rip), %xmm0     # 0x11888
divss %xmm1, %xmm0
movss %xmm0, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movss -0xc(%rbp), %xmm0
callq 0xae20
movq -0x8(%rbp), %rax
movss 0x621b(%rip), %xmm0     # 0x11894
mulss 0x14(%rax), %xmm0
movss %xmm0, 0x14(%rax)
movl $0x0, -0x10(%rbp)
movslq -0x10(%rbp), %rax
cmpq 0xb5ab(%rip), %rax      # 0x16c40
jae 0xb8df
movq -0x8(%rbp), %rdi
callq 0xb0f0
movq -0x8(%rbp), %rax
testb $0x1, (%rax)
je 0xb8cf
xorps %xmm0, %xmm0
movss %xmm0, -0x14(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x8(%rbp), %rax
movl 0x4(%rax), %esi
callq 0xb8f0
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x6c(%rax)
movq -0x8(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0xb170
testb $0x1, %al
jne 0xb6f8
jmp 0xb764
movq -0x8(%rbp), %rax
movl 0x18(%rax), %ecx
incl %ecx
andl $0x1f, %ecx
movl %ecx, 0x18(%rax)
movss -0x14(%rbp), %xmm0
movss -0x18(%rbp), %xmm1
subss %xmm1, %xmm0
movq -0x8(%rbp), %rax
movss 0x14(%rax), %xmm1
divss %xmm1, %xmm0
movzbl 0x6c(%rax), %eax
cvtsi2ss %eax, %xmm2
movss -0x1c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %edi
movq -0x8(%rbp), %rax
movl 0x4(%rax), %esi
callq 0xb8f0
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x6c(%rax)
movss -0x14(%rbp), %xmm0
movss %xmm0, -0x18(%rbp)
jmp 0xb6e5
movss -0x14(%rbp), %xmm0
movss -0x18(%rbp), %xmm1
subss %xmm1, %xmm0
movq -0x8(%rbp), %rax
movss 0x14(%rax), %xmm1
divss %xmm1, %xmm0
movzbl 0x6c(%rax), %eax
cvtsi2ss %eax, %xmm2
movss -0x1c(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jle 0xb8cd
movss 0x60e9(%rip), %xmm0     # 0x11898
movss %xmm0, -0x2c(%rbp)
movss 0x60e4(%rip), %xmm0     # 0x118a0
movss %xmm0, -0x28(%rbp)
movss 0x60d3(%rip), %xmm0     # 0x1189c
movss %xmm0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
cltq
movss -0x2c(%rbp,%rax,4), %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movss -0x1c(%rbp), %xmm0
subss -0x20(%rbp), %xmm0
movss 0x609d(%rip), %xmm1     # 0x11898
divss %xmm1, %xmm0
callq 0xadc0
movss %xmm0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
leaq 0xb26c(%rip), %rcx      # 0x16a80
subq %rcx, %rax
movl $0x70, %ecx
cqto
idivq %rcx
movq %rax, %rcx
leaq 0xb24d(%rip), %rax      # 0x16a78
testb $0x1, (%rax,%rcx)
jne 0xb8cb
movss 0x6053(%rip), %xmm0     # 0x11890
mulss -0x1c(%rbp), %xmm0
movq -0x8(%rbp), %rax
movb 0x2(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
movss 0xb3ea(%rip), %xmm2     # 0x16c48
movq 0xb3eb(%rip), %rax      # 0x16c50
movl -0x10(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
movss 0x6008(%rip), %xmm0     # 0x11890
mulss -0x1c(%rbp), %xmm0
movq -0x8(%rbp), %rax
movb 0x3(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2ss %eax, %xmm1
mulss %xmm1, %xmm0
movss 0xb3af(%rip), %xmm2     # 0x16c58
movq 0xb3a0(%rip), %rax      # 0x16c50
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax,%rcx,4)
jmp 0xb8cd
jmp 0xb8cf
jmp 0xb8d1
movl -0x10(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x10(%rbp)
jmp 0xb68a
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)