2 Copyright (c) 2005, The Musepack Development Team
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
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
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.
36 /// Top level include file for libmpcdec.
51 #include "config_types.h"
55 #include "streaminfo.h"
57 #ifndef IBSS_ATTR_MPC_SAMPLE_BUF
58 #define IBSS_ATTR_MPC_SAMPLE_BUF IBSS_ATTR
61 #ifndef IBSS_ATTR_MPC_LARGE_IRAM
62 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250)
63 /* PP5022/24 and MCF5250 have 128KB of IRAM */
64 #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR
66 /* other PP's and MCF5249 have 96KB of IRAM */
67 #define IBSS_ATTR_MPC_LARGE_IRAM
71 #ifndef ICODE_ATTR_MPC_LARGE_IRAM
72 #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024)
73 /* PP5022/24 have 128KB of IRAM and have better performance with ICODE_ATTR */
74 #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR
76 /* all other targets either haven't enough IRAM or performance suffers */
77 #define ICODE_ATTR_MPC_LARGE_IRAM
81 #ifdef ROCKBOX_LITTLE_ENDIAN
82 #define MPC_LITTLE_ENDIAN
86 MPC_FRAME_LENGTH
= (36 * 32), /// samples per mpc frame
87 MPC_DECODER_BUFFER_LENGTH
= 2 * MPC_FRAME_LENGTH
/// required buffer size for decoder
91 #define ERROR_CODE_OK 0
92 #define ERROR_CODE_FILE -1
93 #define ERROR_CODE_SV7BETA 1
94 #define ERROR_CODE_CBR 2
95 #define ERROR_CODE_IS 3
96 #define ERROR_CODE_BLOCKSIZE 4
97 #define ERROR_CODE_INVALIDSV 5
99 /// Initializes a streaminfo structure.
100 /// \param si streaminfo structure to initialize
101 void mpc_streaminfo_init(mpc_streaminfo
*si
);
103 /// Reads streaminfo header from the mpc stream supplied by r.
104 /// \param si streaminfo pointer to which info will be written
105 /// \param r stream reader to supply raw data
106 /// \return error code
107 mpc_int32_t
mpc_streaminfo_read(mpc_streaminfo
*si
, mpc_reader
*r
);
109 /// Gets length of stream si, in seconds.
110 /// \return length of stream in seconds
111 double mpc_streaminfo_get_length(mpc_streaminfo
*si
);
113 /// Returns length of stream si, in samples.
114 /// \return length of stream in samples
115 mpc_int64_t
mpc_streaminfo_get_length_samples(mpc_streaminfo
*si
);
117 /// Sets up decoder library.
118 /// Call this first when preparing to decode an mpc stream.
119 /// \param r reader that will supply raw data to the decoder
120 void mpc_decoder_setup(mpc_decoder
*d
, mpc_reader
*r
);
122 /// Initializes mpc decoder with the supplied stream info parameters.
123 /// Call this next after calling mpc_decoder_setup.
124 /// \param si streaminfo structure indicating format of source stream
125 /// \return TRUE if decoder was initalized successfully, FALSE otherwise
126 mpc_bool_t
mpc_decoder_initialize(mpc_decoder
*d
, mpc_streaminfo
*si
);
128 /// Sets decoder sample scaling factor. All decoded samples will be multiplied
130 /// \param scale_factor multiplicative scaling factor
131 void mpc_decoder_scale_output(mpc_decoder
*d
, double scale_factor
);
133 /// Actually reads data from previously initialized stream. Call
134 /// this iteratively to decode the mpc stream.
135 /// \param buffer destination buffer for decoded samples
136 /// \param vbr_update_acc \todo document me
137 /// \param vbr_update_bits \todo document me
138 /// \return -1 if an error is encountered
139 /// \return 0 if the stream has been completely decoded successfully and there are no more samples
140 /// \return > 0 to indicate the number of bytes that were actually read from the stream.
141 mpc_uint32_t
mpc_decoder_decode(
143 MPC_SAMPLE_FORMAT
*buffer
,
144 mpc_uint32_t
*vbr_update_acc
,
145 mpc_uint32_t
*vbr_update_bits
);
147 mpc_uint32_t
mpc_decoder_decode_frame(
149 mpc_uint32_t
*in_buffer
,
151 MPC_SAMPLE_FORMAT
*out_buffer
);
153 /// Seeks to the specified sample in the source stream.
154 mpc_bool_t
mpc_decoder_seek_sample(mpc_decoder
*d
, mpc_int64_t destsample
);
156 /// Seeks to specified position in seconds in the source stream.
157 mpc_bool_t
mpc_decoder_seek_seconds(mpc_decoder
*d
, double seconds
);
161 #endif // __cplusplus