Housekeeping. Comment musepack code seqments unused in rockbox.
[kugel-rb.git] / apps / codecs / libmusepack / mpcdec.h
blobf6aab9b16e558dba3af4f9e1d8eefcc0c01dca70
1 /*
2 Copyright (c) 2005-2009, The Musepack Development Team
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
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.
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.
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.
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
42 #include "reader.h"
43 #include "streaminfo.h"
44 #include "config.h"
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
50 #if (CONFIG_CPU == MCF5250) || defined(CPU_S5L870X)
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 /* Keep the data arrays of bitsreadr.c in IRAM. */
56 #define ICONST_ATTR_MPC_BITSREADER ICONST_ATTR
58 #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
59 /* Enough IRAM to move additional data and code to it. */
60 #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
61 #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR
62 #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR
63 /* Not putting the data arrays of bitsreader.c to IRAM allows to move the
64 * sv7/sv8 bitstream demuxing into IRAM. This config is faster. */
65 #define ICONST_ATTR_MPC_BITSREADER
67 #else
68 /* Not enough IRAM available. */
69 #define IBSS_ATTR_MPC_LARGE_IRAM
70 #define ICODE_ATTR_MPC_LARGE_IRAM
71 #define ICONST_ATTR_MPC_LARGE_IRAM
72 #define ICONST_ATTR_MPC_BITSREADER
73 #endif
75 enum {
76 MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame
77 MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels)
78 MPC_DECODER_SYNTH_DELAY = 481
81 typedef struct mpc_decoder_t mpc_decoder;
82 typedef struct mpc_demux_t mpc_demux;
84 typedef struct mpc_bits_reader_t {
85 unsigned char * buff; /// pointer on current byte
86 unsigned int count; /// unread bits in current byte
87 mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only
88 mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only
89 } mpc_bits_reader;
91 typedef struct mpc_frame_info_t {
92 mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels)
93 mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream
94 MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT))
95 mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer.
96 } mpc_frame_info;
98 /* rockbox: not used
99 typedef struct mpc_chap_info_t {
100 mpc_uint64_t sample; /// sample where the chapter starts
101 mpc_uint16_t gain; /// replaygain chapter value
102 mpc_uint16_t peak; /// peak chapter loudness level
103 mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter)
104 char * tag; /// pointer to an APEv2 tag without the preamble
105 } mpc_chap_info;
108 /// Initializes mpc decoder with the supplied stream info parameters.
109 /// \param si streaminfo structure indicating format of source stream
110 /// \return pointer on the initialized decoder structure if successful, 0 if not
111 MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si);
113 /* rockbox: not used
114 /// Releases input mpc decoder
115 MPC_API void mpc_decoder_exit(mpc_decoder *p_dec);
119 * Sets decoder sample scaling factor. All decoded samples will be multiplied
120 * by this factor. Useful for applying replay gain.
121 * @param scale_factor multiplicative scaling factor
123 MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor);
125 MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i);
127 // This is the gain reference used in old replaygain
128 #define MPC_OLD_GAIN_REF 64.82
131 * init demuxer
132 * @param p_reader initialized mpc_reader pointer
133 * @return an initialized mpc_demux pointer
135 MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader);
136 /* rockbox: not used
137 /// free demuxer
138 MPC_API void mpc_demux_exit(mpc_demux * d);
141 * Calls mpc_decoder_scale_output to set the scaling factor according to the
142 * replay gain stream information and the supplied ouput level
143 * @param d pointer to a musepack demuxer
144 * @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
145 * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain
146 * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain
147 * @param clip_prevention MPC_TRUE : uses cliping prevention
149 /* rockbox: not used
150 MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain,
151 mpc_bool_t use_title, mpc_bool_t clip_prevention);
153 /// decode frame
154 MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i);
155 /// get streaminfo
156 MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i);
157 /// seeks to a given sample
158 MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample);
159 /* rockbox: not used
160 /// seeks to a given second
161 MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds);
164 /* rockbox: keep static
165 /// \return the current position in the stream (in bits) from the beginning of the file
166 MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d);
169 /// chapters : only for sv8 streams
171 * Gets the number of chapters in the stream
172 * @param d pointer to a musepack demuxer
173 * @return the number of chapters found in the stream
175 /* rockbox: not used
176 MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d);
179 * Gets datas associated to a given chapter
180 * The chapter tag is an APEv2 tag without the preamble
181 * @param d pointer to a musepack demuxer
182 * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1)
183 * @return the chapter information structure
185 /* rockbox: not used
186 MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb);
188 #ifdef __cplusplus
190 #endif
191 #endif