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

	bool newByte = false;

	input_data[input_position] = next_data_point;

	if(input_count > input_data_width){


		int pos;

		int max_1 = -127;
		int max_idx_1 = 0;
		pos = input_position+1;
		for(int i = 0; i < ninty_deg_phase_width; i++){
			int pos2 = pos+i;
			if(pos2 >= input_data_width) pos2 = pos2 - input_data_width;
			int y1 = input_data[pos2];
			if(y1 > max_1){
				max_1 = y1;
				max_idx_1 = i;
			}
		}

		int max_2 = -127;
		int max_idx_2 = 0;
		pos = (int)floor(input_position-ninty_deg_phase_width+1.5);
		for(int i = 0; i < ninty_deg_phase_width; i++){
			int pos2 = pos+i;
			if(pos2 < 0) pos2 = input_data_width + pos2;
			int y2 = input_data[pos2];
			if(y2 > max_2){
				max_2 = y2;
				max_idx_2 = i;
			}
		}

		float pd = std::abs(max_idx_1-max_idx_2);

		if(pd > ninty_deg_phase_width/2) pd = std::abs(pd-ninty_deg_phase_width);
 		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 0x592a
movl 0x50(%rbx), %eax
movss 0x18(%rbx), %xmm1
movq 0x60(%rbx), %r15
pushq $-0x7f
popq %rcx
xorl %edx, %edx
pushq $0x1
popq %rsi
xorl %r14d, %r14d
leal -0x1(%rsi), %edi
cvtsi2ss %edi, %xmm0
ucomiss %xmm0, %xmm1
jbe 0x587d
leal (%rax,%rsi), %r8d
cmpl %ebp, %r8d
movl %ebp, %r9d
cmovbl %edx, %r9d
subl %r9d, %r8d
movslq %r8d, %r8
movsbl (%r15,%r8), %r8d
cmpl %r8d, %ecx
cmovll %edi, %r14d
cmovlel %r8d, %ecx
incl %esi
jmp 0x5849
movl %eax, %eax
cvtsi2ss %rax, %xmm0
subss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x844(%rip), %xmm0      # 0x60d8
movaps %xmm1, 0x10(%rsp)
callq 0x2340
movaps 0x10(%rsp), %xmm3
cvttsd2si %xmm0, %ecx
xorl %eax, %eax
pushq $-0x7f
popq %rdx
xorl %esi, %esi
cvtsi2ss %esi, %xmm0
ucomiss %xmm0, %xmm3
jbe 0x58db
leal (%rcx,%rsi), %edi
movl %edi, %r8d
sarl $0x1f, %r8d
andl %ebp, %r8d
addl %edi, %r8d
movslq %r8d, %rdi
movsbl (%r15,%rdi), %edi
cmpl %edi, %edx
cmovlel %edi, %edx
cmovll %esi, %eax
incl %esi
jmp 0x58ae
subl %eax, %r14d
movl %r14d, %eax
negl %eax
cmovsl %r14d, %eax
cvtsi2ss %eax, %xmm0
movaps %xmm0, %xmm1
subss %xmm3, %xmm1
mulss 0x822(%rip), %xmm3      # 0x611c
andps 0x7bf(%rip), %xmm1      # 0x60c0
cmpltss %xmm0, %xmm3
movaps %xmm3, %xmm2
andnps %xmm0, %xmm2
andps %xmm1, %xmm3
orps %xmm2, %xmm3
leaq 0x24(%rsp), %rsi
movss %xmm3, (%rsi)
leaq 0x68(%rbx), %rdi
callq 0x4cdc
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 0x593f
andl $0x0, 0x50(%rbx)
movq 0x78(%rbx), %rsi
movl 0x1c(%rbx), %ecx
pushq $0x4
popq %rdi
movl %ecx, %eax
cltd
idivl %edi
cltq
cmpq %rax, %rsi
jae 0x595c
xorl %ebp, %ebp
jmp 0x5a5d
pushq $0x1
popq %r13
leaq 0x68(%rbx), %r14
xorps %xmm0, %xmm0
movq %r14, %rax
movq (%rax), %rax
cmpq %r14, %rax
je 0x5979
addss 0x10(%rax), %xmm0
jmp 0x596a
cvtsi2ssl 0x9c(%rbx), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x5997
cvttss2si %xmm0, %eax
movl %eax, 0x9c(%rbx)
cvttps2dq %xmm0, %xmm1
cvtdq2ps %xmm1, %xmm1
mulss 0x14(%rbx), %xmm1
xorl %eax, %eax
ucomiss %xmm1, %xmm0
seta %al
movl %eax, 0xc(%rsp)
movl 0x98(%rbx), %edx
cmpl $-0x1, %edx
je 0x5a0a
cmpl %eax, %edx
je 0x5a10
leaq 0x80(%rbx), %r15
xorl %ebp, %ebp
leaq 0xc(%rsp), %r12
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
cvtsi2ssl 0xa0(%rbx), %xmm0
cvtsi2ss %ecx, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x6e5(%rip), %xmm0      # 0x60d0
callq 0x2340
ucomisd 0x10(%rsp), %xmm0
jbe 0x5a1a
movq %r15, %rdi
movq %r12, %rsi
callq 0x4ce8
incl %ebp
movl 0x1c(%rbx), %ecx
jmp 0x59c5
movl %eax, 0x98(%rbx)
incl 0xa0(%rbx)
xorl %ebp, %ebp
jmp 0x5a55
movq 0x80(%rbx), %rax
movq 0x88(%rbx), %rdx
subq %rax, %rdx
movq %rdx, %rcx
sarq $0x2, %rcx
cmpq $0x1, %rcx
jbe 0x5a3f
cmpl $0x0, -0x4(%rax,%rdx)
je 0x5a6e
xorl %ebp, %ebp
movl 0xc(%rsp), %eax
movl %eax, 0x98(%rbx)
movl $0x1, 0xa0(%rbx)
movq %r14, %rdi
callq 0x4d06
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 0x5a41
addl $-0x3, %ecx
testl %ecx, %ecx
js 0x5a96
movl %ecx, %edx
cmpl $0x1, (%rax,%rdx,4)
movl $0x0, %edx
cmovel %r13d, %edx
orl %edx, %ebp
addl %r13d, %r13d
decl %ecx
jmp 0x5a7a
leaq 0xa8(%rbx), %r15
movq %rbx, %rdi
movl %ebp, %esi
callq 0x2fa8
leaq 0xb(%rsp), %rsi
movb %al, (%rsi)
movq %r15, %rdi
callq 0x4f0e
movq 0x80(%rbx), %rax
movb $0x1, %bpl
cmpq %rax, 0x88(%rbx)
je 0x5a41
movq %rax, 0x88(%rbx)
jmp 0x5a41