📄 audiowrap.c
字号:
/************************************************** * * mp3wrap.c * * CVS ID: $Id: audiowrap.c,v 1.36 2007/01/30 09:38:16 chlapik Exp $ * Author: Raffaele Belardi [RB] - STM) * Date: $Date: 2007/01/30 09:38:16 $ * Revision: $Revision: 1.36 $ * * Description: * * Wrapper functions around the audio library functions. * *************************************************** * * COPYRIGHT (C) ST Microelectronics 2005 * All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: audiowrap.c,v $ * Revision 1.36 2007/01/30 09:38:16 chlapik * fixed bug: * song_number and xid sent from CTR to PLY is not set in CTR task but it is provided by DEC to AB * * Revision 1.35 2006/10/17 09:51:00 trubac * cosmetic, commented prototypes, whitespaces, newlines * * Revision 1.32 2006/09/15 19:39:28 belardi * Merged the m8_cav2_cm80506_cs3563. * - unused variable removed * * ***************************************************/#include <stdio.h>#include <string.h>#include "gendef.h"#include "osal.h"#include "decoder_task.h"#include "audiowrap.h"#include "framebuffer.h"#include "audiobuffer.h"#include "srvmat.h" // for bcd_2_hex#include "controller.h"#include "utility.h"#include "cifreg.h"#include "dmareg.h"#include "osal.h"#include "eicreg.h"#include "decoder_defines.h"extern void dma_ch0_isr_irq(void); // connected to IRQextern eDecoderSampleRate CurrentSampleRateConverterFrequency;/***** OS related stuff *******/extern semaphore_t sem_decoder;extern uint16 decoder_command; // Command bufferextern unsigned char g_FB_readFrom; // from framebuffer.c// amount of bytes to be skipped in fast seek mode//extern int g_decoderFastSeekJumpBytes; // from decoder.cextern t_PlayMode decoderPlayMode;//extern uint32 g_currentFileStartOffset; // from controller.c//uint32 g_currentFileStartOffsetAudioDec = 0; // [RB] unusedstatic sAudioDecoderBitstream *AudioBitstream_p;static sAudioDecoderBitstream AudioDecoderBitstreamStructure = {0, 2352}; //{0,2856};char AudioWaitingMode = 0;FrameBufferElement pBufferElementAudioDec;AudioDecoderStateType AudioDecoderNextState = notInitializedAudioDec;pAudioBufferData AudioBuffer_p_AudioDec;AudioUpdateStatus AudioUpdateBitstream(sAudioDecoderBitstream *Bitstream, int flag){ // chceck whether there was Controller request to stop (NEXT/PREV/STOP/FF/FR) if (decoderStopRequest()) { return immediateEOFAudioDec; } if (AudioWaitingMode) { //continue after wake up AudioWaitingMode = 0; while (Bitstream->dataRequired > Bitstream->dataLength) { //was the previous FBE 'the last' ? if (pBufferElementAudioDec.ElementFlag & FT_LAST) { // if so return EOF { return dataEOFAudioDec; } } if (pBufferElementAudioDec.en == FrameBufferElements) { //we read last element in FB, we want next data //copy dataLength bytes from data+dataOffset position to 0.element memmove(FrameBuffer[1].data - Bitstream->dataLength, Bitstream->data, Bitstream->dataLength); //set read elements as empty SetEmptyFBE(GetElementNumber((unsigned char *)(Bitstream->data)), FrameBufferElements + 1); //update bitstream pointers Bitstream->data = (unsigned char *)(FrameBuffer[1].data - Bitstream->dataLength); pBufferElementAudioDec = FrameBuffer[0]; } if (FrameBufferGetData(&pBufferElementAudioDec, 1) == fbDataReady) { //we have next data Bitstream->dataLength += pBufferElementAudioDec.availableDataLength; if (pBufferElementAudioDec.ElementFlag & FT_FSLAST) pBufferElementAudioDec.ElementFlag = FT_MIDDLE; } else { AudioWaitingMode = 1; { return waitingForDataAudioDec; } } } //end while { return dataReadyAudioDec; } } if (Bitstream->dataOffset + Bitstream->dataRequired <= Bitstream->dataLength) { //we have enough data, update bitstream pointers Bitstream->data += Bitstream->dataOffset; Bitstream->dataLength -= Bitstream->dataOffset; return dataReadyAudioDec; } else { //we don't have enough data //update bitstream pointers Bitstream->data += Bitstream->dataOffset; Bitstream->dataLength -= Bitstream->dataOffset; //Bitstream->dataOffset = 0; //add more data while (Bitstream->dataRequired > Bitstream->dataLength) { //was the previous FBE 'the last' ? if (pBufferElementAudioDec.ElementFlag & FT_LAST) { // if so return EOF return dataEOFAudioDec; } if (pBufferElementAudioDec.en == FrameBufferElements) { //we read last element in FB, we want next data //copy dataLength bytes from data+dataOffset position to 0.element memmove(FrameBuffer[1].data - Bitstream->dataLength, Bitstream->data, Bitstream->dataLength); //set read elements as empty SetEmptyFBE(GetElementNumber((unsigned char *)(Bitstream->data)), FrameBufferElements + 1); //update bitstream pointers Bitstream->data = (unsigned char *)(FrameBuffer[1].data - Bitstream->dataLength); pBufferElementAudioDec = FrameBuffer[0]; } if (FrameBufferGetData(&pBufferElementAudioDec, 1) == fbDataReady) { //we have next data Bitstream->dataLength += pBufferElementAudioDec.availableDataLength; if (pBufferElementAudioDec.ElementFlag & FT_FSLAST) pBufferElementAudioDec.ElementFlag = FT_MIDDLE; } else { //we don't have next data AudioWaitingMode = 1; return waitingForDataAudioDec; } } //end while { return dataReadyAudioDec; } }}void AudioDecodeBlock(uint32 *in_ptr, uint32 *out_ptr){ // Write Header uint32 data; uint32 in_idx; uint32 out_idx; uint32 i;#if 0 // [RB] to get rid of compiler warnings uint32 SubCode_idx; uint32 C2_flags_in_idx; uint32 C2_flags_out_idx; uint32 data_0; uint32 data_1; uint32 data_2; uint32 data_3; C2_FLAGS_UNION C2_flags_0; C2_FLAGS_UNION C2_flags_1; C2_FLAGS_UNION C2_flags_2; uint32 C2FlagsVect[12];#endif uint32 efm_idx; out_idx = 0; in_idx = 0;#if 0 // [RB] to get rid of compiler (2.2) warning C2_flags_in_idx = 2560>>2; //640 C2_flags_out_idx = 1; SubCode_idx = 2368>>2; //592#endif out_ptr[out_idx++] = 0x00200800; // Write Block Header //#if (1 == HAVE_SHOCK_MEMORY) if (ADPCM_OFF == cap_config.adpcm) { out_ptr[out_idx++] = 0x00000800; // Write Block Header }#endif // C2Flags Copying#if 0 // DISABLE : FHA Mar 31 : CANCEL C2Flag handling while(C2_flags_in_idx < 712) //24 { data_0 = in_ptr[C2_flags_in_idx++]; // Read C2 Flag 3 2 1 0 data_1 = in_ptr[C2_flags_in_idx++]; // Read C2 Flag 7 6 5 4 data_2 = in_ptr[C2_flags_in_idx++]; // Read C2 Flag 11 10 9 8 C2_flags_0.all = data_0; C2_flags_1.all = data_1; C2_flags_2.all = data_2; C2FlagsVect[0] = C2_flags_0.field.flags_4n; // C2 Flag 0 C2FlagsVect[1] = C2_flags_0.field.flags_4np1; // C2 Flag 1 C2FlagsVect[2] = C2_flags_0.field.flags_4np2; // C2 Flag 2 C2FlagsVect[3] = C2_flags_0.field.flags_4np3; // C2 Flag 3 C2FlagsVect[4] = C2_flags_1.field.flags_4n; // C2 Flag 4 C2FlagsVect[5] = C2_flags_1.field.flags_4np1; // C2 Flag 5 C2FlagsVect[6] = C2_flags_1.field.flags_4np2; // C2 Flag 6 C2FlagsVect[7] = C2_flags_1.field.flags_4np3; // C2 Flag 7 C2FlagsVect[8] = C2_flags_2.field.flags_4n; // C2 Flag 8 C2FlagsVect[9] = C2_flags_2.field.flags_4np1; // C2 Flag 9 C2FlagsVect[10] = C2_flags_2.field.flags_4np2; // C2 Flag 10 C2FlagsVect[11] = C2_flags_2.field.flags_4np3; // C2 Flag 11 data = C2FlagsVect[0] + (C2FlagsVect[1] << 8) + (C2FlagsVect[2] << 16);// # 2 1 0 data <<= 8; // 3 2 1 # if(C2_flags_in_idx != 643) data |= ((data_3>>16)&0xFF); out_ptr[C2_flags_out_idx] = data; C2_flags_out_idx += 7;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -