xref: /btstack/platform/posix/wav_util.h (revision 7f812a189335f9172d35692804c192682769db12)
1abc91186SMilanka Ringwald /*
2abc91186SMilanka Ringwald  * Copyright (C) 2016 BlueKitchen GmbH
3abc91186SMilanka Ringwald  *
4abc91186SMilanka Ringwald  * Redistribution and use in source and binary forms, with or without
5abc91186SMilanka Ringwald  * modification, are permitted provided that the following conditions
6abc91186SMilanka Ringwald  * are met:
7abc91186SMilanka Ringwald  *
8abc91186SMilanka Ringwald  * 1. Redistributions of source code must retain the above copyright
9abc91186SMilanka Ringwald  *    notice, this list of conditions and the following disclaimer.
10abc91186SMilanka Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11abc91186SMilanka Ringwald  *    notice, this list of conditions and the following disclaimer in the
12abc91186SMilanka Ringwald  *    documentation and/or other materials provided with the distribution.
13abc91186SMilanka Ringwald  * 3. Neither the name of the copyright holders nor the names of
14abc91186SMilanka Ringwald  *    contributors may be used to endorse or promote products derived
15abc91186SMilanka Ringwald  *    from this software without specific prior written permission.
16abc91186SMilanka Ringwald  * 4. Any redistribution, use, or modification is done solely for
17abc91186SMilanka Ringwald  *    personal benefit and not for any commercial purpose or for
18abc91186SMilanka Ringwald  *    monetary gain.
19abc91186SMilanka Ringwald  *
20abc91186SMilanka Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21abc91186SMilanka Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22abc91186SMilanka Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23abc91186SMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24abc91186SMilanka Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25abc91186SMilanka Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26abc91186SMilanka Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27abc91186SMilanka Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28abc91186SMilanka Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29abc91186SMilanka Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30abc91186SMilanka Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31abc91186SMilanka Ringwald  * SUCH DAMAGE.
32abc91186SMilanka Ringwald  *
33abc91186SMilanka Ringwald  * Please inquire about commercial licensing options at
34abc91186SMilanka Ringwald  * [email protected]
35abc91186SMilanka Ringwald  *
36abc91186SMilanka Ringwald  */
37abc91186SMilanka Ringwald 
38abc91186SMilanka Ringwald #include <stdint.h>
39abc91186SMilanka Ringwald #include <stdio.h>
40abc91186SMilanka Ringwald #include <stdlib.h>
41abc91186SMilanka Ringwald #include <string.h>
42abc91186SMilanka Ringwald #include <fcntl.h>
43abc91186SMilanka Ringwald #include <unistd.h>
44abc91186SMilanka Ringwald 
45abc91186SMilanka Ringwald // return 0 if ok
4692abe7b9SMatthias Ringwald 
4792abe7b9SMatthias Ringwald /**
48*7f812a18SMatthias Ringwald  * Open singleton wav writer
4992abe7b9SMatthias Ringwald  * @return 0 if ok
5092abe7b9SMatthias Ringwald  */
51abc91186SMilanka Ringwald int wav_writer_open(const char * filepath, int num_channels, int sampling_frequency);
5292abe7b9SMatthias Ringwald /**
5392abe7b9SMatthias Ringwald  * Write Int8 samples
5492abe7b9SMatthias Ringwald  * @return 0 if ok
5592abe7b9SMatthias Ringwald  */
56abc91186SMilanka Ringwald int wav_writer_write_int8(int num_samples, int8_t * data);
5792abe7b9SMatthias Ringwald /**
5892abe7b9SMatthias Ringwald  * Write Int16 samples (host endianess)
5992abe7b9SMatthias Ringwald  * @return 0 if ok
6092abe7b9SMatthias Ringwald  */
61fbc7c9f2SMilanka Ringwald int wav_writer_write_int16(int num_samples, int16_t * data);
6292abe7b9SMatthias Ringwald /**
6392abe7b9SMatthias Ringwald  * Write Little Endian Int16 samples
6492abe7b9SMatthias Ringwald  * @return 0 if ok
6592abe7b9SMatthias Ringwald  */
6692abe7b9SMatthias Ringwald int wav_writer_write_le_int16(int num_samples, int16_t * data);
6792abe7b9SMatthias Ringwald /**
6892abe7b9SMatthias Ringwald  * Close wav writer and update wav file header
6992abe7b9SMatthias Ringwald  * @return 0 if ok
7092abe7b9SMatthias Ringwald  */
71abc91186SMilanka Ringwald int wav_writer_close(void);
72abc91186SMilanka Ringwald 
73abc91186SMilanka Ringwald 
74*7f812a18SMatthias Ringwald /**
75*7f812a18SMatthias Ringwald  * Open singleton war reader
76*7f812a18SMatthias Ringwald  * @return 0 if ok
77*7f812a18SMatthias Ringwald  */
78abc91186SMilanka Ringwald int wav_reader_open(const char * filepath);
79*7f812a18SMatthias Ringwald /**
80*7f812a18SMatthias Ringwald  * Read Int8 samples
81*7f812a18SMatthias Ringwald  * @return 0 if ok
82*7f812a18SMatthias Ringwald  */
83abc91186SMilanka Ringwald int wav_reader_read_int8(int num_samples, int8_t * data);
84*7f812a18SMatthias Ringwald /**
85*7f812a18SMatthias Ringwald  * Read Int16 samples (host endianess)
86*7f812a18SMatthias Ringwald  * @return 0 if ok
87*7f812a18SMatthias Ringwald  */
88fbc7c9f2SMilanka Ringwald int wav_reader_read_int16(int num_samples, int16_t * data);
89*7f812a18SMatthias Ringwald /**
90*7f812a18SMatthias Ringwald  * Close war reader
91*7f812a18SMatthias Ringwald  * @return 0 if ok
92*7f812a18SMatthias Ringwald  */
93abc91186SMilanka Ringwald int wav_reader_close(void);
94abc91186SMilanka Ringwald 
95