Restore musepack's IRAM configuration to pre r25127 for non PP5022/24.
[kugel-rb.git] / apps / codecs / libmusepack / mpcdec.h
blobbe18cfec95a59fe24a6fb95311e71e961a6c9b48
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 typedef struct mpc_chap_info_t {
99 mpc_uint64_t sample; /// sample where the chapter starts
100 mpc_uint16_t gain; /// replaygain chapter value
101 mpc_uint16_t peak; /// peak chapter loudness level
102 mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter)
103 char * tag; /// pointer to an APEv2 tag without the preamble
104 } mpc_chap_info;
106 /// Initializes mpc decoder with the supplied stream info parameters.
107 /// \param si streaminfo structure indicating format of source stream
108 /// \return pointer on the initialized decoder structure if successful, 0 if not
109 MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si);
111 /// Releases input mpc decoder
112 MPC_API void mpc_decoder_exit(mpc_decoder *p_dec);
115 * Sets decoder sample scaling factor. All decoded samples will be multiplied
116 * by this factor. Useful for applying replay gain.
117 * @param scale_factor multiplicative scaling factor
119 MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor);
121 MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i);
123 // This is the gain reference used in old replaygain
124 #define MPC_OLD_GAIN_REF 64.82
127 * init demuxer
128 * @param p_reader initialized mpc_reader pointer
129 * @return an initialized mpc_demux pointer
131 MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader);
132 /// free demuxer
133 MPC_API void mpc_demux_exit(mpc_demux * d);
135 * Calls mpc_decoder_scale_output to set the scaling factor according to the
136 * replay gain stream information and the supplied ouput level
137 * @param d pointer to a musepack demuxer
138 * @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
139 * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain
140 * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain
141 * @param clip_prevention MPC_TRUE : uses cliping prevention
143 /* rockbox: not used
144 MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain,
145 mpc_bool_t use_title, mpc_bool_t clip_prevention);
147 /// decode frame
148 MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i);
149 /// get streaminfo
150 MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i);
151 /// seeks to a given sample
152 MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample);
153 /// seeks to a given second
154 MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds);
156 /// \return the current position in the stream (in bits) from the beginning of the file
157 MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d);
159 /// chapters : only for sv8 streams
161 * Gets the number of chapters in the stream
162 * @param d pointer to a musepack demuxer
163 * @return the number of chapters found in the stream
165 /* rockbox: not used
166 MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d);
169 * Gets datas associated to a given chapter
170 * The chapter tag is an APEv2 tag without the preamble
171 * @param d pointer to a musepack demuxer
172 * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1)
173 * @return the chapter information structure
175 /* rockbox: not used
176 MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb);
178 #ifdef __cplusplus
180 #endif
181 #endif