Refacturate IRAM configuration for musepack codec. No functional change.
[kugel-rb.git] / apps / codecs / libmusepack / mpcdec.h
blobf97a6458d45fbf2ac20595c8893cdf19041e955d
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
56 #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
57 /* Enough IRAM to move additional data and code to it. */
58 #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
59 #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR
60 #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR
62 #else
63 /* Not enough IRAM available. */
64 #define IBSS_ATTR_MPC_LARGE_IRAM
65 #define ICODE_ATTR_MPC_LARGE_IRAM
66 #define ICONST_ATTR_MPC_LARGE_IRAM
67 #endif
69 enum {
70 MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame
71 MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels)
72 MPC_DECODER_SYNTH_DELAY = 481
75 typedef struct mpc_decoder_t mpc_decoder;
76 typedef struct mpc_demux_t mpc_demux;
78 typedef struct mpc_bits_reader_t {
79 unsigned char * buff; /// pointer on current byte
80 unsigned int count; /// unread bits in current byte
81 mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only
82 mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only
83 } mpc_bits_reader;
85 typedef struct mpc_frame_info_t {
86 mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels)
87 mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream
88 MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT))
89 mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer.
90 } mpc_frame_info;
92 typedef struct mpc_chap_info_t {
93 mpc_uint64_t sample; /// sample where the chapter starts
94 mpc_uint16_t gain; /// replaygain chapter value
95 mpc_uint16_t peak; /// peak chapter loudness level
96 mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter)
97 char * tag; /// pointer to an APEv2 tag without the preamble
98 } mpc_chap_info;
100 /// Initializes mpc decoder with the supplied stream info parameters.
101 /// \param si streaminfo structure indicating format of source stream
102 /// \return pointer on the initialized decoder structure if successful, 0 if not
103 MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si);
105 /// Releases input mpc decoder
106 MPC_API void mpc_decoder_exit(mpc_decoder *p_dec);
109 * Sets decoder sample scaling factor. All decoded samples will be multiplied
110 * by this factor. Useful for applying replay gain.
111 * @param scale_factor multiplicative scaling factor
113 MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor);
115 MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i);
117 // This is the gain reference used in old replaygain
118 #define MPC_OLD_GAIN_REF 64.82
121 * init demuxer
122 * @param p_reader initialized mpc_reader pointer
123 * @return an initialized mpc_demux pointer
125 MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader);
126 /// free demuxer
127 MPC_API void mpc_demux_exit(mpc_demux * d);
129 * Calls mpc_decoder_scale_output to set the scaling factor according to the
130 * replay gain stream information and the supplied ouput level
131 * @param d pointer to a musepack demuxer
132 * @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
133 * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain
134 * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain
135 * @param clip_prevention MPC_TRUE : uses cliping prevention
137 /* rockbox: not used
138 MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain,
139 mpc_bool_t use_title, mpc_bool_t clip_prevention);
141 /// decode frame
142 MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i);
143 /// get streaminfo
144 MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i);
145 /// seeks to a given sample
146 MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample);
147 /// seeks to a given second
148 MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds);
150 /// \return the current position in the stream (in bits) from the beginning of the file
151 MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d);
153 /// chapters : only for sv8 streams
155 * Gets the number of chapters in the stream
156 * @param d pointer to a musepack demuxer
157 * @return the number of chapters found in the stream
159 /* rockbox: not used
160 MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d);
163 * Gets datas associated to a given chapter
164 * The chapter tag is an APEv2 tag without the preamble
165 * @param d pointer to a musepack demuxer
166 * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1)
167 * @return the chapter information structure
169 /* rockbox: not used
170 MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb);
172 #ifdef __cplusplus
174 #endif
175 #endif