libpcm: deletes PCM_CHUNK_SIZE.
[kugel-rb.git] / apps / codecs / libpcm / pcm_common.h
blob7dcacbd19afc93d8e40916f3c1e9a617fe518d02
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 <sys/types.h>
25 #include <stdbool.h>
26 #include <inttypes.h>
28 /* Macro that sign extends an unsigned byte */
29 #define SE(x) ((int32_t)((int8_t)(x)))
31 /* Macro that shift to -0x80. (0 .. 127 to -128 .. -1, 128 .. 255 to 0 .. 127) */
32 #define SFT(x) ((int32_t)x-0x80)
34 /* Macro that clipping data */
35 #define CLIP(data, min, max) \
36 if ((data) > (max)) data = max; \
37 else if ((data) < (min)) data = min;
39 /* nums of msadpcm coeffs
40 * In many case, nNumCoef is 7.
41 * Depending upon the encoder, as for this value there is a possibility
42 * of increasing more.
43 * If you found the file where this value exceeds 7, please report.
45 #define MSADPCM_NUM_COEFF 7
47 struct pcm_format {
49 * RIFF: wFormatTag (in 'fmt ' chunk)
50 * AIFF: compressionType (in 'COMM' chunk)
52 uint32_t formattag;
55 * RIFF: wChannels (in 'fmt ' chunk)
56 * AIFF: numChannels (in 'COMM' chunk)
58 uint16_t channels;
61 * RIFF: dwSamplesPerSec (in 'fmt ' chunk)
62 * AIFF: sampleRate (in 'COMM' chunk)
64 uint32_t samplespersec;
66 /* RIFF: dwAvgBytesPerSec (in 'fmt ' chunk) */
67 uint32_t avgbytespersec;
70 * RIFF: wBlockAlign (in 'fmt ' chunk)
71 * AIFF: blockSize (in 'SSND' chunk)
73 uint16_t blockalign;
76 * RIFF: wBitsPerSample (in 'fmt ' chunk)
77 * AIFF: sampleSize (in 'COMM' chunk)
79 uint16_t bitspersample;
81 /* RIFF: wSize (in 'fmt ' chunk) */
82 uint16_t size;
84 /* RIFF: dSamplesPerBlock (in 'fmt ' chunk) */
85 uint16_t samplesperblock;
87 /* RIFF: wTotalSamples (in 'fact' chunk) */
88 uint16_t totalsamples;
90 /* the following values are not RIFF/AIFF chunk values */
92 /* bytes per sample */
93 int bytespersample;
95 /* chunk size */
96 long chunksize;
98 /* data size */
99 uint32_t numbytes;
102 * data endian
103 * true: little endian, false: big endian
105 bool is_little_endian;
108 * data signess
109 * true: signed, false: unsigned
111 bool is_signed;
113 /* the following values are format speciffic parameters */
115 /* microsoft adpcm: aCoeff */
116 int16_t coeffs[MSADPCM_NUM_COEFF][2];
119 struct pcm_pos {
120 uint32_t pos;
121 uint32_t samples;
124 struct pcm_codec {
126 * sets the format speciffic RIFF/AIFF header information and checks the pcm_format.
128 * [In/Out] format
129 * the structure which supplies RIFF/AIFF header information.
131 * return
132 * true: RIFF/AIFF header check OK
133 * false: RIFF/AIFF header check NG
135 bool (*set_format)(struct pcm_format *format);
138 * get seek position
140 * [In] seek_time
141 * seek time [ms]
143 * [In] read_buffer
144 * the function which reads the data from the file (chunksize bytes read).
146 * return
147 * position after the seeking.
149 struct pcm_pos *(*get_seek_pos)(long seek_time,
150 uint8_t *(*read_buffer)(size_t *realsize));
153 * decode wave data.
155 * [In] inbuf
156 * the start pointer of wave data buffer.
158 * [In] inbufsize
159 * wave data buffer size (bytes).
161 * [Out] outbuf
162 * the start pointer of the buffer which supplies decoded pcm data.
164 * [Out] outbufcount
165 * decoded pcm data count.
167 * return
168 * CODEC_OK: decode succeed.
169 * CODEC_ERROR: decode failure.
171 int (*decode)(const uint8_t *inbuf, size_t inbufsize,
172 int32_t *outbuf, int *outbufcount);
175 struct pcm_entry {
176 uint32_t format_tag;
177 const struct pcm_codec *(*get_codec)(void);
180 #endif