summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libmusepack/mpcdec.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libmusepack/mpcdec.h')
-rw-r--r--lib/rbcodec/codecs/libmusepack/mpcdec.h212
1 files changed, 212 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libmusepack/mpcdec.h b/lib/rbcodec/codecs/libmusepack/mpcdec.h
new file mode 100644
index 0000000000..85536e726a
--- /dev/null
+++ b/lib/rbcodec/codecs/libmusepack/mpcdec.h
@@ -0,0 +1,212 @@
1/*
2 Copyright (c) 2005-2009, The Musepack Development Team
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the The Musepack Development Team nor the
18 names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior
20 written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*/
34/// \file mpcdec.h
35/// Top level include file for libmpcdec.
36#ifndef _MPCDEC_H_
37#define _MPCDEC_H_
38#ifdef WIN32
39#pragma once
40#endif
41
42#include "reader.h"
43#include "streaminfo.h"
44#include "config.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50#if (CONFIG_CPU == MCF5250)
51/* Enough IRAM but performance suffers with ICODE_ATTR. */
52#define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
53#define ICODE_ATTR_MPC_LARGE_IRAM
54#define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR
55/* Does not fit into IRAM. */
56#define IBSS_ATTR_MPC_BITBUFFER
57#define ICODE_ATTR_MPC_SV8_BS_DEC
58/* Keep the data arrays of bitsreadr.c in IRAM. */
59#define ICONST_ATTR_MPC_BITSREADER ICONST_ATTR
60
61#elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
62/* Enough IRAM to move additional data and code to it. */
63#define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
64#define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR
65#define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR
66/* Does not fit into IRAM. */
67#define IBSS_ATTR_MPC_BITBUFFER
68#define ICODE_ATTR_MPC_SV8_BS_DEC
69/* Not putting the data arrays of bitsreader.c to IRAM allows to move the
70 * sv7/sv8 bitstream demuxing into IRAM. This config is faster. */
71#define ICONST_ATTR_MPC_BITSREADER
72
73#elif defined(CPU_S5L870X)
74/* Enough IRAM to move additional data and code to it. */
75#define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
76#define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR
77#define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR
78/* Faster when moved to IRAM. */
79#define IBSS_ATTR_MPC_BITBUFFER IBSS_ATTR
80#define ICODE_ATTR_MPC_SV8_BS_DEC ICODE_ATTR
81/* Not faster when moved to IRAM. */
82#define ICONST_ATTR_MPC_BITSREADER
83
84#else
85/* Not enough IRAM available. */
86#define IBSS_ATTR_MPC_LARGE_IRAM
87#define ICODE_ATTR_MPC_LARGE_IRAM
88#define ICONST_ATTR_MPC_LARGE_IRAM
89#define IBSS_ATTR_MPC_BITBUFFER
90#define ICODE_ATTR_MPC_SV8_BS_DEC
91#define ICONST_ATTR_MPC_BITSREADER
92#endif
93
94enum {
95 MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame
96 MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels)
97 MPC_DECODER_SYNTH_DELAY = 481
98};
99
100typedef struct mpc_decoder_t mpc_decoder;
101typedef struct mpc_demux_t mpc_demux;
102
103typedef struct mpc_bits_reader_t {
104 unsigned char * buff; /// pointer on current byte
105 unsigned int count; /// unread bits in current byte
106 mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only
107 mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only
108} mpc_bits_reader;
109
110typedef struct mpc_frame_info_t {
111 mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels)
112 mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream
113 MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT))
114 mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer.
115} mpc_frame_info;
116
117/* rockbox: not used
118typedef struct mpc_chap_info_t {
119 mpc_uint64_t sample; /// sample where the chapter starts
120 mpc_uint16_t gain; /// replaygain chapter value
121 mpc_uint16_t peak; /// peak chapter loudness level
122 mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter)
123 char * tag; /// pointer to an APEv2 tag without the preamble
124} mpc_chap_info;
125*/
126
127/// Initializes mpc decoder with the supplied stream info parameters.
128/// \param si streaminfo structure indicating format of source stream
129/// \return pointer on the initialized decoder structure if successful, 0 if not
130MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si);
131
132/* rockbox: not used
133/// Releases input mpc decoder
134MPC_API void mpc_decoder_exit(mpc_decoder *p_dec);
135*/
136
137/**
138 * Sets decoder sample scaling factor. All decoded samples will be multiplied
139 * by this factor. Useful for applying replay gain.
140 * @param scale_factor multiplicative scaling factor
141 */
142/* rockbox: changed to static
143MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor);
144*/
145
146MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i);
147
148// This is the gain reference used in old replaygain
149#define MPC_OLD_GAIN_REF 64.82
150
151/**
152 * init demuxer
153 * @param p_reader initialized mpc_reader pointer
154 * @return an initialized mpc_demux pointer
155 */
156MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader);
157/* rockbox: not used
158/// free demuxer
159MPC_API void mpc_demux_exit(mpc_demux * d);
160*/
161/**
162 * Calls mpc_decoder_scale_output to set the scaling factor according to the
163 * replay gain stream information and the supplied ouput level
164 * @param d pointer to a musepack demuxer
165 * @param level the desired ouput level (in db). Must be MPC_OLD_GAIN_REF (64.82 db) if you want to get the old replaygain behavior
166 * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain
167 * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain
168 * @param clip_prevention MPC_TRUE : uses cliping prevention
169 */
170/* rockbox: not used
171MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain,
172 mpc_bool_t use_title, mpc_bool_t clip_prevention);
173*/
174/// decode frame
175MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i);
176/// get streaminfo
177MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i);
178/// seeks to a given sample
179MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample);
180/* rockbox: not used
181/// seeks to a given second
182MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds);
183*/
184
185/* rockbox: keep static
186/// \return the current position in the stream (in bits) from the beginning of the file
187MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d);
188*/
189
190/// chapters : only for sv8 streams
191/**
192 * Gets the number of chapters in the stream
193 * @param d pointer to a musepack demuxer
194 * @return the number of chapters found in the stream
195 */
196/* rockbox: not used
197MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d);
198*/
199/**
200 * Gets datas associated to a given chapter
201 * The chapter tag is an APEv2 tag without the preamble
202 * @param d pointer to a musepack demuxer
203 * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1)
204 * @return the chapter information structure
205 */
206/* rockbox: not used
207MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb);
208*/
209#ifdef __cplusplus
210}
211#endif
212#endif