xref: /btstack/platform/posix/wav_util.h (revision 86d6811aca843473b9a93ecebb7d71bc45fb6146)
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
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH 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 
384795fc1aSMatthias Ringwald #ifndef WAV_UIL_H
394795fc1aSMatthias Ringwald #define WAV_UIL_H
404795fc1aSMatthias Ringwald 
41abc91186SMilanka Ringwald #include <stdint.h>
42abc91186SMilanka Ringwald 
434795fc1aSMatthias Ringwald #if defined __cplusplus
444795fc1aSMatthias Ringwald extern "C" {
454795fc1aSMatthias Ringwald #endif
464795fc1aSMatthias Ringwald 
47abc91186SMilanka Ringwald // return 0 if ok
4892abe7b9SMatthias Ringwald 
4992abe7b9SMatthias Ringwald /**
507f812a18SMatthias Ringwald  * Open singleton wav writer
5192abe7b9SMatthias Ringwald  * @return 0 if ok
5292abe7b9SMatthias Ringwald  */
53abc91186SMilanka Ringwald int wav_writer_open(const char * filepath, int num_channels, int sampling_frequency);
5492abe7b9SMatthias Ringwald /**
5592abe7b9SMatthias Ringwald  * Write Int8 samples
5692abe7b9SMatthias Ringwald  * @return 0 if ok
5792abe7b9SMatthias Ringwald  */
58abc91186SMilanka Ringwald int wav_writer_write_int8(int num_samples, int8_t * data);
5992abe7b9SMatthias Ringwald /**
6092abe7b9SMatthias Ringwald  * Write Int16 samples (host endianess)
6192abe7b9SMatthias Ringwald  * @return 0 if ok
6292abe7b9SMatthias Ringwald  */
63fbc7c9f2SMilanka Ringwald int wav_writer_write_int16(int num_samples, int16_t * data);
6492abe7b9SMatthias Ringwald /**
6592abe7b9SMatthias Ringwald  * Write Little Endian Int16 samples
6692abe7b9SMatthias Ringwald  * @return 0 if ok
6792abe7b9SMatthias Ringwald  */
6892abe7b9SMatthias Ringwald int wav_writer_write_le_int16(int num_samples, int16_t * data);
6992abe7b9SMatthias Ringwald /**
7092abe7b9SMatthias Ringwald  * Close wav writer and update wav file header
7192abe7b9SMatthias Ringwald  * @return 0 if ok
7292abe7b9SMatthias Ringwald  */
73abc91186SMilanka Ringwald int wav_writer_close(void);
74abc91186SMilanka Ringwald 
75abc91186SMilanka Ringwald 
767f812a18SMatthias Ringwald /**
77*e2bf7a9aSMatthias Ringwald  * Open singleton wav reader
787f812a18SMatthias Ringwald  * @return 0 if ok
797f812a18SMatthias Ringwald  */
80abc91186SMilanka Ringwald int wav_reader_open(const char * filepath);
81*e2bf7a9aSMatthias Ringwald 
82*e2bf7a9aSMatthias Ringwald /**
83*e2bf7a9aSMatthias Ringwald  * Get number of channels
84*e2bf7a9aSMatthias Ringwald  */
85*e2bf7a9aSMatthias Ringwald uint8_t wav_reader_get_num_channels(void);
86*e2bf7a9aSMatthias Ringwald 
87*e2bf7a9aSMatthias Ringwald /**
88*e2bf7a9aSMatthias Ringwald  * Get sampling rate
89*e2bf7a9aSMatthias Ringwald  */
90*e2bf7a9aSMatthias Ringwald uint32_t wav_reader_get_sampling_rate(void);
91*e2bf7a9aSMatthias Ringwald 
927f812a18SMatthias Ringwald /**
937f812a18SMatthias Ringwald  * Read Int8 samples
947f812a18SMatthias Ringwald  * @return 0 if ok
957f812a18SMatthias Ringwald  */
96abc91186SMilanka Ringwald int wav_reader_read_int8(int num_samples, int8_t * data);
977f812a18SMatthias Ringwald /**
987f812a18SMatthias Ringwald  * Read Int16 samples (host endianess)
997f812a18SMatthias Ringwald  * @return 0 if ok
1007f812a18SMatthias Ringwald  */
101fbc7c9f2SMilanka Ringwald int wav_reader_read_int16(int num_samples, int16_t * data);
1027f812a18SMatthias Ringwald /**
1037f812a18SMatthias Ringwald  * Close war reader
1047f812a18SMatthias Ringwald  * @return 0 if ok
1057f812a18SMatthias Ringwald  */
106abc91186SMilanka Ringwald int wav_reader_close(void);
107abc91186SMilanka Ringwald 
1084795fc1aSMatthias Ringwald #if defined __cplusplus
1094795fc1aSMatthias Ringwald }
1104795fc1aSMatthias Ringwald #endif
1114795fc1aSMatthias Ringwald 
1124795fc1aSMatthias Ringwald #endif // WAV_UTIL_H
113