Fix some greedy sed changes in imported code. Also provide a sys/types.h for compatib...
[kugel-rb.git] / apps / codecs / libpcm / pcm_common.h
blob45b922afde0c394c552b972f714b048ac4d16e9e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Yoshihisa Uchida
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef CODEC_LIBPCM_PCM_COMMON_H
22 #define CODEC_LIBPCM_PCM_COMMON_H
24 #include <stdbool.h>
25 #include <inttypes.h>
27 /* decoded pcm sample depth (sample 28bit + sign 1bit) */
28 #define PCM_OUTPUT_DEPTH 29
30 /* Macro that sign extends an unsigned byte */
31 #define SE(x) ((int32_t)((int8_t)(x)))
33 /* Macro that shift to -0x80. (0 .. 127 to -128 .. -1, 128 .. 255 to 0 .. 127) */
34 #define SFT(x) ((int32_t)x-0x80)
36 /* Macro that clipping data */
37 #define CLIP(data, min, max) \
38 if ((data) > (max)) data = max; \
39 else if ((data) < (min)) data = min;
41 /* nums of msadpcm coeffs
42 * In many case, nNumCoef is 7.
43 * Depending upon the encoder, as for this value there is a possibility
44 * of increasing more.
45 * If you found the file where this value exceeds 7, please report.
47 #define MSADPCM_NUM_COEFF 7
49 struct pcm_format {
51 * RIFF: wFormatTag (in 'fmt ' chunk)
52 * AIFF: compressionType (in 'COMM' chunk)
54 uint32_t formattag;
57 * RIFF: wChannels (in 'fmt ' chunk)
58 * AIFF: numChannels (in 'COMM' chunk)
60 uint16_t channels;
63 * RIFF: dwSamplesPerSec (in 'fmt ' chunk)
64 * AIFF: sampleRate (in 'COMM' chunk)
66 uint32_t samplespersec;
68 /* RIFF: dwAvgBytesPerSec (in 'fmt ' chunk) */
69 uint32_t avgbytespersec;
72 * RIFF: wBlockAlign (in 'fmt ' chunk)
73 * AIFF: blockSize (in 'SSND' chunk)
75 uint16_t blockalign;
78 * RIFF: wBitsPerSample (in 'fmt ' chunk)
79 * AIFF: sampleSize (in 'COMM' chunk)
81 uint16_t bitspersample;
83 /* RIFF: wSize (in 'fmt ' chunk) */
84 uint16_t size;
86 /* RIFF: dSamplesPerBlock (in 'fmt ' chunk) */
87 uint16_t samplesperblock;
89 /* RIFF: wTotalSamples (in 'fact' chunk) */
90 uint16_t totalsamples;
92 /* the following values are not RIFF/AIFF chunk values */
94 /* bytes per sample */
95 int bytespersample;
97 /* chunk size */
98 long chunksize;
100 /* data size */
101 uint32_t numbytes;
104 * data endian
105 * true: little endian, false: big endian
107 bool is_little_endian;
110 * data signess
111 * true: signed, false: unsigned
113 bool is_signed;
115 /* the following values are format speciffic parameters */
117 /* microsoft adpcm: aCoeff */
118 int16_t coeffs[MSADPCM_NUM_COEFF][2];
121 struct pcm_pos {
122 uint32_t pos;
123 uint32_t samples;
126 #define PCM_SEEK_TIME 0
127 #define PCM_SEEK_POS 1
129 struct pcm_codec {
131 * sets the format speciffic RIFF/AIFF header information and checks the pcm_format.
133 * [In/Out] format
134 * the structure which supplies RIFF/AIFF header information.
136 * return
137 * true: RIFF/AIFF header check OK
138 * false: RIFF/AIFF header check NG
140 bool (*set_format)(struct pcm_format *format);
143 * get seek position
145 * [In] seek_val
146 * seek time [ms] or seek position
148 * [In] seek_mode
149 * if seek_mode sets PCM_SEEK_TIME, then seek_val means the seek time.
150 * if seek_mode sets PCM_SEEK_POS, then seek_val means the seek position.
152 * [In] read_buffer
153 * the function which reads the data from the file (chunksize bytes read).
155 * return
156 * position after the seeking.
158 struct pcm_pos *(*get_seek_pos)(uint32_t seek_val, int seek_mode,
159 uint8_t *(*read_buffer)(size_t *realsize));
162 * decode wave data.
164 * [In] inbuf
165 * the start pointer of wave data buffer.
167 * [In] inbufsize
168 * wave data buffer size (bytes).
170 * [Out] outbuf
171 * the start pointer of the buffer which supplies decoded pcm data.
173 * [Out] outbufcount
174 * decoded pcm data count.
176 * return
177 * CODEC_OK: decode succeed.
178 * CODEC_ERROR: decode failure.
180 int (*decode)(const uint8_t *inbuf, size_t inbufsize,
181 int32_t *outbuf, int *outbufcount);
184 struct pcm_entry {
185 uint32_t format_tag;
186 const struct pcm_codec *(*get_codec)(void);
189 #endif