useful for decoding

Committer:
vidigi
Date:
Fri Feb 09 13:45:29 2018 +0000
Revision:
0:43fc447561f2
commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vidigi 0:43fc447561f2 1 /*
vidigi 0:43fc447561f2 2 ******************************************************************************
vidigi 0:43fc447561f2 3 * @file spiritMP3Dec.h
vidigi 0:43fc447561f2 4 * @author MCD Application Team
vidigi 0:43fc447561f2 5 * @brief This file is header for spiritMP3Dec MP3 decoder library.
vidigi 0:43fc447561f2 6 ******************************************************************************
vidigi 0:43fc447561f2 7 * Portions COPYRIGHT 2017 STMicroelectronics
vidigi 0:43fc447561f2 8 * Portions SPIRIT Audio Engine Copyright (c) 1995-2009, SPIRIT
vidigi 0:43fc447561f2 9 *
vidigi 0:43fc447561f2 10 * Redistribution and use in source and binary forms, with or without
vidigi 0:43fc447561f2 11 * modification, are permitted, provided that the following conditions are met:
vidigi 0:43fc447561f2 12 *
vidigi 0:43fc447561f2 13 * 1. Redistribution of source code must retain the above copyright notice,
vidigi 0:43fc447561f2 14 * this list of conditions and the following disclaimer.
vidigi 0:43fc447561f2 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
vidigi 0:43fc447561f2 16 * this list of conditions and the following disclaimer in the documentation
vidigi 0:43fc447561f2 17 * and/or other materials provided with the distribution.
vidigi 0:43fc447561f2 18 * 3. Neither the name of STMicroelectronics nor the names of other
vidigi 0:43fc447561f2 19 * contributors to this software may be used to endorse or promote products
vidigi 0:43fc447561f2 20 * derived from this software without specific written permission.
vidigi 0:43fc447561f2 21 * 4. This software, including modifications and/or derivative works of this
vidigi 0:43fc447561f2 22 * software, must execute solely and exclusively on microcontroller based on
vidigi 0:43fc447561f2 23 * ARM Cortex®-M3 and/or ARM Cortex®-M4 cores or microprocessor devices
vidigi 0:43fc447561f2 24 * manufactured by or for STMicroelectronics.
vidigi 0:43fc447561f2 25 * 5. Redistribution and use of this software other than as permitted under
vidigi 0:43fc447561f2 26 * this license is void and will automatically terminate your rights under
vidigi 0:43fc447561f2 27 * this license.
vidigi 0:43fc447561f2 28 *
vidigi 0:43fc447561f2 29 * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
vidigi 0:43fc447561f2 30 * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
vidigi 0:43fc447561f2 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
vidigi 0:43fc447561f2 32 * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
vidigi 0:43fc447561f2 33 * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
vidigi 0:43fc447561f2 34 * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
vidigi 0:43fc447561f2 35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
vidigi 0:43fc447561f2 36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
vidigi 0:43fc447561f2 37 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
vidigi 0:43fc447561f2 38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
vidigi 0:43fc447561f2 39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
vidigi 0:43fc447561f2 40 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vidigi 0:43fc447561f2 41 *
vidigi 0:43fc447561f2 42 ******************************************************************************
vidigi 0:43fc447561f2 43 */
vidigi 0:43fc447561f2 44
vidigi 0:43fc447561f2 45 #ifndef __SPIRITMP3DEC_H__
vidigi 0:43fc447561f2 46 #define __SPIRITMP3DEC_H__
vidigi 0:43fc447561f2 47
vidigi 0:43fc447561f2 48 #ifdef __cplusplus
vidigi 0:43fc447561f2 49 extern "C" {
vidigi 0:43fc447561f2 50 #endif
vidigi 0:43fc447561f2 51
vidigi 0:43fc447561f2 52
vidigi 0:43fc447561f2 53 /**
vidigi 0:43fc447561f2 54 Informational structure to provide information about MP3 stream.
vidigi 0:43fc447561f2 55 */
vidigi 0:43fc447561f2 56 typedef struct
vidigi 0:43fc447561f2 57 {
vidigi 0:43fc447561f2 58 unsigned int nLayer; /* MPEG Audio Layer (1-3). Zero indicates that structure is not valid */
vidigi 0:43fc447561f2 59 unsigned int nSampleRateHz; /* Sample rate, Hz */
vidigi 0:43fc447561f2 60 unsigned int nBitrateKbps; /* Current bit rate, kilobit per seconds (0 for free-format stream) */
vidigi 0:43fc447561f2 61 unsigned int nChannels; /* Number of channels (1 or 2) */
vidigi 0:43fc447561f2 62 unsigned int IsGoodStream; /* Zero indicates that audio stream is not consistent */
vidigi 0:43fc447561f2 63 unsigned int anCutOffFrq576[2]; /* Cut-off frequencies for both channels (range 0-576), where 576 = Nyquist frequency */
vidigi 0:43fc447561f2 64 unsigned int nBitsReadAfterFrameHeader; /* Number of bits, read after last frame header (for AV sync) */
vidigi 0:43fc447561f2 65 unsigned int nSamplesPerFrame; /* Number of samples per audio frame (for AV sync) */
vidigi 0:43fc447561f2 66 unsigned int nSamplesLeftInFrame; /* Number of samples, remaining in the internal buffer (for AV sync) */
vidigi 0:43fc447561f2 67 } TSpiritMP3Info;
vidigi 0:43fc447561f2 68
vidigi 0:43fc447561f2 69
vidigi 0:43fc447561f2 70 /**
vidigi 0:43fc447561f2 71 MP3 decoder object (persistent RAM).
vidigi 0:43fc447561f2 72 */
vidigi 0:43fc447561f2 73 typedef struct
vidigi 0:43fc447561f2 74 {
vidigi 0:43fc447561f2 75 int hidden[3086]; /* Structure contents is hidden for demo version */
vidigi 0:43fc447561f2 76 } TSpiritMP3Decoder;
vidigi 0:43fc447561f2 77
vidigi 0:43fc447561f2 78
vidigi 0:43fc447561f2 79 /**
vidigi 0:43fc447561f2 80 Callback function type to supply decoder with input data.
vidigi 0:43fc447561f2 81 return number of MAU's read into buffer.
vidigi 0:43fc447561f2 82 */
vidigi 0:43fc447561f2 83 typedef unsigned int (fnSpiritMP3ReadCallback)(
vidigi 0:43fc447561f2 84 void * pMP3CompressedData, /* [OUT] Pointer to buffer to fill with coded MP3 data */
vidigi 0:43fc447561f2 85 unsigned int nMP3DataSizeInChars, /* Buffer size in MAU's */
vidigi 0:43fc447561f2 86 void * token /* Application-supplied token */
vidigi 0:43fc447561f2 87 );
vidigi 0:43fc447561f2 88
vidigi 0:43fc447561f2 89
vidigi 0:43fc447561f2 90 /**
vidigi 0:43fc447561f2 91 * Application-supplied MDCT-domain processing function type.
vidigi 0:43fc447561f2 92 * MDCT coefficients represented as float or int32 type, depending
vidigi 0:43fc447561f2 93 * on build options.
vidigi 0:43fc447561f2 94 * This function can be used for equalizer or pitch-shifter
vidigi 0:43fc447561f2 95 */
vidigi 0:43fc447561f2 96 typedef void (fnSpiritMP3ProcessCallback)(
vidigi 0:43fc447561f2 97 void * mdct_samples, /* [IN/OUT] MDCT coefficients */
vidigi 0:43fc447561f2 98 int isShort, /* Flag: 1 if short frame */
vidigi 0:43fc447561f2 99 int ch, /* Channel number (0 or 1). */
vidigi 0:43fc447561f2 100 void * token /* Application-supplied token */
vidigi 0:43fc447561f2 101 );
vidigi 0:43fc447561f2 102
vidigi 0:43fc447561f2 103 /**
vidigi 0:43fc447561f2 104 * Decoder initialization function
vidigi 0:43fc447561f2 105 */
vidigi 0:43fc447561f2 106 void SpiritMP3DecoderInit(
vidigi 0:43fc447561f2 107 TSpiritMP3Decoder *pDecoder, /* Decoder structure */
vidigi 0:43fc447561f2 108 fnSpiritMP3ReadCallback* pCallbackFn, /* Data reading callback function */
vidigi 0:43fc447561f2 109 fnSpiritMP3ProcessCallback *pProcessFn, /* Data processing callback function */
vidigi 0:43fc447561f2 110 void * token /* Optional parameter for callback function */
vidigi 0:43fc447561f2 111 );
vidigi 0:43fc447561f2 112
vidigi 0:43fc447561f2 113
vidigi 0:43fc447561f2 114 /**
vidigi 0:43fc447561f2 115 Decoding function
vidigi 0:43fc447561f2 116 return number of audio samples decoded.
vidigi 0:43fc447561f2 117 NOTE: function always produce stereo data (1 sample = 32 bit = 2ch*16 bit).
vidigi 0:43fc447561f2 118 */
vidigi 0:43fc447561f2 119 unsigned int SpiritMP3Decode (
vidigi 0:43fc447561f2 120 TSpiritMP3Decoder *pDecoder, /* Decoder structure */
vidigi 0:43fc447561f2 121 short *pPCMSamples, /* [OUT] Output PCM buffer */
vidigi 0:43fc447561f2 122 unsigned int nSamplesRequired, /* Number of samples to decode (1 sample = 32 bit = 2ch*16 bit) */
vidigi 0:43fc447561f2 123 TSpiritMP3Info * pMP3Info /* [OUT, opt] Optional informational structure */
vidigi 0:43fc447561f2 124 );
vidigi 0:43fc447561f2 125
vidigi 0:43fc447561f2 126
vidigi 0:43fc447561f2 127 /**
vidigi 0:43fc447561f2 128 * Return sizeof(TSpiritMP3Decoder)
vidigi 0:43fc447561f2 129 */
vidigi 0:43fc447561f2 130 int SpiritMP3DecoderGetPersistentSize(void);
vidigi 0:43fc447561f2 131
vidigi 0:43fc447561f2 132 #ifdef __cplusplus
vidigi 0:43fc447561f2 133 }
vidigi 0:43fc447561f2 134 #endif
vidigi 0:43fc447561f2 135
vidigi 0:43fc447561f2 136 #endif