// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
movb %sil, %al
movq %rdi, 0xa0(%rsp)
movb %al, 0x9f(%rsp)
movq 0xa0(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movb $0x0, 0x9e(%rsp)
movb 0x9f(%rsp), %sil
movq 0x60(%rcx), %rax
movl 0x50(%rcx), %edx
movb %sil, (%rax,%rdx)
movl 0x54(%rcx), %eax
cmpl 0x58(%rcx), %eax
jbe 0xde50
movq 0x30(%rsp), %rax
movl $0xffffff81, 0x94(%rsp) # imm = 0xFFFFFF81
movl $0x0, 0x90(%rsp)
movl 0x50(%rax), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
movl $0x0, 0x8c(%rsp)
movq 0x30(%rsp), %rax
cvtsi2ssl 0x8c(%rsp), %xmm1
movss 0x18(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xdd18
movq 0x30(%rsp), %rcx
movl 0x98(%rsp), %eax
addl 0x8c(%rsp), %eax
movl %eax, 0x88(%rsp)
movl 0x88(%rsp), %eax
cmpl 0x58(%rcx), %eax
jb 0xdcb8
movq 0x30(%rsp), %rcx
movl 0x88(%rsp), %eax
subl 0x58(%rcx), %eax
movl %eax, 0x88(%rsp)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rax
movslq 0x88(%rsp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0x94(%rsp), %eax
jle 0xdd00
movl 0x84(%rsp), %eax
movl %eax, 0x94(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x90(%rsp)
jmp 0xdd02
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0xdc60
movq 0x30(%rsp), %rax
movl $0xffffff81, 0x80(%rsp) # imm = 0xFFFFFF81
movl $0x0, 0x7c(%rsp)
movl 0x50(%rax), %ecx
cvtsi2ss %rcx, %xmm0
subss 0x18(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1377(%rip), %xmm1     # 0xf0c0
addsd %xmm1, %xmm0
callq 0x3430
cvttsd2si %xmm0, %eax
movl %eax, 0x98(%rsp)
movl $0x0, 0x78(%rsp)
movq 0x30(%rsp), %rax
cvtsi2ssl 0x78(%rsp), %xmm1
movss 0x18(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xdde5
movl 0x98(%rsp), %eax
addl 0x78(%rsp), %eax
movl %eax, 0x74(%rsp)
cmpl $0x0, 0x74(%rsp)
jge 0xdda0
movq 0x30(%rsp), %rax
movl 0x58(%rax), %eax
addl 0x74(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rax
movslq 0x74(%rsp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, 0x70(%rsp)
movl 0x70(%rsp), %eax
cmpl 0x80(%rsp), %eax
jle 0xddd6
movl 0x70(%rsp), %eax
movl %eax, 0x80(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x7c(%rsp)
jmp 0xddd8
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0xdd65
movq 0x30(%rsp), %rax
movl 0x90(%rsp), %ecx
subl 0x7c(%rsp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
cvtsi2ss %ecx, %xmm0
movss %xmm0, 0x6c(%rsp)
movss 0x6c(%rsp), %xmm0
movss 0x18(%rax), %xmm1
movss 0x1303(%rip), %xmm2     # 0xf11c
divss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xde3d
movq 0x30(%rsp), %rax
movss 0x6c(%rsp), %xmm0
subss 0x18(%rax), %xmm0
callq 0xd990
movss %xmm0, 0x6c(%rsp)
movq 0x30(%rsp), %rdi
addq $0x68, %rdi
leaq 0x6c(%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 0xde7b
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, 0x28(%rsp)
movl 0x1c(%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x28(%rsp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
jb 0xe1a1
movq 0x30(%rsp), %rdi
xorps %xmm0, %xmm0
movss %xmm0, 0x68(%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 0xdef8
jmp 0xdf25
leaq 0x60(%rsp), %rdi
callq 0xbb10
movss (%rax), %xmm0
addss 0x68(%rsp), %xmm0
movss %xmm0, 0x68(%rsp)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0xbb30
movq %rax, 0x50(%rsp)
jmp 0xded0
movq 0x30(%rsp), %rax
movss 0x68(%rsp), %xmm0
cvtsi2ssl 0x9c(%rax), %xmm1
ucomiss %xmm1, %xmm0
jbe 0xdf4e
movq 0x30(%rsp), %rax
cvttss2si 0x68(%rsp), %ecx
movl %ecx, 0x9c(%rax)
movq 0x30(%rsp), %rax
movss 0x68(%rsp), %xmm0
movss 0x14(%rax), %xmm1
cvtsi2ssl 0x9c(%rax), %xmm2
mulss %xmm2, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xdf79
movl $0x1, 0x4c(%rsp)
jmp 0xdf81
movl $0x0, 0x4c(%rsp)
movq 0x30(%rsp), %rax
cmpl $-0x1, 0x98(%rax)
jne 0xdf9e
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 0xe17f
movl $0x0, 0x48(%rsp)
movq 0x30(%rsp), %rax
cvtsi2sdl 0x48(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
cvtsi2ssl 0xa0(%rax), %xmm0
cvtsi2ssl 0x1c(%rax), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x10cf(%rip), %xmm1     # 0xf0b8
addsd %xmm1, %xmm0
callq 0x3430
movsd 0x20(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xe021
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 0xdfbb
movq 0x30(%rsp), %rdi
addq $0x80, %rdi
callq 0xbbd0
cmpq $0x2, %rax
jb 0xe164
movq 0x30(%rsp), %rdi
movq %rdi, %rax
addq $0x80, %rax
movq %rax, 0x18(%rsp)
addq $0x80, %rdi
callq 0xbbd0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0xbbf0
cmpl $0x0, (%rax)
jne 0xe164
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 $0x2, %rsi
callq 0xbbf0
cmpl $0x0, (%rax)
jne 0xe164
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 0xe11c
movq 0x30(%rsp), %rdi
addq $0x80, %rdi
movslq 0x3c(%rsp), %rsi
callq 0xbbf0
cmpl $0x1, (%rax)
jne 0xe105
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 0xe0d7
movq 0x30(%rsp), %rdi
movb $0x1, 0x9e(%rsp)
movq %rdi, %rax
addq $0xa8, %rax
movq %rax, 0x8(%rsp)
movl 0x40(%rsp), %esi
callq 0x4e30
movq 0x8(%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 0xe193
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 0x9e(%rsp), %al
andb $0x1, %al
addq $0xa8, %rsp
retq