// File: /workspace/github_c_makefile_star2_O0/DrYerzinia[P]C_DigiMode/src/packet/AFSK_Demodulator.c
// Function: AFSK_Demodulator_reset
void AFSK_Demodulator_reset(AFSK_Demodulator *self){

	self->count_last = 0;

	self->window = (int)(self->sample_rate/self->bit_rate+0.5);

	self->bitwidth = self->sample_rate/self->bit_rate;

	/*
	 * Calculate Goertzel coefficents for calculating frequency magnitudes
	 */
	float k0 = ((float)self->window*self->frequency_0/self->sample_rate);
	float k1 = ((float)self->window*self->frequency_1/self->sample_rate);
	float w0 = (2*PI/self->window)*k0;
	float w1 = (2*PI/self->window)*k1;

	self->coeff0 = 2*cos(w0);
	self->coeff1 = 2*cos(w1);

	self->last_bit = 0;

	self->bit_stuffing = false;

	if(self->input_buffer.size != 0)
		char_ring_buffer_destory(&self->input_buffer);
	char_ring_buffer_init(&self->input_buffer, self->window+2);

	if(self->fcd_buffer.size != 0)
		float_ring_buffer_destory(&self->fcd_buffer);
	float_ring_buffer_init(&self->fcd_buffer, self->window+2);

	char_array_expandable_clear(&self->byte_sequence);
	char_ring_buffer_clear(&self->bit_sequence);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movw $0x0, 0x3c(%rax)
movq -0x8(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movl 0x20(%rcx), %eax
movzwl 0x24(%rcx), %ecx
xorl %edx, %edx
movl %edx, -0x2c(%rbp)
divl %ecx
movl -0x2c(%rbp), %edx
movl %eax, %ecx
movq -0x28(%rbp), %rax
cvtsi2sd %rcx, %xmm0
movsd 0x24a6(%rip), %xmm1     # 0x4018
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movb %cl, 0x26(%rax)
movq -0x8(%rbp), %rcx
movq %rcx, -0x20(%rbp)
movl 0x20(%rcx), %eax
movzwl 0x24(%rcx), %ecx
divl %ecx
movl %eax, %ecx
movq -0x20(%rbp), %rax
movb %cl, 0x3e(%rax)
movq -0x8(%rbp), %rax
movzbl 0x26(%rax), %ecx
cvtsi2ss %ecx, %xmm0
movzwl 0x28(%rax), %ecx
cvtsi2ss %ecx, %xmm1
mulss %xmm1, %xmm0
movl 0x20(%rax), %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x26(%rax), %ecx
cvtsi2ss %ecx, %xmm0
movzwl 0x2a(%rax), %ecx
cvtsi2ss %ecx, %xmm1
mulss %xmm1, %xmm0
movl 0x20(%rax), %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x26(%rax), %eax
cvtsi2sd %eax, %xmm1
movsd 0x2413(%rip), %xmm0     # 0x4010
divsd %xmm1, %xmm0
movss -0xc(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x14(%rbp)
movq -0x8(%rbp), %rax
movzbl 0x26(%rax), %eax
cvtsi2sd %eax, %xmm1
movsd 0x23e5(%rip), %xmm0     # 0x4010
divsd %xmm1, %xmm0
movss -0x10(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x18(%rbp)
movss -0x14(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10a0
movaps %xmm0, %xmm1
movsd 0x23aa(%rip), %xmm0     # 0x4008
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x2c(%rax)
movss -0x18(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x10a0
movaps %xmm0, %xmm1
movsd 0x2380(%rip), %xmm0     # 0x4008
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x30(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x58(%rax)
movq -0x8(%rbp), %rax
movb $0x0, 0x59(%rax)
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %eax
cmpl $0x0, %eax
je 0x1cbf
movq -0x8(%rbp), %rdi
callq 0x1890
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movzbl 0x26(%rax), %eax
addl $0x2, %eax
movzwl %ax, %esi
callq 0x1660
movq -0x8(%rbp), %rax
movzwl 0x1c(%rax), %eax
cmpl $0x0, %eax
je 0x1cf0
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
callq 0x1640
movq -0x8(%rbp), %rdi
addq $0x10, %rdi
movq -0x8(%rbp), %rax
movzbl 0x26(%rax), %eax
addl $0x2, %eax
movzwl %ax, %esi
callq 0x1410
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
callq 0x13d0
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
callq 0x1810
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)