aboutsummaryrefslogtreecommitdiffstats
path: root/v23.c
blob: a3efb30fc6c6b29d5bcc6c00cf5f660ec42ae8ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* 
 * generic V23 modulator & demodulator
 * 
 * Copyright (c) 1999 Fabrice Bellard.
 *
 * This code is released under the GNU General Public License version
 * 2. Please read the file COPYING to know the exact terms of the
 * license.
 */
#include <stdlib.h>
#include <stdio.h>

#include "lm.h"
#include "fsk.h"

#define SAMPLE_RATE 8000

void V23_mod_init(FSK_mod_state *s, int calling, get_bit_func get_bit, void *opaque)
{
    if (calling) {
        /* 75 bauds */
        s->f_lo = 390;
        s->f_hi = 450;
        s->baud_rate = 75;
    } else {
        /* 1200 bauds */
        s->f_lo = 1300;
        s->f_hi = 2100;
        s->baud_rate = 1200;
    }
    s->sample_rate = SAMPLE_RATE;
    s->get_bit = get_bit;
    s->opaque = opaque;

    FSK_mod_init(s);
}


void V23_demod_init(FSK_demod_state *s, int calling, put_bit_func put_bit, void *opaque)
{
    if (!calling) {
        /* 75 bauds */
        s->f_lo = 390;
        s->f_hi = 450;
        s->baud_rate = 75;
    } else {
        /* 1200 bauds */
        s->f_lo = 1300;
        s->f_hi = 2100;
        s->baud_rate = 1200;
    }
    s->sample_rate = SAMPLE_RATE;
    s->put_bit = put_bit;
    s->opaque = opaque;
 
    FSK_demod_init(s);
}


void V23_init(V23State *s, int calling, 
              get_bit_func get_bit, put_bit_func put_bit, void *opaque)
{
    V23_mod_init(&s->tx, calling, get_bit, opaque);
    V23_demod_init(&s->rx, calling, put_bit, opaque);
}

int V23_process(V23State *s, s16 *output, s16 *input, int nb_samples)
{
    FSK_mod(&s->tx, output, nb_samples);
    FSK_demod(&s->rx, input, nb_samples);
    return 0;
}