dfm: sample_count wrap-around

pull/3/head
Zilog80 2017-06-07 01:36:43 +02:00
rodzic 4502e9be9d
commit 5ac92703b9
1 zmienionych plików z 19 dodań i 18 usunięć

Wyświetl plik

@ -138,7 +138,6 @@ int read_wav_header(FILE *fp) {
#define LEN_movAvg 3 #define LEN_movAvg 3
int movAvg[LEN_movAvg]; int movAvg[LEN_movAvg];
unsigned long sample_count = 0; unsigned long sample_count = 0;
double bitgrenze = 0;
int read_signed_sample(FILE *fp) { // int = i32_t int read_signed_sample(FILE *fp) { // int = i32_t
int byte, i, sample, s=0; // EOF -> 0x1000000 int byte, i, sample, s=0; // EOF -> 0x1000000
@ -204,16 +203,17 @@ int read_bits_fsk(FILE *fp, int *bit, int *len) {
} }
int bitstart = 0; int bitstart = 0;
double bitgrenze = 0;
unsigned long scount = 0;
int read_rawbit(FILE *fp, int *bit) { int read_rawbit(FILE *fp, int *bit) {
int sample; int sample;
int n, sum; int sum;
sum = 0; sum = 0;
n = 0;
if (bitstart) { if (bitstart) {
n = 1; // d.h. bitgrenze = sample_count-1 (?) scount = 0; // eigentlich scount = 1
bitgrenze = sample_count; bitgrenze = 0; // oder bitgrenze = -1
bitstart = 0; bitstart = 0;
} }
bitgrenze += samples_per_bit; bitgrenze += samples_per_bit;
@ -224,8 +224,8 @@ int read_rawbit(FILE *fp, int *bit) {
//sample_count++; // in read_signed_sample() //sample_count++; // in read_signed_sample()
//par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127) //par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127)
sum += sample; sum += sample;
n++; scount++;
} while (sample_count < bitgrenze); // n < samples_per_bit } while (scount < bitgrenze); // n < samples_per_bit
if (sum >= 0) *bit = 1; if (sum >= 0) *bit = 1;
else *bit = 0; else *bit = 0;
@ -237,14 +237,13 @@ int read_rawbit(FILE *fp, int *bit) {
int read_rawbit2(FILE *fp, int *bit) { int read_rawbit2(FILE *fp, int *bit) {
int sample; int sample;
int n, sum; int sum;
sum = 0; sum = 0;
n = 0;
if (bitstart) { if (bitstart) {
n = 1; // d.h. bitgrenze = sample_count-1 (?) scount = 0; // eigentlich scount = 1
bitgrenze = sample_count-1; bitgrenze = 0; // oder bitgrenze = -1
bitstart = 0; bitstart = 0;
} }
@ -255,8 +254,8 @@ int read_rawbit2(FILE *fp, int *bit) {
//sample_count++; // in read_signed_sample() //sample_count++; // in read_signed_sample()
//par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127) //par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127)
sum += sample; sum += sample;
n++; scount++;
} while (sample_count < bitgrenze); // n < samples_per_bit } while (scount < bitgrenze); // n < samples_per_bit
bitgrenze += samples_per_bit; bitgrenze += samples_per_bit;
do { do {
@ -265,8 +264,8 @@ int read_rawbit2(FILE *fp, int *bit) {
//sample_count++; // in read_signed_sample() //sample_count++; // in read_signed_sample()
//par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127) //par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127)
sum -= sample; sum -= sample;
n++; scount++;
} while (sample_count < bitgrenze); // n < samples_per_bit } while (scount < bitgrenze); // n < samples_per_bit
if (sum >= 0) *bit = 1; if (sum >= 0) *bit = 1;
else *bit = 0; else *bit = 0;
@ -287,8 +286,9 @@ int read_rawbit3(FILE *fp, int *bit) {
n = 0; n = 0;
if (bitstart) { if (bitstart) {
n = 1; // d.h. bitgrenze = sample_count-1 (?) n = 1; // sample*wc[0] ?
bitgrenze = sample_count-1; scount = 1; // (sample_count overflow/wrap-around)
bitgrenze = 0; // d.h. bitgrenze = sample_count-1 (?)
bitstart = 0; bitstart = 0;
} }
@ -300,7 +300,8 @@ int read_rawbit3(FILE *fp, int *bit) {
//par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127) //par = (sample >= 0) ? 1 : -1; // 8bit: 0..127,128..255 (-128..-1,0..127)
sum += sample*wc[n]; sum += sample*wc[n];
n++; n++;
} while (sample_count < bitgrenze); // n < samples_per_bit scount++;
} while (scount < bitgrenze); // n < samples_per_bit
if (sum >= 0) *bit = 1; if (sum >= 0) *bit = 1;
else *bit = 0; else *bit = 0;