// File: /workspace/github_c_makefile_star2_O0/DrYerzinia[P]C_DigiMode/src/psk31/psk31_tdtl.cpp
// Function: psk31_tdtl::proccess_byte(char)
bool psk31_tdtl::proccess_byte(char next_data_point){

	bool newByte = false;

	input_data[input_position] = next_data_point;

	if(input_count > input_data_width){


		int pos;
		pos = input_position+1;
		if(pos >= input_data_width) pos = pos - input_data_width;
		char y1 = input_data[pos];
		pos = (int)floor(1+input_position+ninty_deg_phase_width);
		if(pos >= input_data_width) pos = pos - input_data_width;
		char x1 = input_data[pos];
		pos = (int)floor(input_position-ninty_deg_phase_width+1.5);
		if(pos < 0) pos = input_data_width + pos;
		char y2 = input_data[pos];
		char x2 = input_data[input_position];

		float pd = std::abs(atan2(y1, x1)-atan2(y2, x2));
		if(pd > PI) pd = std::abs(pd-2*PI);
 		phase_change_data.push_back(pd);

	}

	input_position++;
	input_count++;

	if(input_position > input_data_width) input_position = 0;

	if(phase_change_data.size() >= bitwidth/4){

		float phase_change_sum = 0.0;

		for(std::list<float>::iterator it = phase_change_data.begin(); it != phase_change_data.end(); it++){

			phase_change_sum += (*it);

		}

		if(phase_change_sum > max) max = phase_change_sum;

		int current_value;

		if(phase_change_sum > threshhold_value*max)
			current_value = 1;
		else
			current_value = 0;

		if(last == -1) last = current_value;

		if(current_value != last){

			for(int i = 0; i < floor(((float)countlast)/((float)bitwidth)+0.5); i++)
				bit_sequence.push_back(current_value);

			if(bit_sequence.size() >= 2 && bit_sequence[bit_sequence.size()-1] == 0 && bit_sequence[bit_sequence.size()-2] == 0){
				int one = 1;
				int val = 0;
				for(int i = bit_sequence.size()-3; i >= 0; i--){
					if(bit_sequence[i] == 1)
						val |= one;
					one <<= 1;
				}

				newByte = true;

				byte_sequence.push_back(getVaricode(val));
				bit_sequence.clear();
			}

			last = current_value;
			countlast = 1;

		} else countlast++;

		phase_change_data.pop_front();

	}

	return newByte;

}

// Assembly:
subq $0x88, %rsp
movb %sil, %al
movq %rdi, 0x80(%rsp)
movb %al, 0x7f(%rsp)
movq 0x80(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movb $0x0, 0x7e(%rsp)
movb 0x7f(%rsp), %sil
movq 0x60(%rcx), %rax
movl 0x50(%rcx), %edx
movb %sil, (%rax,%rdx)
movl 0x54(%rcx), %eax
cmpl 0x58(%rcx), %eax
jbe 0xb698
movq 0x30(%rsp), %rcx
movl 0x50(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %eax
cmpl 0x58(%rcx), %eax
jb 0xb52c
movq 0x30(%rsp), %rcx
movl 0x78(%rsp), %eax
subl 0x58(%rcx), %eax
movl %eax, 0x78(%rsp)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movslq 0x78(%rsp), %rdx
movb (%rcx,%rdx), %cl
movb %cl, 0x77(%rsp)
movl 0x50(%rax), %ecx
incl %ecx
cvtsi2ss %rcx, %xmm0
addss 0x18(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x3430
movq 0x30(%rsp), %rcx
cvttsd2si %xmm0, %eax
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %eax
cmpl 0x58(%rcx), %eax
jb 0xb57f
movq 0x30(%rsp), %rcx
movl 0x78(%rsp), %eax
subl 0x58(%rcx), %eax
movl %eax, 0x78(%rsp)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rcx
movslq 0x78(%rsp), %rdx
movb (%rcx,%rdx), %cl
movb %cl, 0x76(%rsp)
movl 0x50(%rax), %ecx
cvtsi2ss %rcx, %xmm0
subss 0x18(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3b13(%rip), %xmm1     # 0xf0c0
addsd %xmm1, %xmm0
callq 0x3430
cvttsd2si %xmm0, %eax
movl %eax, 0x78(%rsp)
cmpl $0x0, 0x78(%rsp)
jge 0xb5d5
movq 0x30(%rsp), %rax
movl 0x58(%rax), %eax
addl 0x78(%rsp), %eax
movl %eax, 0x78(%rsp)
movq 0x30(%rsp), %rcx
movq 0x60(%rcx), %rax
movslq 0x78(%rsp), %rdx
movb (%rax,%rdx), %al
movb %al, 0x75(%rsp)
movq 0x60(%rcx), %rax
movl 0x50(%rcx), %ecx
movb (%rax,%rcx), %al
movb %al, 0x74(%rsp)
movsbl 0x77(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsbl 0x76(%rsp), %eax
cvtsi2sd %eax, %xmm1
callq 0x3090
movsd %xmm0, 0x28(%rsp)
movsbl 0x75(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsbl 0x74(%rsp), %eax
cvtsi2sd %eax, %xmm1
callq 0x3090
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
subsd %xmm1, %xmm0
callq 0xba00
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x70(%rsp)
movss 0x70(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3a6e(%rip), %xmm1     # 0xf0c8
ucomisd %xmm1, %xmm0
jbe 0xb685
movss 0x70(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3a5e(%rip), %xmm1     # 0xf0d0
subsd %xmm1, %xmm0
callq 0xba00
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x70(%rsp)
movq 0x30(%rsp), %rdi
addq $0x68, %rdi
leaq 0x70(%rsp), %rsi
callq 0xba20
movq 0x30(%rsp), %rcx
movl 0x50(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x50(%rcx)
movl 0x54(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x54(%rcx)
movl 0x50(%rcx), %eax
cmpl 0x58(%rcx), %eax
jbe 0xb6c3
movq 0x30(%rsp), %rax
movl $0x0, 0x50(%rax)
movq 0x30(%rsp), %rdi
addq $0x68, %rdi
callq 0xba60
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x20(%rsp)
movl 0x1c(%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
jb 0xb9e4
movq 0x30(%rsp), %rdi
xorps %xmm0, %xmm0
movss %xmm0, 0x6c(%rsp)
addq $0x68, %rdi
callq 0xba90
movq %rax, 0x60(%rsp)
movq 0x30(%rsp), %rdi
addq $0x68, %rdi
callq 0xbae0
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xbac0
testb $0x1, %al
jne 0xb740
jmp 0xb76d
leaq 0x60(%rsp), %rdi
callq 0xbb10
movss (%rax), %xmm0
addss 0x6c(%rsp), %xmm0
movss %xmm0, 0x6c(%rsp)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0xbb30
movq %rax, 0x50(%rsp)
jmp 0xb718
movq 0x30(%rsp), %rax
movss 0x6c(%rsp), %xmm0
cvtsi2ssl 0x9c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0xb796
movq 0x30(%rsp), %rax
cvttss2si 0x6c(%rsp), %ecx
movl %ecx, 0x9c(%rax)
movq 0x30(%rsp), %rax
movss 0x6c(%rsp), %xmm0
movss 0x14(%rax), %xmm1
cvtsi2ssl 0x9c(%rax), %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xb7c1
movl $0x1, 0x4c(%rsp)
jmp 0xb7c9
movl $0x0, 0x4c(%rsp)
movq 0x30(%rsp), %rax
cmpl $-0x1, 0x98(%rax)
jne 0xb7e6
movq 0x30(%rsp), %rax
movl 0x4c(%rsp), %ecx
movl %ecx, 0x98(%rax)
movq 0x30(%rsp), %rcx
movl 0x4c(%rsp), %eax
cmpl 0x98(%rcx), %eax
je 0xb9c2
movl $0x0, 0x48(%rsp)
movq 0x30(%rsp), %rax
cvtsi2sdl 0x48(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
cvtsi2ssl 0xa0(%rax), %xmm0
cvtsi2ssl 0x1c(%rax), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3887(%rip), %xmm1     # 0xf0b8
addsd %xmm1, %xmm0
callq 0x3430
movsd 0x18(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xb869
movq 0x30(%rsp), %rdi
addq $0x80, %rdi
leaq 0x4c(%rsp), %rsi
callq 0xbb60
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0xb803
movq 0x30(%rsp), %rdi
addq $0x80, %rdi
callq 0xbbd0
cmpq $0x2, %rax
jb 0xb9a7
movq 0x30(%rsp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, 0x10(%rsp)
addq $0x80, %rdi
callq 0xbbd0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0xbbf0
cmpl $0x0, (%rax)
jne 0xb9a7
movq 0x30(%rsp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, 0x8(%rsp)
addq $0x80, %rdi
callq 0xbbd0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
subq $0x2, %rsi
callq 0xbbf0
cmpl $0x0, (%rax)
jne 0xb9a7
movq 0x30(%rsp), %rdi
movl $0x1, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
addq $0x80, %rdi
callq 0xbbd0
subq $0x3, %rax
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jl 0xb964
movq 0x30(%rsp), %rdi
addq $0x80, %rdi
movslq 0x3c(%rsp), %rsi
callq 0xbbf0
cmpl $0x1, (%rax)
jne 0xb94d
movl 0x44(%rsp), %eax
orl 0x40(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x44(%rsp), %eax
shll %eax
movl %eax, 0x44(%rsp)
movl 0x3c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0xb91f
movq 0x30(%rsp), %rdi
movb $0x1, 0x7e(%rsp)
movq %rdi, %rax
addq $0xa8, %rax
movq %rax, (%rsp)
movl 0x40(%rsp), %esi
callq 0x4e30
movq (%rsp), %rdi
movb %al, 0x3b(%rsp)
leaq 0x3b(%rsp), %rsi
callq 0xbc10
movq 0x30(%rsp), %rdi
addq $0x80, %rdi
callq 0xbc40
movq 0x30(%rsp), %rax
movl 0x4c(%rsp), %ecx
movl %ecx, 0x98(%rax)
movl $0x1, 0xa0(%rax)
jmp 0xb9d6
movq 0x30(%rsp), %rax
movl 0xa0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xa0(%rax)
movq 0x30(%rsp), %rdi
addq $0x68, %rdi
callq 0xbc60
movb 0x7e(%rsp), %al
andb $0x1, %al
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)