[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11757] branches/soc-2007-hcube/intern/ tinySND/blender/SND_C-api.cpp: Added mixbuffer functions implementation.
Csaba Hruska
csaba.hruska at gmail.com
Mon Aug 20 22:54:06 CEST 2007
Revision: 11757
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11757
Author: hcube
Date: 2007-08-20 22:54:06 +0200 (Mon, 20 Aug 2007)
Log Message:
-----------
Added mixbuffer functions implementation.
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-20 20:53:37 UTC (rev 11756)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp 2007-08-20 20:54:06 UTC (rev 11757)
@@ -58,7 +58,7 @@
static SND_FXMixer *gFXMixerRight = 0;
static SND_DataConsumer *gFileWriter = 0;
-static SND_DataMultiplexer *gVisualDataMultiplexer = 0;
+static SND_DataMultiplexer *gCommonDataMultiplexer = 0;
static SND_CallbackFunction *gCallbackFunction = 0;
@@ -96,6 +96,9 @@
gDataMultiplexer = new SND_DataMultiplexer();
gDataMultiplexer->setNumChannels( gDevice->getNumChannels() );
gDataMultiplexer->setSampleFormat( gDevice->getSampleFormat() );
+
+ // add callback for blender sound system
+ gDataMultiplexer->setCallback( gAudioCallback_cb );
gSounds.clear();
@@ -104,11 +107,9 @@
gDataMultiplexer->assignSoundToChannel( gFXMixerLeft, 0 );
gDataMultiplexer->assignSoundToChannel( gFXMixerRight, 1 );
- gVisualDataMultiplexer = new SND_DataMultiplexer();
+ gCommonDataMultiplexer = new SND_DataMultiplexer();
gDevice->setInput( gDataMultiplexer );
- // add callback for global frame counter
- gDevice->setCallback( gAudioCallback_cb );
gDevice->enable();
}
@@ -116,10 +117,10 @@
{
assert( gDevice != 0 );
- gDevice->setCallback( 0 );
+ gDataMultiplexer->setCallback( 0 );
gDevice->finalize();
- delete gVisualDataMultiplexer;
+ delete gCommonDataMultiplexer;
delete gFXMixerLeft;
delete gFXMixerRight;
delete gDataMultiplexer;
@@ -178,13 +179,14 @@
int SND_FileOpenForWrite( char *filename, int sampleRate )
{
+ assert( gDevice != 0 );
+ assert( gPlayTarget == AUDIODEVICE_TARGET );
+
gDevice->disable();
gFileWriter = new sndfileWriter( filename );
gFileWriter->setInput( gDataMultiplexer );
- // add callback for global frame counter
- gFileWriter->setCallback( gAudioCallback_cb );
//setup parameters
gFileWriter->setSampleRate( sampleRate );
@@ -233,6 +235,7 @@
{
assert( gDevice != 0 );
assert( gFileWriter != 0 );
+ assert( gPlayTarget == AUDIOFILE_TARGET );
// restore sounds samplerates
// restore sounds samplerate method
@@ -263,19 +266,60 @@
// mixbuffer handling
int SND_MixBufferOpen( int sampleRate )
{
- // !!!! UNIMPLEMENTED YET !!!!
+ assert( gDevice != 0 );
+ assert( gPlayTarget == AUDIODEVICE_TARGET );
+
gDevice->disable();
+
gPlayTarget = AUDIOBUFFER_TARGET;
+
+ // setup sounds datamultiplexer format, only signed 16 bit int is supported
+ gDataMultiplexer->setSampleFormat( SND_FORMAT_PCM_16 );
+
+ // setup sounds samplerates
+ // setup sounds a good samplerate method
+ std::vector<SND_Sound*>::const_iterator i;
+ for( i = gSounds.begin() ; i != gSounds.end() ; ++i )
+ {
+ SND_Sound *sound = (*i);
+ for( std::vector<SND_FXSRC*>::iterator j = sound->mSRCs.begin() ; j != sound->mSRCs.end() ; ++j )
+ {
+ (*j)->setConverterType( SRC_SINC_BEST_QUALITY );
+ (*j)->setSampleRate( (float)sampleRate );
+ }
+ }
+
return true;
}
void SND_MixBufferFill( void *buffer, int framesNum )
{
- // !!!! UNIMPLEMENTED YET !!!!
+ assert( gPlayTarget == AUDIOBUFFER_TARGET );
+
+ gDataMultiplexer->fillBuffer( buffer, framesNum );
}
void SND_MixBufferClose(void)
{
- // !!!! UNIMPLEMENTED YET !!!!
+ assert( gDevice != 0 );
+ assert( gPlayTarget == AUDIOBUFFER_TARGET );
+
+ // restore sounds samplerates
+ // restore sounds samplerate method
+ float sampleRate = gDevice->getSampleRate();
+ std::vector<SND_Sound*>::const_iterator i;
+ for( i = gSounds.begin() ; i != gSounds.end() ; ++i )
+ {
+ SND_Sound *sound = (*i);
+ for( std::vector<SND_FXSRC*>::iterator j = sound->mSRCs.begin() ; j != sound->mSRCs.end() ; ++j )
+ {
+ (*j)->setConverterType( SRC_LINEAR );
+ (*j)->setSampleRate( sampleRate );
+ }
+ }
+
+ // restore datamultiplexer format
+ gDataMultiplexer->setSampleFormat( gDevice->getSampleFormat() );
+
gDevice->enable();
gPlayTarget = AUDIODEVICE_TARGET;
}
@@ -656,8 +700,8 @@
gFXMixerLeft->removeSound( sound->mMixerLeft );
gFXMixerRight->removeSound( sound->mMixerRight );
- gVisualDataMultiplexer->setNumChannels( channelsNum );
- gVisualDataMultiplexer->setSampleFormat( SND_FORMAT_PCM_S8 );
+ gCommonDataMultiplexer->setNumChannels( channelsNum );
+ gCommonDataMultiplexer->setSampleFormat( SND_FORMAT_PCM_S8 );
for( int i = 0 ; i < channelsNum ; ++i )
{
@@ -669,7 +713,7 @@
sound->mSamples[ i ]->setMute( false );
sound->mSamples[ i ]->setGain( 1.0 );
sound->mSamples[ i ]->play();
- gVisualDataMultiplexer->assignSoundToChannel( sound->mSRCs[ i ], i );
+ gCommonDataMultiplexer->assignSoundToChannel( sound->mSRCs[ i ], i );
}
// fill the buffer
@@ -688,7 +732,7 @@
framesToProcess = framesNum - framesDone;
}
- gVisualDataMultiplexer->fillBuffer( &buffer[ framesDone * channelsNum ], framesToProcess );
+ gCommonDataMultiplexer->fillBuffer( &buffer[ framesDone * channelsNum ], framesToProcess );
framesDone += framesToProcess;
}
More information about the Bf-blender-cvs
mailing list