summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libpcm/pcm_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libpcm/pcm_common.h')
-rw-r--r--lib/rbcodec/codecs/libpcm/pcm_common.h190
1 files changed, 190 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libpcm/pcm_common.h b/lib/rbcodec/codecs/libpcm/pcm_common.h
new file mode 100644
index 0000000000..90e29c98ee
--- /dev/null
+++ b/lib/rbcodec/codecs/libpcm/pcm_common.h
@@ -0,0 +1,190 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Yoshihisa Uchida
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef CODEC_LIBPCM_PCM_COMMON_H
22#define CODEC_LIBPCM_PCM_COMMON_H
23
24#include <stdbool.h>
25#include <inttypes.h>
26#include <string.h>
27
28/* decoded pcm sample depth (sample 28bit + sign 1bit) */
29#define PCM_OUTPUT_DEPTH 29
30
31/* Macro that sign extends an unsigned byte */
32#define SE(x) ((int32_t)((int8_t)(x)))
33
34/* Macro that shift to -0x80. (0 .. 127 to -128 .. -1, 128 .. 255 to 0 .. 127) */
35#define SFT(x) ((int32_t)x-0x80)
36
37/* Macro that clipping data */
38#define CLIP(data, min, max) \
39if ((data) > (max)) data = max; \
40else if ((data) < (min)) data = min;
41
42/* nums of msadpcm coeffs
43 * In many case, nNumCoef is 7.
44 * Depending upon the encoder, as for this value there is a possibility
45 * of increasing more.
46 * If you found the file where this value exceeds 7, please report.
47 */
48#define MSADPCM_NUM_COEFF 7
49
50struct pcm_format {
51 /*
52 * RIFF: wFormatTag (in 'fmt ' chunk)
53 * AIFF: compressionType (in 'COMM' chunk)
54 */
55 uint32_t formattag;
56
57 /*
58 * RIFF: wChannels (in 'fmt ' chunk)
59 * AIFF: numChannels (in 'COMM' chunk)
60 */
61 uint16_t channels;
62
63 /*
64 * RIFF: dwSamplesPerSec (in 'fmt ' chunk)
65 * AIFF: sampleRate (in 'COMM' chunk)
66 */
67 uint32_t samplespersec;
68
69 /* RIFF: dwAvgBytesPerSec (in 'fmt ' chunk) */
70 uint32_t avgbytespersec;
71
72 /*
73 * RIFF: wBlockAlign (in 'fmt ' chunk)
74 * AIFF: blockSize (in 'SSND' chunk)
75 */
76 uint16_t blockalign;
77
78 /*
79 * RIFF: wBitsPerSample (in 'fmt ' chunk)
80 * AIFF: sampleSize (in 'COMM' chunk)
81 */
82 uint16_t bitspersample;
83
84 /* RIFF: wSize (in 'fmt ' chunk) */
85 uint16_t size;
86
87 /* RIFF: dSamplesPerBlock (in 'fmt ' chunk) */
88 uint16_t samplesperblock;
89
90 /* RIFF: wTotalSamples (in 'fact' chunk) */
91 uint16_t totalsamples;
92
93 /* the following values are not RIFF/AIFF chunk values */
94
95 /* bytes per sample */
96 int bytespersample;
97
98 /* chunk size */
99 long chunksize;
100
101 /* data size */
102 uint32_t numbytes;
103
104 /*
105 * data endian
106 * true: little endian, false: big endian
107 */
108 bool is_little_endian;
109
110 /*
111 * data signess
112 * true: signed, false: unsigned
113 */
114 bool is_signed;
115
116 /* the following values are format speciffic parameters */
117
118 /* microsoft adpcm: aCoeff */
119 int16_t coeffs[MSADPCM_NUM_COEFF][2];
120};
121
122struct pcm_pos {
123 uint32_t pos;
124 uint32_t samples;
125};
126
127#define PCM_SEEK_TIME 0
128#define PCM_SEEK_POS 1
129
130struct pcm_codec {
131 /*
132 * sets the format speciffic RIFF/AIFF header information and checks the pcm_format.
133 *
134 * [In/Out] format
135 * the structure which supplies RIFF/AIFF header information.
136 *
137 * return
138 * true: RIFF/AIFF header check OK
139 * false: RIFF/AIFF header check NG
140 */
141 bool (*set_format)(struct pcm_format *format);
142
143 /*
144 * get seek position
145 *
146 * [In] seek_val
147 * seek time [ms] or seek position
148 *
149 * [In] seek_mode
150 * if seek_mode sets PCM_SEEK_TIME, then seek_val means the seek time.
151 * if seek_mode sets PCM_SEEK_POS, then seek_val means the seek position.
152 *
153 * [In] read_buffer
154 * the function which reads the data from the file (chunksize bytes read).
155 *
156 * return
157 * position after the seeking.
158 */
159 struct pcm_pos *(*get_seek_pos)(uint32_t seek_val, int seek_mode,
160 uint8_t *(*read_buffer)(size_t *realsize));
161
162 /*
163 * decode wave data.
164 *
165 * [In] inbuf
166 * the start pointer of wave data buffer.
167 *
168 * [In] inbufsize
169 * wave data buffer size (bytes).
170 *
171 * [Out] outbuf
172 * the start pointer of the buffer which supplies decoded pcm data.
173 *
174 * [Out] outbufcount
175 * decoded pcm data count.
176 *
177 * return
178 * CODEC_OK: decode succeed.
179 * CODEC_ERROR: decode failure.
180 */
181 int (*decode)(const uint8_t *inbuf, size_t inbufsize,
182 int32_t *outbuf, int *outbufcount);
183};
184
185struct pcm_entry {
186 uint32_t format_tag;
187 const struct pcm_codec *(*get_codec)(void);
188};
189
190#endif