[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11613] branches/soc-2007-hcube/intern/ tinySND/blender/SND_C-api.cpp: Changed the internal implementation of tinySND blender interface.
Csaba Hruska
csaba.hruska at gmail.com
Wed Aug 15 10:33:31 CEST 2007
Revision: 11613
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11613
Author: hcube
Date: 2007-08-15 10:33:31 +0200 (Wed, 15 Aug 2007)
Log Message:
-----------
Changed the internal implementation of tinySND blender interface. Added new data holder class, SND_Sound. Multichannel and Mono channel sounds are also supported now. Also added SND_DeleteSound implementation. SND_CloneSound has been removed.
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-15 08:30:24 UTC (rev 11612)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp 2007-08-15 08:33:31 UTC (rev 11613)
@@ -6,6 +6,7 @@
#include "SND_FXSample.h"
#include "SND_FXMixer.h"
#include "SND_FXSRC.h"
+#include "SND_FXDuplicator.h"
#include "SND_WavProvider.h"
#include "SND_AiffProvider.h"
@@ -18,8 +19,20 @@
#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
#endif //WIN32
-static std::vector<SND_FXSample*> gSamples;
-static std::vector<SND_FXSRC*> gSRCs;
+class SND_Sound
+{
+public:
+
+ SND_DataProvider *mDataProvider;
+ SND_DataCache *mDataCache;
+ SND_FXDuplicator *mDuplicator;
+
+ std::vector<SND_FXSample*> mSamples;
+ std::vector<SND_FXSRC*> mSRCs;
+ std::vector<SND_FXMixer*> mTargets;
+};
+
+static std::vector<SND_Sound*> gSounds;
static SND_Device *gDevice = 0;
static SND_FXMixer *gFXMixerLeft = 0;
static SND_FXMixer *gFXMixerRight = 0;
@@ -37,7 +50,7 @@
// gDevice = new portaudioDevice();
gDevice->initialize();
- gSamples.clear();
+ gSounds.clear();
gFXMixerLeft = new SND_FXMixer();
gFXMixerRight = new SND_FXMixer();
@@ -114,91 +127,199 @@
///////////////////////////////////////////////////////////////////
// DataProvider -> FXSound -> FXSRC -> FXMixer -> devices'channel
///////////////////////////////////////////////////////////////////
+ SND_Sound *sound = new SND_Sound;
SND_FXSample *fxsample;
SND_FXSRC *fxsrc;
- fxsample = new SND_FXSample( dataProvider, 1 );
- fxsrc = new SND_FXSRC();
- fxsrc->setInput( fxsample );
- fxsrc->setSampleRate( gDevice->getSampleRate() );
+ int channelNum = dataProvider->getNumChannels();
- gSRCs.push_back( fxsrc );
- gSamples.push_back( fxsample );
+ //setup SND_Sound
+ sound->mDataProvider = dataProvider;
+ sound->mDataCache = new SND_DataCache( dataProvider );
+ sound->mDuplicator = 0;
+
+ for( int i = 0 ; i < channelNum ; ++i )
+ {
+ fxsample = new SND_FXSample( sound->mDataCache, i );
+ fxsrc = new SND_FXSRC();
+ fxsrc->setInput( fxsample );
+ fxsrc->setSampleRate( gDevice->getSampleRate() );
+
+
+ sound->mSamples.push_back( fxsample );
+ sound->mSRCs.push_back( fxsrc );
- gFXMixerLeft->addSound( fxsrc );
- //gFXMixerRight->addSound( fxsrc );
+ if( channelNum == 1 )
+ {
+ // mono channel
+ SND_FXDuplicator *fxduplicator = new SND_FXDuplicator;
+ fxduplicator->setInput( fxsrc );
+ fxduplicator->setNumCopy( 2 );
+ sound->mDuplicator = fxduplicator;
+
+ // add to left channel
+ gFXMixerLeft->addSound( fxduplicator );
+ sound->mTargets.push_back( gFXMixerLeft );
+
+ // add to right channel
+ gFXMixerRight->addSound( fxduplicator );
+ sound->mTargets.push_back( gFXMixerRight );
+ }
+ else
+ {
+ // multi channel
+ if( i & (long)1 == 0 )
+ {
+ gFXMixerLeft->addSound( fxsrc );
+ sound->mTargets.push_back( gFXMixerLeft );
+ }
+ else
+ {
+ gFXMixerRight->addSound( fxsrc );
+ sound->mTargets.push_back( gFXMixerRight );
+ }
+ }
+ }
- return (SND_SoundIHandle)fxsample;
+ gSounds.push_back( sound );
+
+ return (SND_SoundIHandle)sound;
}
-SND_SoundIHandle SND_CloneSound( SND_SoundIHandle sound )
+void SND_DeleteSound( SND_SoundIHandle soundHandle )
{
- assert( sound != 0 );
+ assert( soundHandle != 0 );
- return (SND_SoundIHandle)0;
-}
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ // remove from sound chain and delete SRCs
+ std::vector<SND_FXMixer*>::const_iterator iFXMixer;
+ iFXMixer = sound->mTargets.begin();
+ for( std::vector<SND_FXSRC*>::iterator i = sound->mSRCs.begin() ; i != sound->mSRCs.end() ; ++i, ++iFXMixer )
+ {
+ (*iFXMixer)->removeSound( (*i) );
+ delete (*i);
+ }
-void SND_DeleteSound( SND_SoundIHandle sound )
-{
- assert( sound != 0 );
+ // delete mSamples
+ for( std::vector<SND_FXSample*>::iterator i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ {
+ delete (*i);
+ }
+
+ if( sound->mDuplicator != 0 )
+ {
+ delete sound->mDuplicator;
+ }
+
+ delete sound->mDataCache;
+ delete sound->mDataProvider;
+ delete sound;
}
-int SND_IsPlayingSound( SND_SoundIHandle sound )
+int SND_IsPlayingSound( SND_SoundIHandle soundHandle )
{
- assert( sound != 0 );
+ assert( soundHandle != 0 );
- SND_FXSample *sample = (SND_FXSample*)sound;
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ bool result = false;
+
+ std::vector<SND_FXSample*>::const_iterator i;
+ for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ {
+ result = result || (*i)->getPlayState() == SND_FXSample::STARTED;
+ }
- return sample->getPlayState() == SND_FXSample::STARTED;
+ return result;
}
-void SND_PlaySound( SND_SoundIHandle sound )
+void SND_PlaySound( SND_SoundIHandle soundHandle )
{
- assert( sound != 0 );
+ assert( soundHandle != 0 );
if( !gDevice->isEnabled() )
{
gDevice->enable();
}
- SND_FXSample *sample = (SND_FXSample*)sound;
- sample->play();
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ std::vector<SND_FXSample*>::const_iterator i;
+
+ for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ {
+ (*i)->play();
+ }
}
-void SND_StopSound( SND_SoundIHandle sound )
+void SND_StopSound( SND_SoundIHandle soundHandle )
{
- assert( sound != 0 );
+ assert( soundHandle != 0 );
- SND_FXSample *sample = (SND_FXSample*)sound;
- sample->stop();
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ std::vector<SND_FXSample*>::const_iterator i;
+
+ for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ {
+ (*i)->stop();
+ }
}
-void SND_SeekSound( SND_SoundIHandle sound, int frameNum )
+void SND_SeekSound( SND_SoundIHandle soundHandle, int frameNum )
{
- assert( sound != 0 );
+ assert( soundHandle != 0 );
- SND_FXSample *sample = (SND_FXSample*)sound;
- sample->seek( frameNum );
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ std::vector<SND_FXSample*>::const_iterator i;
+
+ for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ {
+ (*i)->seek( frameNum );
+ }
}
-void SND_GetSoundInfo( SND_SoundIHandle sound, SND_SoundInfo *sndInfo )
+int SND_GetSoundFramePos( SND_SoundIHandle soundHandle )
{
- assert( sound != 0 );
+ assert( soundHandle != 0 );
+
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ int result = 0;
+
+ std::vector<SND_FXSample*>::const_iterator i;
- SND_FXSample *sample = (SND_FXSample*)sound;
- sndInfo->channelsNum = 1; // UNIMPLEMENTED YET
- sndInfo->framesNum = sample->getNumFrames();
- sndInfo->bitRate = sample->getBitRate();
- sndInfo->frameRate = sample->getSampleRate();
+ for( i = sound->mSamples.begin() ; i != sound->mSamples.end() ; ++i )
+ {
+ result = (*i)->getCurrentFrameNumber();
+ // !!!! refactor !!!!
+ break;
+ }
+
+ return result;
}
+void SND_GetSoundInfo( SND_SoundIHandle soundHandle, SND_SoundInfo *sndInfo )
+{
+ assert( soundHandle != 0 );
+
+ SND_Sound *sound = (SND_Sound*)soundHandle;
+
+ sndInfo->channelsNum = sound->mDataProvider->getNumChannels();
+ sndInfo->framesNum = sound->mDataProvider->getNumFrames();
+ sndInfo->bitRate = sound->mDataProvider->getBitRate();
+ sndInfo->frameRate = sound->mDataProvider->getSampleRate();
+}
+
void SND_StopAllSounds(void)
{
assert( gDevice != 0 );
- std::vector<SND_FXSample*>::const_iterator i;
- for( i = gSamples.begin() ; i != gSamples.end() ; ++i )
+ std::vector<SND_Sound*>::const_iterator i;
+ for( i = gSounds.begin() ; i != gSounds.end() ; ++i )
{
- (*i)->stop();
+ SND_StopSound( (SND_SoundIHandle)(*i) );
}
gDevice->disable();
More information about the Bf-blender-cvs
mailing list