xref: /btstack/3rd-party/lc3-google/tools/lc3bin.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 __LC3BIN_H
20*4930cef6SMatthias Ringwald #define __LC3BIN_H
21*4930cef6SMatthias Ringwald 
22*4930cef6SMatthias Ringwald #include <stdio.h>
23*4930cef6SMatthias Ringwald #include <stdint.h>
24*4930cef6SMatthias Ringwald #include <lc3.h>
25*4930cef6SMatthias Ringwald 
26*4930cef6SMatthias Ringwald 
27*4930cef6SMatthias Ringwald /**
28*4930cef6SMatthias Ringwald  * Read LC3 binary header
29*4930cef6SMatthias Ringwald  * fp              Opened file, moved after header on return
30*4930cef6SMatthias Ringwald  * frame_us        Return frame duration, in us
31*4930cef6SMatthias Ringwald  * srate_hz        Return samplerate, in Hz
32*4930cef6SMatthias Ringwald  * nchannels       Return number of channels
33*4930cef6SMatthias Ringwald  * nsamples        Return count of source samples by channels
34*4930cef6SMatthias Ringwald  * return          0: Ok  -1: Bad LC3 File
35*4930cef6SMatthias Ringwald  */
36*4930cef6SMatthias Ringwald int lc3bin_read_header(FILE *fp,
37*4930cef6SMatthias Ringwald     int *frame_us, int *srate_hz, int *nchannels, int *nsamples);
38*4930cef6SMatthias Ringwald 
39*4930cef6SMatthias Ringwald /**
40*4930cef6SMatthias Ringwald  * Read LC3 block of data
41*4930cef6SMatthias Ringwald  * fp              Opened file
42*4930cef6SMatthias Ringwald  * nchannels       Number of channels
43*4930cef6SMatthias Ringwald  * buffer          Output buffer of `nchannels * LC3_MAX_FRAME_BYTES`
44*4930cef6SMatthias Ringwald  * return          Size of each 'nchannels` frames, -1 on error
45*4930cef6SMatthias Ringwald  */
46*4930cef6SMatthias Ringwald int lc3bin_read_data(FILE *fp, int nchannels, void *buffer);
47*4930cef6SMatthias Ringwald 
48*4930cef6SMatthias Ringwald /**
49*4930cef6SMatthias Ringwald  * Write LC3 binary header
50*4930cef6SMatthias Ringwald  * fp              Opened file, moved after header on return
51*4930cef6SMatthias Ringwald  * frame_us        Frame duration, in us
52*4930cef6SMatthias Ringwald  * srate_hz        Samplerate, in Hz
53*4930cef6SMatthias Ringwald  * bitrate         Bitrate indication of the stream, in bps
54*4930cef6SMatthias Ringwald  * nchannels       Number of channels
55*4930cef6SMatthias Ringwald  * nsamples        Count of source samples by channels
56*4930cef6SMatthias Ringwald  */
57*4930cef6SMatthias Ringwald void lc3bin_write_header(FILE *fp,
58*4930cef6SMatthias Ringwald     int frame_us, int srate_hz, int bitrate, int nchannels, int nsamples);
59*4930cef6SMatthias Ringwald 
60*4930cef6SMatthias Ringwald /**
61*4930cef6SMatthias Ringwald  * Write LC3 block of data
62*4930cef6SMatthias Ringwald  * fp              Opened file
63*4930cef6SMatthias Ringwald  * data            The frames data
64*4930cef6SMatthias Ringwald  * nchannels       Number of channels
65*4930cef6SMatthias Ringwald  * frame_bytes     Size of each `nchannels` frames
66*4930cef6SMatthias Ringwald  */
67*4930cef6SMatthias Ringwald void lc3bin_write_data(FILE *fp,
68*4930cef6SMatthias Ringwald     const void *data, int nchannels, int frame_bytes);
69*4930cef6SMatthias Ringwald 
70*4930cef6SMatthias Ringwald 
71*4930cef6SMatthias Ringwald #endif /* __LC3BIN_H */
72