diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-04-22 22:20:13 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-04-22 22:20:13 +0000 |
commit | 89fa345e9ee4778b5f0391b5ab1cfc043aadc1d9 (patch) | |
tree | f92b98e1686a7424a476bc20e6ee37ab3aa971dc /v17dem.c | |
parent | 783b56d54788f177881d68ae2ec7a7cb4bb38ac4 (diff) |
git-svn-id: file:///home/lennart/svn/public/vfax/trunk@4 541b366f-4dd8-0310-ae39-b2612fd50714
Diffstat (limited to 'v17dem.c')
-rw-r--r-- | v17dem.c | 121 |
1 files changed, 53 insertions, 68 deletions
@@ -5,98 +5,83 @@ #define SAMPLE_RATE 8000 #define SAMPLES_MAX (SAMPLES_RATE*5) /* -> 5s buffer */ -#define SINC_RADIUS 10 - struct v17dem_state { - float *samples; - int i_samples, n_samples; - - int sample_index; - int baud_rate; int carrier_freq; - - struct interpol_state qam_interpol; - struct interpol_state am_interpol; - - enum { COSINUS, SINUS } current; - float *xam, *yam; - int am_index; + + struct resample_state qam_resample, xam_resample, yam_resample; + struct qbuf am_qbuf, xam_qbuf, yam_qbuf, xsymbols_qbuf, ysymbols_qbuf; }; -void v17dem_init(struct v17dem_state *s) { - assert(s); +static int v17_7k2_symbol_decode(float x, float y) { + int row, col, i; - memset(s, 0, sizeof(struct v17dem_state)); - s->baud_rate = INITIAL_BAUD_RATE; - s->carrier_freq = INITIAL_CARRIER_FREQ; - s->samples = malloc(sizeof(float) * SAMPLES_MAX * 2); + static const int v17_7k2_table[] = { + 3, 10, 5, 0, + 6, 15, 12, 9, + 13, 8, 11, 2, + 4, 1, 14, 7 + }; - interpol_init(&s->qam_interpol, 9, SINC_RADIUS); -} + col = (int) ((x+.6)/.4 +.5); + if (col < 0) col = 0; + if (col > 3) col = 3; -void v17dem_done(struct v17dem_state *s) { - assert(s); + row = (int) ((y+.6)/.4 +.5); + if (row < 0) row = 0; + if (row > 3) row = 3; - free(s->samples); - inertpol_done(&s->qam_interpol); -} - -static void move_to_front(struct v17dem_state *s) { - assert(s); + i = col*4+row; - if (s->i_samples < SAMPLES_MAX) - return; + assert(i >= 0 && i <= 15); - memmove(s->samples, s->samples + s->i_samples, s->n_samples*sizeof(float)); - s->i_samples = 0; + return v17_7k2_table[i]; } -void v17dem_push(struct v17dem_state *s, const float *p, int l){ - assert(s && p && l); +void v17dem_init(struct v17dem_state *s) { + assert(s); - assert(l <= SAMPLES_MAX-s->n_samples); + memset(s, 0, sizeof(struct v17dem_state)); + s->baud_rate = INITIAL_BAUD_RATE; + s->carrier_freq = INITIAL_CARRIER_FREQ; - move_to_front(s); + resample_init(&s->qam_resample); + resample_init(&s->xam_resample); + resample_init(&s->yam_resample); - memcpy(s->samples + s->i_samples + s->n_samples, p, l*sizeof(float)); - s->n_samples += l; + qbuf_init(&s->am_qbuf, sizeof(float) * SAMPLES_MAX); + qbuf_init(&s->xam_qbuf, sizeof(float) * SAMPLES_MAX/2); + qbuf_init(&s->yam_qbuf, sizeof(float) * SAMPLES_MAX/2); + qbuf_init(&s->xsymbols_qbuf, sizeof(float) * SAMPLES_MAX/2); + qbuf_init(&s->ysymbols_qbuf, sizeof(float) * SAMPLES_MAX/2); } -int v17dem_pull(struct v17dem_state *s, uint8_t *p, int l){ - int alt = 0; - - assert(s && p && l); +void v17dem_done(struct v17dem_state *s) { + assert(s); - for (;;) { - int n; - - /* Position für AM-Abtastung im Sample-Puffer berechnen -- alle 90° */ - float x = (SAMPLE_RATE/(4.0*s->carrier_freq) * s->am_index) - s->sample_index; - assert(x >= 0); + resample_done(&s->qam_resample); + resample_done(&s->xam_resample); + resample_done(&s->yam_resample); - /* AM-Abtatsung druchführen */ - if (s->current = COSINUS) - am = s->xam; - else - am = s->yam; + qbuf_done(&s->am_qbuf); + qbuf_done(&s->xam_qbuf); + qbuf_done(&s->yam_qbuf); + qbuf_done(&s->xsymbols_qbuf); + qbuf_done(&s->ysymbols_qbuf); +} - am[s->am_index] = interpol_get(s->qam_interpol, s->samples + s->i_samples, s->n_samples, x); +static int v17_decode(struct qbuf - if (s->current == SINUS) - s->am_index++; - - s->current = !s->current; - /* Überflüssige Sampledaten killen */ +int v17dem_run(struct v17dem_state *s, struct qbuf *sample_qbuf, struct qbuf *byte_qbuf){ + assert(s && sample_qbuf && byte_qbuf); - n = (int) (x - (float) SINC_RADIUS*SAMPLE_RATE/s->carrier_freq/4); + resample_get(s->qam_resample, sample_qbuf, s->am_qbuf, SAMPLE_RATE, s->carrier_freq*4); + qbuf_float_split(s->am_qbuf, s->xam_qbuf, s->yam_qbuf); + resample_get(s->xam_resample, s->xam_qbuf, s->xsymbols_qbuf); + resample_get(s->yam_resample, s->yam_qbuf, s->ysymbols_qbuf); - if (n > 0) { - s->n_samples -= n; - s->i_samples += n; - s->sample_index += n; - } - } + v17_decode(s->xsymbols_qbuf, s->ysymbols_qbuf, byte_qbuf), + } |