REVISION
Definition in file DECODER__wavfirst.c.
#include "../SYSTEM/sys_hardware.h"
#include "../SYSTEM/sys_assert.h"
#include "../codec/codec.h"
#include "../coder/coder.h"
#include "decoder.h"
Include dependency graph for DECODER__wavfirst.c:

Go to the source code of this file.
Functions | |
| BOOL | DECODER__wavReadHeader (st_DECODER *) |
| Function read wave file header and parse parameters into decoder.status. | |
| BOOL | DECODER__wavfirst (void) |
| Function check to set up WAV decoder input bit stream. | |
|
|
Function check to set up WAV decoder input bit stream.
Definition at line 46 of file DECODER__wavfirst.c. References Audio, st_DECODER::decodeBitstrm, Decoder, DECODER__wav(), DECODER__wavReadHeader(), st_DECODER::flag, st_AUDIO::offset, st_PCM::sampleRate, and st_DECODER::status. 00047 {
00048 USHORT strmLen;
00049 //USHORT * pDst;
00050
00051 // Check WAV header. */
00052 BITSTRM_pack(Decoder.decodeBitstrm);
00053 strmLen = BITSTRM_numDataWords(Decoder.decodeBitstrm);
00054 if(strmLen > sizeof(st_WAVHEADER))
00055 {
00056 if( TRUE == DECODER__wavReadHeader(&Decoder) )
00057 {
00058 PCM_samplerateChanged();
00059 Pcm.sampleRate = Decoder.status.sampleRate;
00060 // Reset bookmark.
00061 if(Audio.offset)
00062 {
00063 Decoder.flag |= DEC_FFWD|DEC_MEDIASEEK;
00064 DECODER__wav();
00065 }
00066 BITSTRM_pack(Decoder.decodeBitstrm);
00067 return TRUE;
00068 }
00069 }
00070 // Return FALSE if header is invalid, coder will keep calling this routine
00071 // until valid header is found or media has been gone through completely.
00072 return FALSE;
00073 }
|
Here is the call graph for this function:

|
|
Function read wave file header and parse parameters into decoder.status.
Definition at line 85 of file DECODER__wavfirst.c. References st_WAVHEADER::chID, st_WAVHEADER::ckSize, Decoder, st_DECODER::firstPacketOffset, st_WAVHEADER::fmt_ckID, st_WAVHEADER::fmt_ckSize, st_WAVHEADER::formatTag, st_WAVHEADER::nAvgBytesPerSec, st_WAVHEADER::nBitsPerSample, st_WAVHEADER::nBlockAlign, st_WAVHEADER::nChannels, st_WAVHEADER::nSamplesPerSec, st_DECODER::status, SYS_assert(), and st_WAVHEADER::wave_ckID. Referenced by DECODER__wavfirst(). 00086 {
00087 char info[4];
00088 unsigned long tempSize;
00089 unsigned int * pD;
00090 unsigned int * pStart;
00091 int numWords;
00092
00093 numWords = BITSTRM_numDataWords(pDecoder->decodeBitstrm);
00094 pD =
00095 pStart = (unsigned int *)BITSTRM_readPtr(pDecoder->decodeBitstrm);
00096
00097 /* Parameter Transform: little-endian to big-endian */
00098 wvHeader.chID[0] = pD[0] >> 8;
00099 wvHeader.chID[1] = pD[0] & 0x0FF;
00100 wvHeader.chID[2] = pD[1] >> 8;
00101 wvHeader.chID[3] = pD[1] & 0x0FF;
00102
00103 wvHeader.ckSize = (pD[3] << 8) | ((pD[3] >> 8) & 0x0FF);
00104 wvHeader.ckSize = (wvHeader.ckSize<<16) | (pD[2] << 8) | ((pD[2] >> 8) & 0x0FF);
00105
00106 wvHeader.wave_ckID[0] = pD[4] >> 8;
00107 wvHeader.wave_ckID[1] = pD[4] & 0x0FF;
00108 wvHeader.wave_ckID[2] = pD[5] >> 8;
00109 wvHeader.wave_ckID[3] = pD[5] & 0x0FF;
00110
00111 wvHeader.fmt_ckID[0] = pD[6] >> 8;
00112 wvHeader.fmt_ckID[1] = pD[6] & 0x0FF;
00113 wvHeader.fmt_ckID[2] = pD[7] >> 8;
00114 wvHeader.fmt_ckID[3] = pD[7] & 0x0FF;
00115
00116 wvHeader.fmt_ckSize = (pD[9] << 8) | ((pD[9] >> 8) & 0x0FF);
00117 wvHeader.fmt_ckSize = (wvHeader.fmt_ckSize<<16) | (pD[8] << 8) | ((pD[8] >> 8) & 0x0FF);
00118
00119 wvHeader.formatTag = (pD[10] << 8) | ((pD[10] >> 8) & 0x0FF);
00120 wvHeader.nChannels = (pD[11] << 8) | ((pD[11] >> 8) & 0x0FF);
00121 wvHeader.nSamplesPerSec = (pD[13] << 8) | ((pD[13] >> 8) & 0x0FF);
00122 wvHeader.nSamplesPerSec = (wvHeader.nSamplesPerSec<<16) | (pD[12] << 8) | ((pD[12] >> 8) & 0x0FF);
00123
00124 wvHeader.nAvgBytesPerSec = (pD[15] << 8) | ((pD[15] >> 8) & 0x0FF);
00125 wvHeader.nAvgBytesPerSec = (wvHeader.nAvgBytesPerSec<<16) | (pD[14] << 8) | ((pD[14] >> 8) & 0x0FF);
00126
00127 wvHeader.nBlockAlign = (pD[16] << 8) | ((pD[16] >> 8) & 0x0FF);
00128 wvHeader.nBitsPerSample = (pD[17] << 8) | ((pD[17] >> 8) & 0x0FF);
00129
00130 /* Check if is a right wav file */
00131 if( (strncmp(wvHeader.chID,"RIFF",4) != 0)||
00132 (strncmp(wvHeader.wave_ckID,"WAVE",4) != 0)||
00133 (strncmp(wvHeader.fmt_ckID,"fmt ",4) != 0)||
00134 (wvHeader.formatTag != 1))
00135 { //return wrong_format;
00136 wavRETURN(numWords, FALSE);
00137 }
00138
00139 // Assuming bitstream is BIG enough to hold the entire WAV header section.
00140
00141 /* Skip rest of fmt header */
00142 //FAT_fseek(wavefile, ((wvHeader.fmt_ckSize-16)/2), SEEK_MID);
00143 pD += (sizeof(st_WAVHEADER)-6 + ((wvHeader.fmt_ckSize-16)/2));
00144
00145 /* There may be additional subchunks in Wave. */
00146 while (1)
00147 {
00148 SYS_assert(pD < pStart+numWords, SYS_DECODER__WAVFIRST);
00149 info[0] = pD[0] >> 8;
00150 info[1] = pD[0] & 0x0FF;
00151 info[2] = pD[1] >> 8;
00152 info[3] = pD[1] & 0x0FF;
00153
00154 if (strncmp(info,"data",4) == 0)
00155 {
00156 /* It's "data" subchunk. Skip following 4 bytes. */
00157 pD += 4;
00158 BITSTRM_remove(pDecoder->decodeBitstrm, pD-pStart);
00159 break;
00160 }
00161 else if (strncmp(info,"fact",4) == 0)
00162 {
00163 /* Some other type of chunk -- skip it */
00164 //FAT_fread(wavefile, &pD[0], 2);
00165 pD += 2;
00166 tempSize = (pD[1] << 8) | ((pD[1] >> 8) & 0x0FF);
00167 tempSize = (tempSize<<16) | (pD[0] << 8) | ((pD[0] >> 8) & 0x0FF);
00168
00169 //FAT_fseek(wavefile, (tempSize/2), SEEK_MID);/* skip rest of header */
00170 pD += 2+(tempSize/2);
00171 }
00172 else
00173 {
00174 wavRETURN(numWords, FALSE); //misc_read_error
00175 }
00176 }
00177
00178 /* Pass parameters to Decoder. */
00179 Decoder.status.numChannels = wvHeader.nChannels;
00180 Decoder.status.sampleRate = wvHeader.nSamplesPerSec;
00181 Decoder.status.bitRate = wvHeader.nAvgBytesPerSec * 8;
00182 Decoder.status.isValid = TRUE;
00183
00184 // Initialize status frameSize, which will then be used
00185 // in DECODER__wav to determine if enough data is
00186 // available in input bitstream.
00187 Decoder.status.frameSize = WAV_PIPE_FRAMELEN*16/wvHeader.nBitsPerSample;
00188 wvFastFwdLen = 5L*Decoder.status.bitRate>>4;
00189 wvAverageWordRate = wvHeader.nAvgBytesPerSec/2;
00190
00191 /*
00192 if(1 == wvHeader.nChannels)
00193 {
00194 //Decoder.status.fastFwdLen >>= 1;
00195 wvFastFwdLen >>= 1;
00196 wvAverageWordRate >>= 1;
00197 }
00198 */
00199 Decoder.firstPacketOffset = pD-pStart;
00200
00201 return TRUE;
00202 }
|
Here is the call graph for this function:

1.3.9.1