xref: /btstack/3rd-party/lc3-google/tools/wave.h (revision 4930cef6e21e6da2d7571b9259c7f0fb8bed3d01)
1*4930cef6SMatthias Ringwald /******************************************************************************
2*4930cef6SMatthias Ringwald  *
3*4930cef6SMatthias Ringwald  *  Copyright 2022 Google LLC
4*4930cef6SMatthias Ringwald  *
5*4930cef6SMatthias Ringwald  *  Licensed under the Apache License, Version 2.0 (the "License");
6*4930cef6SMatthias Ringwald  *  you may not use this file except in compliance with the License.
7*4930cef6SMatthias Ringwald  *  You may obtain a copy of the License at:
8*4930cef6SMatthias Ringwald  *
9*4930cef6SMatthias Ringwald  *  http://www.apache.org/licenses/LICENSE-2.0
10*4930cef6SMatthias Ringwald  *
11*4930cef6SMatthias Ringwald  *  Unless required by applicable law or agreed to in writing, software
12*4930cef6SMatthias Ringwald  *  distributed under the License is distributed on an "AS IS" BASIS,
13*4930cef6SMatthias Ringwald  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*4930cef6SMatthias Ringwald  *  See the License for the specific language governing permissions and
15*4930cef6SMatthias Ringwald  *  limitations under the License.
16*4930cef6SMatthias Ringwald  *
17*4930cef6SMatthias Ringwald  ******************************************************************************/
18*4930cef6SMatthias Ringwald 
19*4930cef6SMatthias Ringwald #ifndef __WAVE_H
20*4930cef6SMatthias Ringwald #define __WAVE_H
21*4930cef6SMatthias Ringwald 
22*4930cef6SMatthias Ringwald #include <stdio.h>
23*4930cef6SMatthias Ringwald #include <stdint.h>
24*4930cef6SMatthias Ringwald 
25*4930cef6SMatthias Ringwald 
26*4930cef6SMatthias Ringwald /**
27*4930cef6SMatthias Ringwald  * Read WAVE file header
28*4930cef6SMatthias Ringwald  * fp              Opened file, moved after header on return
29*4930cef6SMatthias Ringwald  * bitdepth        Return bitdepth
30*4930cef6SMatthias Ringwald  * samplesize      Return size of samples, in bytes
31*4930cef6SMatthias Ringwald  * samplerate      Return samplerate, in Hz
32*4930cef6SMatthias Ringwald  * nchannels       Return number of channels
33*4930cef6SMatthias Ringwald  * nframes         Return count of frames
34*4930cef6SMatthias Ringwald  * return          0: Ok  -1: Bad or unsupported WAVE File
35*4930cef6SMatthias Ringwald  */
36*4930cef6SMatthias Ringwald int wave_read_header(FILE *fp, int *bitdepth, int *samplesize,
37*4930cef6SMatthias Ringwald     int *samplerate, int *nchannels, int *nframes);
38*4930cef6SMatthias Ringwald 
39*4930cef6SMatthias Ringwald /**
40*4930cef6SMatthias Ringwald  * Read PCM samples from wave file
41*4930cef6SMatthias Ringwald  * fp              Opened file
42*4930cef6SMatthias Ringwald  * samplesize      Size of samples, in bytes
43*4930cef6SMatthias Ringwald  * nch, count      Number of channels and count of frames to read
44*4930cef6SMatthias Ringwald  * buffer          Output buffer of `nchannels * count` interleaved samples
45*4930cef6SMatthias Ringwald  * return          Number of frames read
46*4930cef6SMatthias Ringwald  */
47*4930cef6SMatthias Ringwald int wave_read_pcm(FILE *fp, int samplesize,
48*4930cef6SMatthias Ringwald     int nch, int count, void *_buffer);
49*4930cef6SMatthias Ringwald 
50*4930cef6SMatthias Ringwald /**
51*4930cef6SMatthias Ringwald  * Write WAVE file header
52*4930cef6SMatthias Ringwald  * fp              Opened file, moved after header on return
53*4930cef6SMatthias Ringwald  * bitdepth        Bitdepth
54*4930cef6SMatthias Ringwald  * samplesize      Size of samples
55*4930cef6SMatthias Ringwald  * samplerate      Samplerate, in Hz
56*4930cef6SMatthias Ringwald  * nchannels       Number of channels
57*4930cef6SMatthias Ringwald  * nframes         Count of frames
58*4930cef6SMatthias Ringwald  */
59*4930cef6SMatthias Ringwald void wave_write_header(FILE *fp, int bitdepth, int samplesize,
60*4930cef6SMatthias Ringwald     int samplerate, int nchannels, int nframes);
61*4930cef6SMatthias Ringwald 
62*4930cef6SMatthias Ringwald /**
63*4930cef6SMatthias Ringwald  * Write PCM samples to wave file
64*4930cef6SMatthias Ringwald  * fp              Opened file
65*4930cef6SMatthias Ringwald  * samplesize      Size of samples, in bytes
66*4930cef6SMatthias Ringwald  * pcm, nch        PCM frames, as 'nch' interleaved samples
67*4930cef6SMatthias Ringwald  * off, count      Offset and count of frames
68*4930cef6SMatthias Ringwald  */
69*4930cef6SMatthias Ringwald void wave_write_pcm(FILE *fp, int samplesize,
70*4930cef6SMatthias Ringwald     const void *pcm, int nch, int off, int count);
71*4930cef6SMatthias Ringwald 
72*4930cef6SMatthias Ringwald 
73*4930cef6SMatthias Ringwald #endif /* __WAVE_H */
74