Use more IRAM for musepack on S5L870X CPUs.
[kugel-rb.git] / apps / codecs / libmusepack / mpcdec.h
blob97c0f39acbe3ae9bd425685f89e92ad747533291
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 #ifndef IBSS_ATTR_MPC_LARGE_IRAM
51 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250) || defined(CPU_S5L870X)
52 /* PP5022/24 and MCF5250 have 128KB of IRAM */
53 #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
54 #else
55 /* other PP's and MCF5249 have 96KB of IRAM */
56 #define IBSS_ATTR_MPC_LARGE_IRAM
57 #endif
58 #endif
60 #ifndef ICODE_ATTR_MPC_LARGE_IRAM
61 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
62 /* PP5022/24 have 128KB of IRAM and have better performance with ICODE_ATTR */
63 #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR
64 #else
65 /* all other targets either haven't enough IRAM or performance suffers */
66 #define ICODE_ATTR_MPC_LARGE_IRAM
67 #endif
68 #endif
70 #ifndef ICONST_ATTR_MPC_LARGE_IRAM
71 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250) || defined(CPU_S5L870X)
72 /* PP5022/24 and MCF5250 have 128KB of IRAM */
73 #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR
74 #else
75 /* other PP's and MCF5249 have 96KB of IRAM */
76 #define ICONST_ATTR_MPC_LARGE_IRAM
77 #endif
78 #endif
80 enum {
81 MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame
82 MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels)
83 MPC_DECODER_SYNTH_DELAY = 481
86 typedef struct mpc_decoder_t mpc_decoder;
87 typedef struct mpc_demux_t mpc_demux;
89 typedef struct mpc_bits_reader_t {
90 unsigned char * buff; /// pointer on current byte
91 unsigned int count; /// unread bits in current byte
92 mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only
93 mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only
94 } mpc_bits_reader;
96 typedef struct mpc_frame_info_t {
97 mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels)
98 mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream
99 MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT))
100 mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer.
101 } mpc_frame_info;
103 typedef struct mpc_chap_info_t {
104 mpc_uint64_t sample; /// sample where the chapter starts
105 mpc_uint16_t gain; /// replaygain chapter value
106 mpc_uint16_t peak; /// peak chapter loudness level
107 mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter)
108 char * tag; /// pointer to an APEv2 tag without the preamble
109 } mpc_chap_info;
111 /// Initializes mpc decoder with the supplied stream info parameters.
112 /// \param si streaminfo structure indicating format of source stream
113 /// \return pointer on the initialized decoder structure if successful, 0 if not
114 MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si);
116 /// Releases input mpc decoder
117 MPC_API void mpc_decoder_exit(mpc_decoder *p_dec);
120 * Sets decoder sample scaling factor. All decoded samples will be multiplied
121 * by this factor. Useful for applying replay gain.
122 * @param scale_factor multiplicative scaling factor
124 MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor);
126 MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i);
128 // This is the gain reference used in old replaygain
129 #define MPC_OLD_GAIN_REF 64.82
132 * init demuxer
133 * @param p_reader initialized mpc_reader pointer
134 * @return an initialized mpc_demux pointer
136 MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader);
137 /// free demuxer
138 MPC_API void mpc_demux_exit(mpc_demux * d);
140 * Calls mpc_decoder_scale_output to set the scaling factor according to the
141 * replay gain stream information and the supplied ouput level
142 * @param d pointer to a musepack demuxer
143 * @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
144 * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain
145 * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain
146 * @param clip_prevention MPC_TRUE : uses cliping prevention
148 /* rockbox: not used
149 MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain,
150 mpc_bool_t use_title, mpc_bool_t clip_prevention);
152 /// decode frame
153 MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i);
154 /// get streaminfo
155 MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i);
156 /// seeks to a given sample
157 MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample);
158 /// seeks to a given second
159 MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds);
161 /// \return the current position in the stream (in bits) from the beginning of the file
162 MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d);
164 /// chapters : only for sv8 streams
166 * Gets the number of chapters in the stream
167 * @param d pointer to a musepack demuxer
168 * @return the number of chapters found in the stream
170 /* rockbox: not used
171 MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d);
174 * Gets datas associated to a given chapter
175 * The chapter tag is an APEv2 tag without the preamble
176 * @param d pointer to a musepack demuxer
177 * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1)
178 * @return the chapter information structure
180 /* rockbox: not used
181 MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb);
183 #ifdef __cplusplus
185 #endif
186 #endif