DECODER__wav.c File Reference


Detailed Description

This module provides WAV decoder handle.

REVISION

Definition in file DECODER__wav.c.

#include "../SYSTEM/sys_hardware.h"
#include "../MESSAGE/message.h"
#include "../codec/codec.h"
#include "../coder/coder.h"
#include "decoder.h"

Include dependency graph for DECODER__wav.c:

Include dependency graph

Go to the source code of this file.

Functions

BOOL DECODER__wav (void)
 Function serves as the wav decoder task handle.
int DECODER__wavdecode (BITSTRM_Obj *in, int *out)
 Function serves as the WAV decoder to convert little-endian audio data into big-endian.


Function Documentation

BOOL DECODER__wav void   ) 
 

Function serves as the wav decoder task handle.

Returns:
FALSE if more data is needed, otherwise TRUE;

Definition at line 50 of file DECODER__wav.c.

References Audio, st_DECODER::decodeBitstrm, Decoder, DECODER__wavdecode(), st_DECODER::firstPacketOffset, st_DECODER::flag, GEN_zeroOut(), st_AUDIO::offset, st_DECODER::pipe, PIPE_writeNext(), st_AUDIO::playtime, SAUDIOTIME_UPDT, and st_DECODER::status.

Referenced by DECODER__wavfirst().

00051 {
00052     unsigned long   tmpUL;
00053     PIPE_Obj *      pipe = &Decoder.pipe;
00054     int             error = DECODE_NO_ERROR;
00055     int             dataLength;
00056     BOOL            ret = TRUE;
00057     
00058     // Try to decode as long as output pipe is open.
00059     while( PIPE_writeFrameNum(pipe) ) 
00060     {   
00061         BITSTRM_pack(Decoder.decodeBitstrm); 
00062         dataLength = BITSTRM_numDataWords(Decoder.decodeBitstrm);               
00063     
00064         // YES. valid data detected, prepare to decode.         
00065         if ( Decoder.flag & (DEC_FFWD|DEC_FRWD|DEC_MEDIASEEK) )
00066         {
00067             BITSTRM_remove(Decoder.decodeBitstrm, dataLength);          
00068             if(Decoder.flag & DEC_MEDIASEEK) 
00069             {
00070                 wvEndOfReadPtr = Audio.offset;
00071                 Decoder.flag &= ~DEC_MEDIASEEK;
00072             }
00073             else
00074             {
00075                 if(Decoder.flag & DEC_FFWD) wvEndOfReadPtr += wvFastFwdLen;
00076                 else if(wvEndOfReadPtr>wvFastFwdLen+Decoder.firstPacketOffset)
00077                     wvEndOfReadPtr -= wvFastFwdLen;
00078                 else
00079                 {   
00080                     // Send silence to get rid of the noise.
00081                     wvSilence = 6L*Decoder.status.bitRate/8000L;
00082                     wvEndOfReadPtr = Decoder.firstPacketOffset;             
00083                 }
00084             }           
00085             wvReadPtr = wvEndOfReadPtr;         
00086             Decoder.flag &= ~(DEC_FFWD|DEC_FRWD);
00087             ret = FALSE;
00088             break;
00089         }
00090         else
00091         {       
00092             if(wvSilence)
00093             {
00094                 GEN_zeroOut((UINT16*)pipe->WrFrame.Frame, WAV_PIPE_FRAMELEN);
00095                 wvSilence--;
00096             }
00097             else
00098             {
00099                 // is there enough data to be decoded?
00100                 if( dataLength < WAV_INPUT_BUFFER_SIZE - READ_THRESHOLD_WAV ) ret = FALSE;
00101                 
00102                 if( dataLength < (Decoder.status.frameSize) )
00103                 {    
00104                     // NO. data not enough yet, bring up media task. 
00105                     return ret;         
00106                 }
00107                 
00108                 // decode the bitstream 
00109                 error = DECODER__wavdecode(Decoder.decodeBitstrm, (Int *)pipe->WrFrame.Frame);
00110             }
00111             
00112             // no error, output the data, prepare for the next write as well. 
00113             if (error == DECODE_NO_ERROR) PIPE_writeNext(pipe);
00114         }
00115     }   
00116     
00117     BITSTRM_pack(Decoder.decodeBitstrm); 
00118     // Check to update time.
00119     tmpUL = 0;
00120     if(wvReadPtr > Decoder.firstPacketOffset)       
00121         tmpUL = (wvReadPtr-Decoder.firstPacketOffset)/wvAverageWordRate;
00122     if ( Audio.playtime != tmpUL )
00123     {
00124         Audio.playtime = tmpUL;
00125         mMSG_send(sysMsgQ, SYS_MSG_ID, SAUDIOTIME_UPDT, DONTCARE, 0);
00126     }       
00127     
00128     return ret; 
00129 }   

Here is the call graph for this function:

int DECODER__wavdecode BITSTRM_Obj *  in,
int *  out
 

Function serves as the WAV decoder to convert little-endian audio data into big-endian.

Parameters:
in Decoder input bitstream.
out Decoder output data.
Returns:
Error code.

Definition at line 143 of file DECODER__wav.c.

References Decoder, st_WAVHEADER::nBitsPerSample, and st_DECODER::status.

Referenced by DECODER__wav().

00144 {
00145     int *pSrc, *pDst, *pDst1;
00146     int nBitsPerSample;
00147     int len;
00148         
00149     pSrc = (int*)BITSTRM_readPtr(in);
00150     pDst = out;
00151     pDst1 = pDst + (WAV_PIPE_FRAMELEN/2);
00152                     
00153     //nBitsPerSample = Decoder.status.bitRate/(Decoder.status.numChannels*Decoder.status.sampleRate);
00154     nBitsPerSample = wvHeader.nBitsPerSample;
00155         
00156     switch(Decoder.status.numChannels)
00157     {
00158         case 1: //Mono
00159             switch(nBitsPerSample)
00160             {
00161                 case 8:
00162                     len = WAV_PIPE_FRAMELEN/4;
00163                     while(len--)
00164                     {
00165                         //  *pDst = (((*pSrc) & 0x0FF00) - 128) >> 1; 
00166                         // Subtracting 8-bit unsigned data from 128 increases noise.                                
00167                         *pDst1 = 
00168                         *pDst = (((*pSrc) & 0x0FF00)) >> 1;
00169                                 
00170                         //  *pDst = ~(*pDst) + 1;   
00171                         //  Converting to 2's complement increases noise.
00172                         pDst++;
00173                         pDst1++;
00174                                 
00175                         //  *pDst = (((*pSrc) & 0x0FF) - 128) << 7;
00176                         *pDst1 = 
00177                         *pDst = (((*pSrc) & 0x0FF) ) << 7;
00178                         //  *pDst = ~(*pDst) + 1;                               
00179                         pDst++;
00180                         pDst1++;
00181                         pSrc++;                         
00182                     }
00183                     //  Advances the read pointer.
00184                     BITSTRM_remove(in, WAV_PIPE_FRAMELEN/4);
00185                     wvReadPtr += WAV_PIPE_FRAMELEN/4;
00186                     break;
00187                     
00188                 case 16:
00189                     len = WAV_PIPE_FRAMELEN/2;
00190                     while(len--)
00191                     {                       
00192                         //*(pDst+(WAV_PIPE_FRAMELEN/2)) = (((*pSrc) & 0x0FF) << 8) | (((*pSrc) & 0x0FF00) >> 8);
00193                         *pDst1 = 
00194                         *pDst = ((*pSrc) << 8) | (((*pSrc) >> 8) & 0x0FF);
00195                                                                 
00196                         pDst++;
00197                         pDst1++;                        
00198                         pSrc++;     
00199                     }
00200                     //  Advances the read pointer.
00201                     BITSTRM_remove(in, WAV_PIPE_FRAMELEN/2);
00202                     wvReadPtr += WAV_PIPE_FRAMELEN/2;
00203                     break;
00204                         
00205                 default:
00206                     break;
00207             }               
00208             break;
00209                 
00210         case 2: //Stereo
00211             switch(nBitsPerSample)
00212             {
00213                 case 8:
00214                     len = WAV_PIPE_FRAMELEN;
00215                     while(len--)
00216                     {
00217                         if( len & 0x01 )    
00218                         {   
00219                             // Lower half Decoder.pipe.WrFrame.Frame stored left channel 
00220                             // samples (even address in Decoder.decodeBitstrm).
00221                             //*pDst = (((*pSrc) & 0x0FF00) >> 8) << 7;
00222                             *pDst = ((*pSrc) & 0x0FF00) >> 1 ;
00223                             //  *pDst = ~(*pDst) + 1;
00224                         }   
00225                         else        
00226                         {
00227                             // Upper half Decoder.pipe.WrFrame.Frame stored right channel 
00228                             // samples (odd address in Decoder.decodeBitstrm).
00229                             *pDst1 = ((*pSrc) & 0x0FF) << 7;
00230                             //  *(pDst+(WAV_PIPE_FRAMELEN/2)) = ~(*(pDst+(WAV_PIPE_FRAMELEN/2))) + 1;
00231                             pDst++;
00232                             pDst1++;                        
00233                             pSrc++;                                 
00234                         }
00235                     }
00236                     //  Advances the read pointer.
00237                     BITSTRM_remove(in, WAV_PIPE_FRAMELEN/2);
00238                     wvReadPtr += WAV_PIPE_FRAMELEN/2;
00239                     break;
00240                     
00241                 case 16:
00242                     // Stereo 16-bit Mode.
00243                     // Read number of WAV_PIPE_FRAMELEN samples from decodeBitstrm.
00244                     // Change data format from little-endian to big-endian.
00245                     len = WAV_PIPE_FRAMELEN;
00246                     while(len--)
00247                     {
00248                         if( len & 0x01 )    
00249                         {   
00250                             // Low-address half Decoder.pipe.WrFrame.Frame stored left channel 
00251                             // samples (even address in Decoder.decodeBitstrm).
00252                              *pDst = ((*pSrc) << 8) | (((*pSrc) >> 8) & 0x0FF);
00253                              pDst++;    
00254                         }   
00255                         else        
00256                         {
00257                             // High-address half Decoder.pipe.WrFrame.Frame stored right channel 
00258                             // samples (odd address in Decoder.decodeBitstrm).
00259                             *pDst1 = ((*pSrc) << 8) | (((*pSrc) >> 8) & 0x0FF);
00260                             pDst1++;                        
00261                         }
00262                         pSrc++;                                     
00263                     }
00264                         
00265                     //  Advances the read pointer.
00266                     BITSTRM_remove(in, WAV_PIPE_FRAMELEN);
00267                     wvReadPtr += WAV_PIPE_FRAMELEN;
00268                     break;
00269                     
00270                 default:
00271                     break;
00272             }
00273             break;
00274                 
00275         default:
00276             break;
00277     }
00278     return DECODE_NO_ERROR;
00279 }


Generated on Wed Jan 19 01:12:54 2005 for neuros-firmware by  doxygen 1.3.9.1