sound mixer problem
| Mon, 2007-01-08 07:08 | |
|
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..... |
|






Forum posts: 2009
If it is "how it works", take a debugger and run the code to understand how it behaves.... Two clues:
// has to be done because channels are mixed by adding their values
// to each other
Eric Bustarret
NewLC Founder & CEO / Professional Symbian OS Consultant
Forum posts: 112
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
Forum posts: 57
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
Forum posts: 112