[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11700] branches/soc-2007-hcube/intern/ tinySND/blender: Added functions for mixdown to file feature.
Csaba Hruska
csaba.hruska at gmail.com
Sun Aug 19 17:02:08 CEST 2007
Revision: 11700
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11700
Author: hcube
Date: 2007-08-19 17:02:08 +0200 (Sun, 19 Aug 2007)
Log Message:
-----------
Added functions for mixdown to file feature.
Modified Paths:
--------------
branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp
branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.h
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-19 15:01:06 UTC (rev 11699)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp 2007-08-19 15:02:08 UTC (rev 11700)
@@ -13,6 +13,7 @@
#include "SDLDevice.h"
#include "portaudioDevice.h"
#include "sndfileReader.h"
+#include "sndfileWriter.h"
#include "ffmpegReader.h"
#ifdef WIN32
@@ -34,12 +35,21 @@
std::vector<SND_FXMixer*> mTargets;
};
+enum PlayTarget
+{
+ AUDIODEVICE_TARGET = 0,
+ AUDIOFILE_TARGET = 1
+};
+
+static PlayTarget gPlayTarget = AUDIODEVICE_TARGET;
static int gGlobalFrameCounter = 0;
static std::vector<SND_Sound*> gSounds;
static SND_Device *gDevice = 0;
static SND_DataMultiplexer *gDataMultiplexer = 0;
static SND_FXMixer *gFXMixerLeft = 0;
static SND_FXMixer *gFXMixerRight = 0;
+static SND_DataConsumer *gFileWriter = 0;
+static bool gWasDeviceEnabled = false;
// callback for global frame counter
static void gGlobalFrameCounter_cb( int framesNum, void *userData1, void *userData2 )
@@ -58,6 +68,8 @@
assert( gDevice == 0 );
gGlobalFrameCounter = 0;
+ gFileWriter = 0;
+ gPlayTarget = AUDIODEVICE_TARGET;
gDevice = new SDLDevice();
// gDevice = new portaudioDevice();
@@ -110,6 +122,110 @@
gGlobalFrameCounter = 0;
}
+//file handling
+
+int SND_OpenFileForWrite( char *filename, int sampleRate )
+{
+ gWasDeviceEnabled = gDevice->isEnabled();
+ gDevice->disable();
+
+ gFileWriter = new sndfileWriter( filename );
+
+ gFileWriter->setInput( gDataMultiplexer );
+ // add callback for global frame counter
+ gFileWriter->setCallback( gGlobalFrameCounter_cb );
+
+ //setup parameters
+ gFileWriter->setSampleRate( sampleRate );
+ gFileWriter->setSampleFormat( SND_FORMAT_PCM_16 );
+ gFileWriter->setNumChannels( 2 );
+
+ if( !gFileWriter->initialize() )
+ {
+ delete gFileWriter;
+ gFileWriter = 0;
+
+ if( gWasDeviceEnabled )
+ {
+ gDevice->enable();
+ }
+ else
+ {
+ gDevice->disable();
+ }
+
+ return false;
+ }
+
+ gPlayTarget = AUDIOFILE_TARGET;
+
+ // setup sounds datamultiplexer format
+ gDataMultiplexer->setSampleFormat( gFileWriter->getSampleFormat() );
+
+ // 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_WriteFramesToFile( int framesNum )
+{
+ assert( gFileWriter != 0 );
+ assert( gPlayTarget == AUDIOFILE_TARGET );
+
+ gFileWriter->consumeData( framesNum );
+}
+
+void SND_CloseFile(void)
+{
+ assert( gDevice != 0 );
+ assert( gFileWriter != 0 );
+
+ // 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() );
+
+ gFileWriter->finalize();
+ delete gFileWriter;
+
+ gFileWriter = 0;
+
+ if( gWasDeviceEnabled )
+ {
+ gDevice->enable();
+ }
+ else
+ {
+ gDevice->disable();
+ }
+
+ gPlayTarget = AUDIODEVICE_TARGET;
+}
+
+
// sound handling
// hides various DataProvider backends
@@ -277,7 +393,7 @@
{
assert( soundHandle != 0 );
- if( !gDevice->isEnabled() )
+ if( gPlayTarget == AUDIODEVICE_TARGET && !gDevice->isEnabled() )
{
gDevice->enable();
}
Modified: branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.h
===================================================================
--- branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.h 2007-08-19 15:01:06 UTC (rev 11699)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.h 2007-08-19 15:02:08 UTC (rev 11700)
@@ -31,6 +31,11 @@
extern int SND_GetGlobalFrameCounter(void);
extern void SND_ClearGlobalFrameCounter(void);
+// file handling
+extern int SND_OpenFileForWrite( char *filename, int sampleRate );
+extern void SND_WriteFramesToFile( int framesNum );
+extern void SND_CloseFile(void);
+
// sound handling
extern SND_SoundIHandle SND_NewSound( char *filename ); // hides various DataProvider backends
extern void SND_DeleteSound( SND_SoundIHandle soundHandle );
More information about the Bf-blender-cvs
mailing list