CODEC_playHdl.c File Reference


Detailed Description

This module provide Codec PCM handles for normal playback and myfi.

REVISION

Definition in file CODEC_playHdl.c.

#include "../SYSTEM/sys_hardware.h"
#include "../SYSTEM/sys_hiddenfeature.h"
#include "codec.h"
#include "codec_assert.h"
#include "../AUDIO/audio.h"
#include "../FMXMIT/xmit_inc.h"

Include dependency graph for CODEC_playHdl.c:

Include dependency graph

Go to the source code of this file.

Functions

void CODEC_playPcmPut (int *pcmBuf, int len)
 Function serves as the normal playback PCM data put handle.
void CODEC_myfiPcmPut (int *pcmBuf, int len)
 Function serves as the MyFi playback PCM data put handle.
void CODEC_linkitPcmPut (int *pcmBuf, int len)
 Function serves as the linkIt mode PCM data put handle.
void CODEC_linkitPcmGet (int *pcmBuf, int len)
 Function serves as the linkIt mode PCM data get handle.


Function Documentation

void CODEC_linkitPcmGet int *  pcmBuf,
int  len
 

Function serves as the linkIt mode PCM data get handle.

Parameters:
pcmBuf PCM data buffer.
len Available PCM data length in words.

Definition at line 367 of file CODEC_playHdl.c.

Referenced by AUDIO_start().

00368 {
00369     leftChannel  = pcmBuf;
00370     rightChannel = pcmBuf + len/2;
00371 }

void CODEC_linkitPcmPut int *  pcmBuf,
int  len
 

Function serves as the linkIt mode PCM data put handle.

Parameters:
pcmBuf PCM data buffer.
len Pending PCM data length in words.

Definition at line 305 of file CODEC_playHdl.c.

Referenced by AUDIO_start().

00306 {
00307     int i;
00308     
00309     /*if(SYS_HF_myfiTest())
00310     {
00311         st_AUDIO_OSCILLATOR LeftTestTone;
00312         st_AUDIO_OSCILLATOR RightTestTone;
00313         
00314         // set up oscillators for the test tones
00315         // 500 Hz, 95% full-scale sine wave (to prevent clipping due to
00316         // rounding)
00317         LeftTestTone.Coeff =
00318         RightTestTone.Coeff = 32753;
00319         LeftTestTone.Tap1 =
00320         RightTestTone.Tap1 = 887;
00321         LeftTestTone.Tap2 =
00322         RightTestTone.Tap2 = 0;
00323 
00324         LeftTestTone.pOutput = leftChannel;
00325         RightTestTone.pOutput = rightChannel;
00326         AUDIO_toneGen(&LeftTestTone);
00327         AUDIO_toneGen(&RightTestTone);
00328     }*/
00329         
00330     StereoMod.pSum = leftChannel;
00331     StereoMod.pDiff = rightChannel;
00332     StereoMod.OutputLeft = (int *)pcmBuf;
00333     StereoMod.OutputRight = (int *)pcmBuf + 64;
00334     
00335     //if(SYS_HF_myfiTest())
00336     {
00337         FIRPremphasisLeft.pOutput = leftChannel;
00338         FIRPremphasisRight.pOutput = rightChannel;
00339     }
00340     
00341     for (i = 0; i < PCM_CHANNEL_BUFLEN; i++)
00342     {
00343         //XMIT_Energy(&EnergyInputLeft);
00344         //XMIT_Energy(&EnergyInputRight);
00345 
00346         CarrierGen(&Carrier);
00347         
00348         //if(SYS_HF_myfiTest())
00349         {
00350             XMIT_preemphasisFIR(&FIRPremphasisLeft);
00351             XMIT_preemphasisFIR(&FIRPremphasisRight);
00352         }
00353             
00354         XMIT_Modulator(&StereoMod);
00355     }
00356 }

void CODEC_myfiPcmPut int *  pcmBuf,
int  len
 

Function serves as the MyFi playback PCM data put handle.

Parameters:
pcmBuf PCM data buffer.
len Pending PCM data length in words.

Definition at line 144 of file CODEC_playHdl.c.

References st_PCM::decode, st_PCM::flag, GEN_zeroOut(), and st_PCM::sampleRate.

Referenced by AUDIO_start().

00145 {
00146     int     i;
00147     int *   pData;
00148     int *   pDstLeft;
00149     int *   pDstRight;
00150 
00151     if (XMIT_CompressBuffer( &EncoderBuffer ))
00152     // if the input buffer has less than the required number of samples
00153     // and the output buffer has less than 64 samples ready to go, we need
00154     // to decode more MP3 and perform SRC on it.
00155     // For the input buffer, there are always 11 extra samples left over
00156     // from the previous frame for the taps of the FIR filter.
00157     {
00158         pDstLeft = EncoderBuffer.pSumInput;
00159         pDstRight = EncoderBuffer.pDiffInput;               
00160         
00161         /* Setup sample rate conversion output buffer. */
00162         SRC_setOutput(&LeftSRC, pDstLeft);
00163         SRC_setOutput(&RightSRC, pDstRight);       
00164 
00165         /* check for a change in sample rate and reset SRC if needed */
00166         if (Pcm.flag&SAMPLE_RATE_CHANGED) 
00167         {
00168             /* set sample rate */
00169             SRC_setInputRate(&LeftSRC, Pcm.sampleRate);
00170             SRC_setInputRate(&RightSRC, Pcm.sampleRate);
00171             PCM_samplerateNotChanged();
00172         }
00173         
00174         /* loop over sample rate converter until output buffers are filled */
00175         while (SRC_isOutputBufferFull(&LeftSRC) == 0) 
00176         {
00177             /* get another input block if needed */
00178             if (SRC_isInputBufferEmpty(&LeftSRC)) 
00179             {
00180                 pData = Pcm.decode();
00181     
00182                 if( NULL == pData)
00183                 {
00184                     // Decoder data is not ready, 
00185                     // Zero sending out.
00186                     GEN_zeroOut((UINT16*)pcmBuf, len);
00187                     return;
00188                 }
00189                 else
00190                 {
00191                     SRC_setInput(&LeftSRC, pData);
00192                     SRC_setInput(&RightSRC, pData + SRC_inputBufferSize());
00193                 }
00194             }
00195     
00196             /* run the left and right channels */
00197             SRC_apply(&LeftSRC);
00198             SRC_apply(&RightSRC);
00199         }
00200         
00201         EncoderBuffer.Samples += PCM_CHANNEL_BUFLEN;                    
00202     }
00203 
00204     // by the time we get here, we should have at least 26 samples (+11 previous samples)
00205     // available in the input buffers.
00206     DifSRCData.Input = EncoderBuffer.pDiffOutput;
00207     SumSRCData.Input = EncoderBuffer.pSumOutput;
00208     DifSRCData.Output = SRCBuffer.pDiffInput;
00209     SumSRCData.Output = SRCBuffer.pSumInput;
00210 
00211     while (SRCBuffer.Samples < PCM_CHANNEL_BUFLEN)
00212     /* If there are not enough samples after the SRC, then
00213      * we need to run the SRC until there are enough samples */
00214     {
00215         /* SRC Automatically updates the input and output pointers. */
00216         XMIT_SRC(&SumSRCData);
00217         XMIT_SRC(&DifSRCData);
00218         SRCBuffer.Samples += XMIT_OUTPUT;
00219         EncoderBuffer.Samples -= XMIT_SAMPLES;
00220     }
00221 
00222     /* Update pointers */           
00223     EncoderBuffer.pDiffOutput = DifSRCData.Input;
00224     EncoderBuffer.pSumOutput = SumSRCData.Input;
00225     SRCBuffer.pDiffInput = DifSRCData.Output;
00226     SRCBuffer.pSumInput = SumSRCData.Output;
00227     /* Now, enough up-sampled data is in the SRC Output buffers.
00228     * we can not process the data and put it in the output buffer.
00229     * Then, we need to compress the SRC Output Buffers. */
00230     EnergyInputLeft.pInput =  StereoMod.pSum = SRCBuffer.pSumOutput;
00231     EnergyInputRight.pInput = StereoMod.pDiff = SRCBuffer.pDiffOutput;
00232             
00233     SRCBuffer.pSumOutput += PCM_CHANNEL_BUFLEN;         
00234     SRCBuffer.pDiffOutput += PCM_CHANNEL_BUFLEN;
00235     SRCBuffer.Samples -= PCM_CHANNEL_BUFLEN;
00236 
00237     pDstLeft = pcmBuf;
00238     pDstRight = pcmBuf + len/2;
00239 
00240     //' Now, let's take this data and put it into the EncoderBuffers
00241     //' Apply all filters (15kHz and pre-emphasis here)
00242     //' Also apply all summing of the left and right channels
00243     //' and the difference of the left and right channels.
00244     StereoMod.OutputRight = pDstRight;
00245     StereoMod.OutputLeft = pDstLeft;
00246     
00247     #ifdef MIXER_SUPPORT
00248     {
00249         int     ii,
00250                *pL,
00251                *pR;
00252                        
00253         pL = StereoMod.pDiff;
00254         pR = StereoMod.pSum;
00255         for (ii = 0; ii < PCM_CHANNEL_BUFLEN; ii++)
00256         {
00257             *pL = (*pL+*leftChannel)/2;
00258             *pR = (*pR+*rightChannel)/2;
00259             pL++;
00260             pR++;
00261             leftChannel++;
00262             rightChannel++;
00263         }
00264     }
00265     #endif
00266 
00267 
00268     for (i = 0; i < PCM_CHANNEL_BUFLEN; i++)
00269     {
00270         // Not enought mips for this.
00271         //XMIT_Energy(&EnergyInputLeft);
00272         //XMIT_Energy(&EnergyInputRight);
00273         #if 0   // 11/13/02
00274             FIRPremphasisLeftTaps[0] = *pSrcLeft;
00275             FIRPremphasisRightTaps[0] = *pSrcRight;
00276             *pSrcLeft++ = XMIT_PreemphasisFIR(&FIRPremphasisLeft);
00277             *pSrcRight++ = XMIT_PreemphasisFIR(&FIRPremphasisRight);
00278         #endif
00279 
00280         CarrierGen(&Carrier);
00281         //XMIT_SumDiff(&StereoMod);
00282         XMIT_Modulator(&StereoMod);
00283     }
00284                 
00285     XMIT_CompressBuffer(&SRCBuffer);
00286                 
00287     /*remove the EQ apply for MIPs limit*/
00288     /* Let's apply EQ here. */
00289     /*
00290     EQ_apply(&LeftEQ, pDstLeft, pDstLeft);
00291     EQ_apply(&RightEQ, pDstRight, pDstRight);
00292     */
00293 }

Here is the call graph for this function:

void CODEC_playPcmPut int *  pcmBuf,
int  len
 

Function serves as the normal playback PCM data put handle.

Parameters:
pcmBuf PCM data buffer.
len Pending PCM data length in words.

Definition at line 50 of file CODEC_playHdl.c.

References AUDIO_speedIsOutputBufferFull(), st_PCM::decode, st_PCM::flag, GEN_zeroOut(), and st_PCM::sampleRate.

Referenced by AUDIO_start().

00051 {
00052     int * pData;
00053     int * pRight = pcmBuf+len/2;
00054 
00055     #ifdef DJ_SUPPORT
00056     // loop over speed control.
00057     while(1)
00058     #endif
00059     {   
00060         #ifdef DJ_SUPPORT
00061         if(AUDIO_speedIsOutputBufferFull()) break;
00062         #endif
00063 
00064         /* Setup sample rate conversion output buffer. */
00065         // This could be opted out in the future, to have PCM put to a buffer at fixed 
00066         // position.
00067         SRC_setOutput(&LeftSRC, pcmBuf);                
00068         SRC_setOutput(&RightSRC, pRight);       
00069     
00070         /* check for a change in sample rate and reset SRC if needed */
00071         if (Pcm.flag&SAMPLE_RATE_CHANGED) 
00072         {
00073             /* set sample rate */
00074             SRC_setInputRate(&LeftSRC, Pcm.sampleRate);
00075             SRC_setInputRate(&RightSRC, Pcm.sampleRate);
00076             PCM_samplerateNotChanged();
00077         }
00078             
00079         /* loop over sample rate converter until output buffers are filled */
00080         while (SRC_isOutputBufferFull(&LeftSRC) == 0) 
00081         {
00082             /* get another input block if needed */
00083             if (SRC_isInputBufferEmpty(&LeftSRC)) 
00084             {
00085                 pData = Pcm.decode();
00086                 
00087                 if( NULL == pData)
00088                 {
00089                     // Decoder data is not ready, 
00090                     // Zero sending out.
00091                     GEN_zeroOut((UINT16*)pcmBuf, len);
00092                     return;
00093                 }
00094                 else
00095                 {
00096                     SRC_setInput(&LeftSRC, pData);
00097                     SRC_setInput(&RightSRC, pData + SRC_inputBufferSize());
00098                 }
00099             }
00100     
00101             /* run the left and right channels */
00102             SRC_apply(&LeftSRC);
00103             SRC_apply(&RightSRC);
00104         }
00105         
00106         #ifdef DJ_SUPPORT
00107         if(AUDIO_speedFIR(pcmBuf, pRight)) break;
00108         #endif
00109 
00110     }
00111     
00112     #ifdef DJ_SUPPORT
00113     AUDIO_speedGetSample(pcmBuf, pRight);
00114     #endif
00115     
00116     EQ_apply(&LeftEQ,  pcmBuf,  pcmBuf);
00117     EQ_apply(&RightEQ, pRight,  pRight);
00118     
00119     #ifdef MIXER_SUPPORT
00120     {
00121         unsigned short ii;
00122         for (ii = 0; ii < PCM_CHANNEL_BUFLEN; ii++)
00123         {
00124             *pcmBuf = (*pcmBuf+*leftChannel)/2;
00125             *pRight = (*pRight+*rightChannel)/2;
00126             pcmBuf++;
00127             pRight++;
00128             leftChannel++;
00129             rightChannel++;
00130         }
00131     }
00132     #endif
00133 }

Here is the call graph for this function:


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