/* Copyright (c) 2005-2009, The Musepack Development Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the The Musepack Development Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /// \file mpcdec.h /// Top level include file for libmpcdec. #ifndef _MPCDEC_H_ #define _MPCDEC_H_ #ifdef WIN32 #pragma once #endif #include "reader.h" #include "streaminfo.h" #include "config.h" #ifdef __cplusplus extern "C" { #endif #if (CONFIG_CPU == MCF5250) || defined(CPU_S5L870X) /* Enough IRAM but performance suffers with ICODE_ATTR. */ #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR #define ICODE_ATTR_MPC_LARGE_IRAM #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR /* Keep the data arrays of bitsreadr.c in IRAM. */ #define ICONST_ATTR_MPC_BITSREADER ICONST_ATTR #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) /* Enough IRAM to move additional data and code to it. */ #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR /* Not putting the data arrays of bitsreader.c to IRAM allows to move the * sv7/sv8 bitstream demuxing into IRAM. This config is faster. */ #define ICONST_ATTR_MPC_BITSREADER #else /* Not enough IRAM available. */ #define IBSS_ATTR_MPC_LARGE_IRAM #define ICODE_ATTR_MPC_LARGE_IRAM #define ICONST_ATTR_MPC_LARGE_IRAM #define ICONST_ATTR_MPC_BITSREADER #endif enum { MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels) MPC_DECODER_SYNTH_DELAY = 481 }; typedef struct mpc_decoder_t mpc_decoder; typedef struct mpc_demux_t mpc_demux; typedef struct mpc_bits_reader_t { unsigned char * buff; /// pointer on current byte unsigned int count; /// unread bits in current byte mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only } mpc_bits_reader; typedef struct mpc_frame_info_t { mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels) mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT)) mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer. } mpc_frame_info; typedef struct mpc_chap_info_t { mpc_uint64_t sample; /// sample where the chapter starts mpc_uint16_t gain; /// replaygain chapter value mpc_uint16_t peak; /// peak chapter loudness level mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter) char * tag; /// pointer to an APEv2 tag without the preamble } mpc_chap_info; /// Initializes mpc decoder with the supplied stream info parameters. /// \param si streaminfo structure indicating format of source stream /// \return pointer on the initialized decoder structure if successful, 0 if not MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si); /// Releases input mpc decoder MPC_API void mpc_decoder_exit(mpc_decoder *p_dec); /** * Sets decoder sample scaling factor. All decoded samples will be multiplied * by this factor. Useful for applying replay gain. * @param scale_factor multiplicative scaling factor */ MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor); MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i); // This is the gain reference used in old replaygain #define MPC_OLD_GAIN_REF 64.82 /** * init demuxer * @param p_reader initialized mpc_reader pointer * @return an initialized mpc_demux pointer */ MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader); /// free demuxer MPC_API void mpc_demux_exit(mpc_demux * d); /** * Calls mpc_decoder_scale_output to set the scaling factor according to the * replay gain stream information and the supplied ouput level * @param d pointer to a musepack demuxer * @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 * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain * @param clip_prevention MPC_TRUE : uses cliping prevention */ /* rockbox: not used MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, mpc_bool_t use_title, mpc_bool_t clip_prevention); */ /// decode frame MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i); /// get streaminfo MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i); /// seeks to a given sample MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample); /// seeks to a given second MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds); /// \return the current position in the stream (in bits) from the beginning of the file MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d); /// chapters : only for sv8 streams /** * Gets the number of chapters in the stream * @param d pointer to a musepack demuxer * @return the number of chapters found in the stream */ /* rockbox: not used MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d); */ /** * Gets datas associated to a given chapter * The chapter tag is an APEv2 tag without the preamble * @param d pointer to a musepack demuxer * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1) * @return the chapter information structure */ /* rockbox: not used MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb); */ #ifdef __cplusplus } #endif #endif 2'>132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480