kopia lustrzana https://github.com/rs1729/RS
clean-up
rodzic
a4ba753a67
commit
f6bb7bf35f
|
@ -1006,6 +1006,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
|
||||
// init gpx
|
||||
|
||||
pcm.sel_ch = sel_wavch;
|
||||
k = read_wav_header(&pcm, fp);
|
||||
if ( k < 0 ) {
|
||||
|
@ -1050,63 +1051,63 @@ int main(int argc, char **argv) {
|
|||
|
||||
bitofs += shift;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
while ( 1 )
|
||||
{
|
||||
|
||||
header_found = find_header(&dsp, thres, 2, bitofs, option_dc);
|
||||
_mv = dsp.mv;
|
||||
header_found = find_header(&dsp, thres, 2, bitofs, option_dc);
|
||||
_mv = dsp.mv;
|
||||
|
||||
if (header_found == EOF) break;
|
||||
if (header_found == EOF) break;
|
||||
|
||||
// mv == correlation score
|
||||
if (_mv*(0.5-gpx.option.inv) < 0) {
|
||||
gpx.option.inv ^= 0x1; // M10: irrelevant
|
||||
// mv == correlation score
|
||||
if (_mv*(0.5-gpx.option.inv) < 0) {
|
||||
gpx.option.inv ^= 0x1; // M10: irrelevant
|
||||
}
|
||||
|
||||
|
||||
if (header_found) {
|
||||
|
||||
bitpos = 0;
|
||||
pos = 0;
|
||||
pos /= 2;
|
||||
bit0 = '0'; // oder: _mv[j] > 0
|
||||
|
||||
while ( pos < BITFRAME_LEN+BITAUX_LEN ) {
|
||||
|
||||
if (option_iq >= 2) {
|
||||
float bl = -1;
|
||||
if (option_iq > 2) bl = 4.0;
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, bl, 0);
|
||||
}
|
||||
else {
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, -1, spike); // symlen=2
|
||||
}
|
||||
|
||||
if ( bitQ == EOF ) { break; }
|
||||
|
||||
gpx.frame_bits[pos] = 0x31 ^ (bit0 ^ bit);
|
||||
pos++;
|
||||
bit0 = bit;
|
||||
bitpos += 1;
|
||||
}
|
||||
gpx.frame_bits[pos] = '\0';
|
||||
print_frame(&gpx, pos);
|
||||
if (pos < BITFRAME_LEN) break;
|
||||
|
||||
header_found = 0;
|
||||
|
||||
// bis Ende der Sekunde vorspulen; allerdings Doppel-Frame alle 10 sek
|
||||
if (gpx.option.vbs < 3) { // && (regulare frame) // print_frame-return?
|
||||
while ( bitpos < 5*BITFRAME_LEN ) {
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, -1, spike); // symlen=2
|
||||
if ( bitQ == EOF) break;
|
||||
bitpos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (header_found) {
|
||||
|
||||
bitpos = 0;
|
||||
pos = 0;
|
||||
pos /= 2;
|
||||
bit0 = '0'; // oder: _mv[j] > 0
|
||||
|
||||
while ( pos < BITFRAME_LEN+BITAUX_LEN ) {
|
||||
|
||||
if (option_iq >= 2) {
|
||||
float bl = -1;
|
||||
if (option_iq > 2) bl = 4.0;
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, bl, 0);
|
||||
}
|
||||
else {
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, -1, spike); // symlen=2
|
||||
}
|
||||
|
||||
if ( bitQ == EOF ) { break; }
|
||||
|
||||
gpx.frame_bits[pos] = 0x31 ^ (bit0 ^ bit);
|
||||
pos++;
|
||||
bit0 = bit;
|
||||
bitpos += 1;
|
||||
}
|
||||
gpx.frame_bits[pos] = '\0';
|
||||
print_frame(&gpx, pos);
|
||||
if (pos < BITFRAME_LEN) break;
|
||||
|
||||
header_found = 0;
|
||||
|
||||
// bis Ende der Sekunde vorspulen; allerdings Doppel-Frame alle 10 sek
|
||||
if (gpx.option.vbs < 3) { // && (regulare frame) // print_frame-return?
|
||||
while ( bitpos < 5*BITFRAME_LEN ) {
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, -1, spike); // symlen=2
|
||||
if ( bitQ == EOF) break;
|
||||
bitpos++;
|
||||
}
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
}
|
||||
pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
free_buffers(&dsp);
|
||||
|
|
|
@ -779,80 +779,16 @@ static int print_frame(gpx_t *gpx, dsp_t *dsp) {
|
|||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// header bit buffer
|
||||
typedef struct {
|
||||
char *hdr;
|
||||
char *buf;
|
||||
char len;
|
||||
int bufpos;
|
||||
float ths;
|
||||
} hdb_t;
|
||||
|
||||
static float cmp_hdb(hdb_t *hdb) { // bit-errors?
|
||||
int i, j;
|
||||
int headlen = hdb->len;
|
||||
int berrs1 = 0, berrs2 = 0;
|
||||
|
||||
i = 0;
|
||||
j = hdb->bufpos;
|
||||
while (i < headlen) {
|
||||
if (j < 0) j = headlen-1;
|
||||
if (hdb->buf[j] != hdb->hdr[headlen-1-i]) berrs1 += 1;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
j = hdb->bufpos;
|
||||
while (i < headlen) {
|
||||
if (j < 0) j = headlen-1;
|
||||
if ((hdb->buf[j]^0x01) != hdb->hdr[headlen-1-i]) berrs2 += 1;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
if (berrs2 < berrs1) return (-headlen+berrs2)/(float)headlen;
|
||||
else return ( headlen-berrs1)/(float)headlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int find_binhead(FILE *fp, hdb_t *hdb, float *score) {
|
||||
int bit;
|
||||
int headlen = hdb->len;
|
||||
float mv;
|
||||
|
||||
//*score = 0.0;
|
||||
|
||||
while ( (bit = fgetc(fp)) != EOF )
|
||||
{
|
||||
bit &= 1;
|
||||
|
||||
hdb->bufpos = (hdb->bufpos+1) % headlen;
|
||||
hdb->buf[hdb->bufpos] = 0x30 | bit; // Ascii
|
||||
|
||||
mv = cmp_hdb(hdb);
|
||||
if ( fabs(mv) > hdb->ths ) {
|
||||
*score = mv;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
void *thd_dfm09(void *targs) {
|
||||
|
||||
|
||||
thargs_t *tharg = targs;
|
||||
pcm_t *pcm = &(tharg->pcm);
|
||||
|
||||
|
||||
int option_iq = 5;
|
||||
int option_bin = 0;
|
||||
int spike = 0;
|
||||
|
||||
FILE *fp = NULL;
|
||||
char *fpname = NULL;
|
||||
|
||||
int ret = 0;
|
||||
int k;
|
||||
|
@ -878,9 +814,6 @@ void *thd_dfm09(void *targs) {
|
|||
|
||||
gpx_t gpx = {0};
|
||||
|
||||
hdb_t hdb = {0};
|
||||
ui32_t hdrcnt = 0;
|
||||
|
||||
/*
|
||||
#ifdef CYGWIN
|
||||
_setmode(fileno(stdin), _O_BINARY); // _setmode(_fileno(stdin), _O_BINARY);
|
||||
|
@ -947,16 +880,12 @@ void *thd_dfm09(void *targs) {
|
|||
bitofs += shift;
|
||||
|
||||
|
||||
bitQ = 0;
|
||||
while ( 1 && bitQ != EOF )
|
||||
{
|
||||
if (option_bin) { // aka find_binrawhead()
|
||||
header_found = find_binhead(fp, &hdb, &_mv); // symbols or bits?
|
||||
hdrcnt += nfrms;
|
||||
}
|
||||
else {
|
||||
header_found = find_header(&dsp, thres, 2, bitofs, 0);
|
||||
_mv = dsp.mv;
|
||||
}
|
||||
header_found = find_header(&dsp, thres, 2, bitofs, 0);
|
||||
_mv = dsp.mv;
|
||||
|
||||
if (header_found == EOF) break;
|
||||
|
||||
// mv == correlation score
|
||||
|
@ -975,34 +904,18 @@ void *thd_dfm09(void *targs) {
|
|||
|
||||
frm = 0;
|
||||
while ( frm < nfrms ) { // nfrms=1,2,4,8
|
||||
if (option_bin) {
|
||||
gpx._frmcnt = hdrcnt + frm;
|
||||
}
|
||||
else {
|
||||
gpx._frmcnt = dsp.mv_pos/(2.0*dsp.sps*BITFRAME_LEN) + frm;
|
||||
}
|
||||
|
||||
gpx._frmcnt = dsp.mv_pos/(2.0*dsp.sps*BITFRAME_LEN) + frm;
|
||||
|
||||
while ( pos < BITFRAME_LEN )
|
||||
{
|
||||
if (option_bin) {
|
||||
// symbols or bits?
|
||||
// manchester1 1->10,0->01: 1.bit (DFM-06)
|
||||
// manchester2 0->10,1->01: 2.bit (DFM-09)
|
||||
bitQ = fgetc(fp);
|
||||
if (bitQ != EOF) {
|
||||
bit = bitQ & 0x1;
|
||||
bitQ = fgetc(fp); // check: rbit0^rbit1=1 (Manchester)
|
||||
if (bitQ != EOF) bit = bitQ & 0x1; // 2.bit (DFM-09)
|
||||
}
|
||||
if (option_iq >= 2) {
|
||||
float bl = -1;
|
||||
if (option_iq > 2) bl = 4.0;
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, bl, 0);
|
||||
}
|
||||
else {
|
||||
if (option_iq >= 2) {
|
||||
float bl = -1;
|
||||
if (option_iq > 2) bl = 4.0;
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, bl, 0);
|
||||
}
|
||||
else {
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, -1, spike);
|
||||
}
|
||||
bitQ = read_slbit(&dsp, &bit, 0/*gpx.option.inv*/, bitofs, bitpos, -1, spike);
|
||||
}
|
||||
if ( bitQ == EOF ) { frm = nfrms; break; } // liest 2x EOF
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* (a)
|
||||
* gcc -DINCLUDESTATIC -c rs41base.c
|
||||
* (b)
|
||||
* gcc -c demod_mod.c
|
||||
* gcc -c bch_ecc_mod.c
|
||||
* gcc -c rs41base.c
|
||||
*
|
||||
* author: zilog80
|
||||
|
@ -1468,69 +1468,6 @@ static void print_frame(gpx_t *gpx, int len, dsp_t *dsp) {
|
|||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
// header bit buffer
|
||||
typedef struct {
|
||||
char *hdr;
|
||||
char *buf;
|
||||
char len;
|
||||
int bufpos;
|
||||
float ths;
|
||||
} hdb_t;
|
||||
|
||||
static float cmp_hdb(hdb_t *hdb) { // bit-errors?
|
||||
int i, j;
|
||||
int headlen = hdb->len;
|
||||
int berrs1 = 0, berrs2 = 0;
|
||||
|
||||
i = 0;
|
||||
j = hdb->bufpos;
|
||||
while (i < headlen) {
|
||||
if (j < 0) j = headlen-1;
|
||||
if (hdb->buf[j] != hdb->hdr[headlen-1-i]) berrs1 += 1;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
j = hdb->bufpos;
|
||||
while (i < headlen) {
|
||||
if (j < 0) j = headlen-1;
|
||||
if ((hdb->buf[j]^0x01) != hdb->hdr[headlen-1-i]) berrs2 += 1;
|
||||
j--;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (berrs2 < berrs1) return (-headlen+berrs2)/(float)headlen;
|
||||
else return ( headlen-berrs1)/(float)headlen;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int find_binhead(FILE *fp, hdb_t *hdb, float *score) {
|
||||
int bit;
|
||||
int headlen = hdb->len;
|
||||
float mv;
|
||||
|
||||
//*score = 0.0;
|
||||
|
||||
while ( (bit = fgetc(fp)) != EOF )
|
||||
{
|
||||
bit &= 1;
|
||||
|
||||
hdb->bufpos = (hdb->bufpos+1) % headlen;
|
||||
hdb->buf[hdb->bufpos] = 0x30 | bit; // Ascii
|
||||
|
||||
mv = cmp_hdb(hdb);
|
||||
if ( fabs(mv) > hdb->ths ) {
|
||||
*score = mv;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return EOF;
|
||||
}
|
||||
|
||||
|
||||
void *thd_rs41(void *targs) { // pcm_t *pcm, double xlt_fq
|
||||
|
||||
thargs_t *tharg = targs;
|
||||
|
@ -1540,12 +1477,7 @@ void *thd_rs41(void *targs) { // pcm_t *pcm, double xlt_fq
|
|||
//int option_inv = 0; // invertiert Signal
|
||||
int option_iq = 5; // baseband, decimate
|
||||
int option_ofs = 0;
|
||||
int option_bin = 0;
|
||||
//int sel_wavch = 0; // audio channel: left
|
||||
int rawhex = 0, xorhex = 0;
|
||||
|
||||
//FILE *fp;
|
||||
//char *fpname = NULL;
|
||||
|
||||
int k;
|
||||
|
||||
|
@ -1569,8 +1501,6 @@ void *thd_rs41(void *targs) { // pcm_t *pcm, double xlt_fq
|
|||
|
||||
gpx_t gpx = {0};
|
||||
|
||||
hdb_t hdb = {0};
|
||||
|
||||
/*
|
||||
#ifdef CYGWIN
|
||||
_setmode(fileno(stdin), _O_BINARY); // _fileno(stdin)
|
||||
|
@ -1593,9 +1523,7 @@ void *thd_rs41(void *targs) { // pcm_t *pcm, double xlt_fq
|
|||
memcpy(gpx.frame, rs41_header_bytes, sizeof(rs41_header_bytes)); // 8 header bytes
|
||||
|
||||
|
||||
//if (option_iq) sel_wavch = 0;
|
||||
|
||||
pcm->sel_ch = 0; //sel_wavch;
|
||||
pcm->sel_ch = 0;
|
||||
|
||||
// rs41: BT=0.5, h=0.8,1.0 ?
|
||||
symlen = 1;
|
||||
|
@ -1609,14 +1537,7 @@ void *thd_rs41(void *targs) { // pcm_t *pcm, double xlt_fq
|
|||
dsp.decM = pcm->decM;
|
||||
|
||||
dsp.thd = tharg->thd;
|
||||
/*
|
||||
thread_struct->tn;
|
||||
dsp.mutex = thread_struct->mutex;
|
||||
dsp.cond = thread_struct->cond;
|
||||
dsp.xlt_fq = thread_struct->xlt_fq;
|
||||
dsp.max_fq = thread_struct->max_fq;
|
||||
dsp.blk = thread_struct->blk;
|
||||
*/
|
||||
|
||||
dsp.bps = pcm->bps;
|
||||
dsp.nch = pcm->nch;
|
||||
dsp.ch = pcm->sel_ch;
|
||||
|
@ -1642,11 +1563,11 @@ void *thd_rs41(void *targs) { // pcm_t *pcm, double xlt_fq
|
|||
return NULL;
|
||||
};
|
||||
|
||||
//if (option_iq >= 2) bitofs += 1; // FM: +1 , IQ: +2
|
||||
//if (option_iq: 2,3) bitofs += 1; // FM: +1 , IQ: +2, IQ5: +1
|
||||
bitofs += shift;
|
||||
|
||||
//fprintf(stderr, "%d\n", dsp.tn);
|
||||
|
||||
bitQ = 0;
|
||||
while ( 1 && bitQ != EOF )
|
||||
{
|
||||
header_found = find_header(&dsp, thres, 3, bitofs, 0);
|
||||
|
|
Ładowanie…
Reference in New Issue