1 /* Copyright (C) 2002 Jean-Marc Valin
2    File: wav_io.h
3 
4    Redistribution and use in source and binary forms, with or without
5    modification, are permitted provided that the following conditions
6    are met:
7 
8    - Redistributions of source code must retain the above copyright
9    notice, this list of conditions and the following disclaimer.
10 
11    - Redistributions in binary form must reproduce the above copyright
12    notice, this list of conditions and the following disclaimer in the
13    documentation and/or other materials provided with the distribution.
14 
15    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
19    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef WAV_IO_H
29 #define WAV_IO_H
30 
31 #include <stdio.h>
32 #include "celt_types.h"
33 
34 #if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
35 #define le_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
36 #define be_short(s) ((short) (s))
37 #else
38 #define le_short(s) ((short) (s))
39 #define be_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
40 #endif
41 
42 /** Convert little endian */
le_int(celt_int32 i)43 static inline celt_int32 le_int(celt_int32 i)
44 {
45 #if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
46    celt_uint32 ui, ret;
47    ui = i;
48    ret =  ui>>24;
49    ret |= (ui>>8)&0x0000ff00;
50    ret |= (ui<<8)&0x00ff0000;
51    ret |= (ui<<24);
52    return ret;
53 #else
54    return i;
55 #endif
56 }
57 
58 int read_wav_header(FILE *file, int *rate, int *channels, int *format, celt_int32 *size);
59 
60 void write_wav_header(FILE *file, int rate, int channels, int format, int size);
61 
62 #endif
63