[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11772] branches/soc-2007-hcube/intern/ tinySND/blender/SND_C-api.cpp: bugfix: Sound playback was crazy in first few ms.
Csaba Hruska
csaba.hruska at gmail.com
Tue Aug 21 20:35:16 CEST 2007
Revision: 11772
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11772
Author: hcube
Date: 2007-08-21 20:35:16 +0200 (Tue, 21 Aug 2007)
Log Message:
-----------
bugfix: Sound playback was crazy in first few ms. sample rate converter were not restetted.
Modified Paths:
--------------
branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp
Modified: branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp
===================================================================
--- branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp 2007-08-21 18:30:56 UTC (rev 11771)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp 2007-08-21 18:35:16 UTC (rev 11772)
@@ -421,7 +421,7 @@
else
{
// multi channel
- if( i & (long)1 == 0 )
+ if( i % 2 == 0 )
{
sound->mMixerLeft->addSound( fxsrc );
}
@@ -502,11 +502,12 @@
SND_Sound *sound = (SND_Sound*)soundHandle;
- std::vector<SND_FXSample*>::const_iterator i;
+ int channelsNum = sound->mSamples.size();
- for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ for( int i = 0 ; i < channelsNum ; ++i )
{
- (*i)->play();
+ sound->mSamples[ i ]->play();
+ sound->mSRCs[ i ]->reset();
}
}
@@ -530,11 +531,12 @@
SND_Sound *sound = (SND_Sound*)soundHandle;
- std::vector<SND_FXSample*>::const_iterator i;
+ int channelsNum = sound->mSamples.size();
- for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ for( int i = 0 ; i < channelsNum ; ++i )
{
- (*i)->seek( frameNum );
+ sound->mSamples[ i ]->seek( frameNum );
+ sound->mSRCs[ i ]->reset();
}
}
@@ -694,6 +696,7 @@
char *buffer;
int framesDone;
int framesToProcess;
+ int batchSize;
int channelsNum = sound->mSamples.size();
sound->mVisualWaveBuffer = new char[ framesNum * channelsNum ];
@@ -710,6 +713,7 @@
// setup samplerate converters
sound->mSRCs[ i ]->setSampleRate( 4000.0 );
sound->mSRCs[ i ]->setConverterType( SRC_LINEAR );
+ sound->mSRCs[ i ]->reset();
// setup samples
sound->mSamples[ i ]->setMute( false );
@@ -719,15 +723,21 @@
}
// fill the buffer
+ batchSize = (int)((float)SND_MIX_BUFFER_FRAMES / sound->mSamples[ 0 ]->getSampleRate() * 4000.0) - 1;
+ if( batchSize < 1 )
+ {
+ batchSize = 1;
+ }
+
buffer = sound->mVisualWaveBuffer;
framesDone = 0;
while( framesDone < framesNum )
{
- if( framesNum - framesDone > SND_MIX_BUFFER_FRAMES )
+ if( framesNum - framesDone > batchSize )
{
- framesToProcess = SND_MIX_BUFFER_FRAMES;
+ framesToProcess = batchSize;
}
else
{
@@ -738,7 +748,6 @@
framesDone += framesToProcess;
}
-
for( int i = 0 ; i < channelsNum ; ++i )
{
// reset samplerate converters
More information about the Bf-blender-cvs
mailing list