aboutsummaryrefslogtreecommitdiff
path: root/unittest/freedv_700d_comptx.c
blob: 9f66c76524694e1f4b0595a6b5e6af46242ad169 (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
/*---------------------------------------------------------------------------*\

  freedv_comptx.c

  Complex valued Tx to support ctests.

\*---------------------------------------------------------------------------*/

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "freedv_api.h"

int main(int argc, char *argv[]) {
  struct freedv *freedv;

  freedv = freedv_open(FREEDV_MODE_700D);
  assert(freedv != NULL);

  /* handy functions to set buffer sizes */
  int n_speech_samples = freedv_get_n_speech_samples(freedv);
  short speech_in[n_speech_samples];
  int n_nom_modem_samples = freedv_get_n_nom_modem_samples(freedv);
  COMP mod_out[n_nom_modem_samples];
  short mod_out_short[2 * n_nom_modem_samples];

  /* OK main loop  --------------------------------------- */

  while (fread(speech_in, sizeof(short), n_speech_samples, stdin) ==
         n_speech_samples) {
    freedv_comptx(freedv, mod_out, speech_in);
    for (int i = 0; i < n_nom_modem_samples; i++) {
      mod_out_short[2 * i] = mod_out[i].real;
      mod_out_short[2 * i + 1] = mod_out[i].imag;
    }
    fwrite(mod_out_short, sizeof(short), 2 * n_nom_modem_samples, stdout);
  }

  freedv_close(freedv);

  return 0;
}