commit FS#10424 and FS#10425
[kugel-rb.git] / apps / codecs / libpcm / pcm_common.h
blobd490a85e9f012e99ca1c90b002c6288d998eafc5
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>
29 * PCM_CHUNK_SIZE has the size only of storing the sample at 1/50 seconds.
30 * But it might not be 1/50 seconds according to the format.
31 * Please confirm the source file of each format.
33 #define PCM_CHUNK_SIZE (4096*2)
35 /* Macro that sign extends an unsigned byte */
36 #define SE(x) ((int32_t)((int8_t)(x)))
38 /* Macro that shift to -0x80. (0 .. 127 to -128 .. -1, 128 .. 255 to 0 .. 127) */
39 #define SFT(x) ((int32_t)x-0x80)
41 /* Macro that clipping data */
42 #define CLIP(data, min, max) \
43 if ((data) > (max)) data = max; \
44 else if ((data) < (min)) data = min;
46 /* nums of msadpcm coeffs
47 * In many case, nNumCoef is 7.
48 * Depending upon the encoder, as for this value there is a possibility
49 * of increasing more.
50 * If you found the file where this value exceeds 7, please report.
52 #define MSADPCM_NUM_COEFF 7
54 struct pcm_format {
56 * RIFF: wFormatTag (in 'fmt ' chunk)
57 * AIFF: compressionType (in 'COMM' chunk)
59 uint32_t formattag;
62 * RIFF: wChannels (in 'fmt ' chunk)
63 * AIFF: numChannels (in 'COMM' chunk)
65 uint16_t channels;
68 * RIFF: dwSamplesPerSec (in 'fmt ' chunk)
69 * AIFF: sampleRate (in 'COMM' chunk)
71 uint32_t samplespersec;
73 /* RIFF: dwAvgBytesPerSec (in 'fmt ' chunk) */
74 uint32_t avgbytespersec;
77 * RIFF: wBlockAlign (in 'fmt ' chunk)
78 * AIFF: blockSize (in 'SSND' chunk)
80 uint16_t blockalign;
83 * RIFF: wBitsPerSample (in 'fmt ' chunk)
84 * AIFF: sampleSize (in 'COMM' chunk)
86 uint16_t bitspersample;
88 /* RIFF: wSize (in 'fmt ' chunk) */
89 uint16_t size;
91 /* RIFF: dSamplesPerBlock (in 'fmt ' chunk) */
92 uint16_t samplesperblock;
94 /* RIFF: wTotalSamples (in 'fact' chunk) */
95 uint16_t totalsamples;
97 /* the following values are not RIFF/AIFF chunk values */
99 /* bytes per sample */
100 int bytespersample;
102 /* chunk size */
103 long chunksize;
105 /* data size */
106 uint32_t numbytes;
109 * data endian
110 * true: little endian, false: big endian
112 bool is_little_endian;
115 * data signess
116 * true: signed, false: unsigned
118 bool is_signed;
120 /* the following values are format speciffic parameters */
122 /* microsoft adpcm: aCoeff */
123 int16_t coeffs[MSADPCM_NUM_COEFF][2];
126 struct pcm_pos {
127 uint32_t pos;
128 uint32_t samples;
131 struct pcm_codec {
133 * sets the format speciffic RIFF/AIFF header information and checks the pcm_format.
135 * [In/Out] format
136 * the structure which supplies RIFF/AIFF header information.
138 * return
139 * true: RIFF/AIFF header check OK
140 * false: RIFF/AIFF header check NG
142 bool (*set_format)(struct pcm_format *format);
145 * get seek position
147 * [In] seek_time
148 * seek time [ms]
150 * [In] read_buffer
151 * the function which reads the data from the file (chunksize bytes read).
153 * return
154 * position after the seeking.
156 struct pcm_pos *(*get_seek_pos)(long seek_time,
157 uint8_t *(*read_buffer)(size_t *realsize));
160 * decode wave data.
162 * [In] inbuf
163 * the start pointer of wave data buffer.
165 * [In] inbufsize
166 * wave data buffer size (bytes).
168 * [Out] outbuf
169 * the start pointer of the buffer which supplies decoded pcm data.
171 * [Out] outbufcount
172 * decoded pcm data count.
174 * return
175 * CODEC_OK: decode succeed.
176 * CODEC_ERROR: decode failure.
178 int (*decode)(const uint8_t *inbuf, size_t inbufsize,
179 int32_t *outbuf, int *outbufcount);
182 struct pcm_entry {
183 uint32_t format_tag;
184 const struct pcm_codec *(*get_codec)(void);
187 #endif