sound mixer problem

Login to reply to this topic.
Mon, 2007-01-08 07:08
Joined: 2005-01-22
Forum posts: 112
how , sound mixer example is mixing the buffer......

the code is...


void CMixerThread::FillBufferL()
  {
  // wait for access to shared data
  iShared.iMutex.Wait();

  TInt volume = iShared.iMainVolume;

  // Gather new sample information
  TInt i;
  for( i=0; i<KMaxChannels; i++ )
    {
    if( iShared.iPlayStarted[ i ] )
      {
      iShared.iPlayStarted[ i ] = EFalse;
      TSample& s = iShared.iSample[ i ];

      iAudioData[ i ] = s.iData;
      iAudioPos[ i ] = 0;
      iAudioEnd[ i ] = s.iLength << KAudioShift;
      iRepStart[ i ] = s.iRepStart << KAudioShift;
      iRepEnd[ i ] = s.iRepEnd << KAudioShift;
      }
    }
  // give access to shared data
  iShared.iMutex.Signal();

  // clear buffer
  // has to be done because channels are mixed by adding their values
  // to each other
  Mem::FillZ( iMixBuffer, KBufferSize*4 );

  // mix active channels
  for( i=0; i<KMaxChannels; i++ )
    {
    if( iAudioData[ i ] != NULL )
      {
      TInt* buf = iMixBuffer;
      TInt* bufEnd = buf + KBufferSize;

      TInt16* src = iAudioData[ i ];

      TInt pos = iAudioPos[ i ];
      TInt posEnd = iAudioEnd[ i ];
      TInt repStart = iRepStart[ i ];
      TInt repEnd = iRepEnd[ i ];
      TInt posAdd = ( iShared.iFrequency[ i ] << KAudioShift ) / KSampleRate;
      TInt volume = iShared.iVolume[ i ];

      while( buf < bufEnd )
        {
        TInt sample = ( src[ pos >> KAudioShift ] * volume );
        pos += posAdd;
        if( pos >= posEnd )
          {
          if( repEnd == 0 )
            {
            iAudioData[ i ] = NULL;
            break;
            }
          else
            {
            pos = repStart;
            posEnd = repEnd;
            }
          }
        *buf++ += sample;
        }
      iAudioPos[ i ] = pos;
      iAudioEnd[ i ] = posEnd;
      }
    }

  // convert 32-bit mixing buffer to 16-bit output buffer
  TInt* buf = iMixBuffer;
 
  TInt* bufEnd = buf + KBufferSize;
  TInt16* buf2 = iBuffer;
  while( buf < bufEnd )
    {
    // 32-bit mixer buffer contents are multiplied by main volume
    // shifts are in two phases to prevent overflow and maintain quality
    TInt value = ( ( *buf++ >> 8 ) * volume ) >> 8;

    // Prevent sound from trashing on overboost volume:
    if( value < -0x7fff ) value = -0x7fff;
    if( value > 0x7fff ) value = 0x7fff;

    // and write to buffer
    *buf2++ = (TInt16)value;
    }


pls if anyone know then pls explain

with regards
jai.....



Mon, 2007-01-08 11:08
NewLC AdministratorSymbian AccreditedForum Nokia Champion
Joined: 2003-01-14
Forum posts: 2009
Re: sound mixer problem
What is your question ?

If it is "how it works", take a debugger and run the code to understand how it behaves.... Two clues:

Code:
  // clear buffer
  // has to be done because channels are mixed by adding their values
  // to each other

Code:
*buf++ += sample;

Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant

Wed, 2007-01-10 10:58
Joined: 2005-01-22
Forum posts: 112
Re: sound mixer problem
thanks eric for ur reply

i m reading one one byte of  two sound file nd mixing one by one byte ,then finally i get mix file but it(mix) s not play.
but individual file r playing properly
why
Thu, 2007-01-11 05:14
Joined: 2005-01-24
Forum posts: 57
Re: sound mixer problem
hi ,
 u said that one file plays

does it mean tht if u supply only one file to the mixer(the above code ) it  plays or the file plays in another program?
 chk the values before writting into the buffer if all are zero or all are same values no sound will be heard...
hope this helps

if the values written into the buffer are non zero and not are not same  pls revert to me back
regs
saju

"I dont know with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."
.... Albert Einstein

Thu, 2007-01-11 07:25
Joined: 2005-01-22
Forum posts: 112
Re: sound mixer problem
hi saju i want to mix two wav sound file .. but how ,i hv been read the sound mixer example but i cant understand the code, means ,how, it is mixing the code.
  • Login to reply to this topic.