// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x60(%rdi), %rax
movl 0x50(%rdi), %ecx
movb %sil, (%rax,%rcx)
movl 0x54(%rdi), %eax
movl 0x58(%rdi), %ebp
cmpl %ebp, %eax
jbe 0x5124
movl 0x50(%rbx), %r14d
leal 0x1(%r14), %eax
xorl %r13d, %r13d
cmpl %ebp, %eax
movl %ebp, %ecx
cmovbl %r13d, %ecx
cvtsi2ss %rax, %xmm0
subl %ecx, %eax
movq 0x60(%rbx), %r15
cltq
movsbl (%r15,%rax), %r12d
movss 0x18(%rbx), %xmm1
movss %xmm1, 0x10(%rsp)
addss %xmm1, %xmm0
callq 0x2120
cvttss2si %xmm0, %eax
cmpl %eax, %ebp
cmovbel %ebp, %r13d
subl %r13d, %eax
cltq
movsbl (%r15,%rax), %r13d
xorps %xmm0, %xmm0
cvtsi2ss %r14, %xmm0
subss 0x10(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x2073(%rip), %xmm0     # 0x70d8
callq 0x2320
cvttsd2si %xmm0, %eax
movl %eax, %ecx
sarl $0x1f, %ecx
andl %ebp, %ecx
addl %eax, %ecx
movslq %ecx, %rax
movsbl (%r15,%rax), %ebp
movsbl (%r15,%r14), %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
callq 0x2080
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
callq 0x2080
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm2
movaps 0x1ff8(%rip), %xmm0     # 0x70c0
andps %xmm0, %xmm2
xorps %xmm1, %xmm1
cvtss2sd %xmm2, %xmm1
ucomisd 0x2006(%rip), %xmm1     # 0x70e0
ja 0x50e3
movaps %xmm2, 0x10(%rsp)
jmp 0x50f7
addsd 0x1ffd(%rip), %xmm1     # 0x70e8
cvtsd2ss %xmm1, %xmm1
andps %xmm0, %xmm1
movaps %xmm1, 0x10(%rsp)
leaq 0x68(%rbx), %r14
movl $0x18, %edi
callq 0x21e0
movaps 0x10(%rsp), %xmm0
movss %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r14, %rsi
callq 0x2070
incq 0x78(%rbx)
movl 0x54(%rbx), %eax
movl 0x58(%rbx), %ebp
movl 0x50(%rbx), %ecx
incl %ecx
movl %ecx, 0x50(%rbx)
incl %eax
movl %eax, 0x54(%rbx)
cmpl %ebp, %ecx
jbe 0x513c
movl $0x0, 0x50(%rbx)
movl 0x1c(%rbx), %ecx
leal 0x3(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
movq 0x78(%rbx), %rax
sarl $0x2, %edx
movslq %edx, %rdx
cmpq %rdx, %rax
jae 0x515d
xorl %ebp, %ebp
jmp 0x52e2
leaq 0x68(%rbx), %rdx
movq (%rdx), %r14
xorps %xmm0, %xmm0
cmpq %rdx, %r14
je 0x517c
movq %r14, %rsi
addss 0x10(%rsi), %xmm0
movq (%rsi), %rsi
cmpq %rdx, %rsi
jne 0x516f
xorps %xmm1, %xmm1
cvtsi2ssl 0x9c(%rbx), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x519d
cvttss2si %xmm0, %edx
movl %edx, 0x9c(%rbx)
cvttps2dq %xmm0, %xmm1
cvtdq2ps %xmm1, %xmm1
mulss 0x14(%rbx), %xmm1
xorl %edx, %edx
ucomiss %xmm1, %xmm0
seta %dl
movl %edx, 0x8(%rsp)
movl 0x98(%rbx), %esi
cmpl $-0x1, %esi
je 0x52b8
cmpl %edx, %esi
je 0x52be
xorps %xmm0, %xmm0
cvtsi2ssl 0xa0(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x1ee9(%rip), %xmm0     # 0x70d0
callq 0x2320
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5273
leaq 0x80(%rbx), %r14
movl $0x1, %ebp
leaq 0x8(%rsp), %r15
movq 0x88(%rbx), %rsi
cmpq 0x90(%rbx), %rsi
je 0x5229
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x88(%rbx)
jmp 0x5234
movq %r14, %rdi
movq %r15, %rdx
callq 0x5364
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2ssl 0xa0(%rbx), %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x1c(%rbx), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x1e6c(%rip), %xmm0     # 0x70d0
callq 0x2320
incl %ebp
ucomisd 0x10(%rsp), %xmm0
ja 0x5206
movq 0x80(%rbx), %rax
movq 0x88(%rbx), %rdx
subq %rax, %rdx
movq %rdx, %rcx
sarq $0x2, %rcx
cmpq $0x1, %rcx
jbe 0x5298
cmpl $0x0, -0x4(%rax,%rdx)
je 0x52f3
xorl %ebp, %ebp
movl 0x8(%rsp), %eax
movl %eax, 0x98(%rbx)
movl $0x1, 0xa0(%rbx)
movq 0x68(%rbx), %r14
movq 0x78(%rbx), %rax
jmp 0x52c6
movl %edx, 0x98(%rbx)
incl 0xa0(%rbx)
xorl %ebp, %ebp
decq %rax
movq %rax, 0x78(%rbx)
movq %r14, %rdi
callq 0x2300
movl $0x18, %esi
movq %r14, %rdi
callq 0x21f0
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
cmpl $0x0, -0x8(%rax,%rdx)
jne 0x529a
addl $-0x3, %ecx
js 0x5320
movl %ecx, %ecx
movl $0x1, %edx
xorl %ebp, %ebp
cmpl $0x1, (%rax,%rcx,4)
movl $0x0, %esi
cmovel %edx, %esi
orl %esi, %ebp
addl %edx, %edx
addq $-0x1, %rcx
jb 0x530a
leaq 0xa8(%rbx), %r14
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3398
leaq 0xf(%rsp), %rsi
movb %al, (%rsi)
movq %r14, %rdi
callq 0x54a0
movq 0x80(%rbx), %rax
movb $0x1, %bpl
cmpq %rax, 0x88(%rbx)
je 0x529a
movq %rax, 0x88(%rbx)
jmp 0x529a
nop