-
Notifications
You must be signed in to change notification settings - Fork 90
/
soundfile.c
111 lines (93 loc) · 2.34 KB
/
soundfile.c
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Copyright (c) 2014 Thierry Leconte (f4dwv)
*
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#ifdef WITH_SNDFILE
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sndfile.h>
#include "acarsdec.h"
#define MAXNBFRAMES 4096
static SNDFILE *insnd;
int initSoundfile(char **argv, int optind)
{
SF_INFO infsnd;
int n;
infsnd.format = 0;
insnd = sf_open(argv[optind], SFM_READ, &infsnd);
if (insnd == NULL) {
fprintf(stderr, "could not open %s\n", argv[optind]);
return (1);
}
nbch = infsnd.channels;
if (nbch > MAXNBCHANNELS) {
fprintf(stderr, "Too much input channels : %d\n", nbch);
return (1);
}
if(infsnd.samplerate!=INTRATE) {
fprintf(stderr, "unsupported sample rate : %d (must be %d)\n",infsnd.samplerate,INTRATE);
return (1);
}
for (n = 0; n < nbch; n++) {
channel[n].dm_buffer=malloc(sizeof(float)*MAXNBFRAMES);
}
return (0);
}
int runSoundfileSample(void)
{
int nbi, n, i;
sample_t sndbuff[MAXNBFRAMES * MAXNBCHANNELS];
do {
nbi = sf_read_float(insnd, sndbuff, MAXNBFRAMES * nbch);
if (nbi == 0) {
return -1;
}
for (n = 0; n < nbch; n++) {
int len = nbi / nbch;
for (i = 0; i < len; i++)
channel[n].dm_buffer[i]=sndbuff[n + i * nbch];
demodMSK(&(channel[n]),len);
}
} while (1);
return 0;
}
#ifdef DEBUG
static SNDFILE *outsnd;
void initSndWrite(void)
{
SF_INFO infsnd;
infsnd.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
infsnd.samplerate = INTRATE;
infsnd.channels = 1;
outsnd = sf_open("data.wav", SFM_WRITE, &infsnd);
if (outsnd == NULL) {
fprintf(stderr, "could not open data\n ");
return;
}
}
void SndWrite(float *in)
{
sf_write_float(outsnd, in, 1);
}
void SndWriteClose(void)
{
sf_close(outsnd);
}
#endif
#endif