[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11751] branches/soc-2007-hcube: Implemented visual PCM data generation
Csaba Hruska
csaba.hruska at gmail.com
Mon Aug 20 21:26:46 CEST 2007
Revision: 11751
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11751
Author: hcube
Date: 2007-08-20 21:26:46 +0200 (Mon, 20 Aug 2007)
Log Message:
-----------
Implemented visual PCM data generation
Modified Paths:
--------------
branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp
branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.h
branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h
branches/soc-2007-hcube/source/blender/src/soundsystem.c
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 19:25:45 UTC (rev 11750)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.cpp 2007-08-20 19:26:46 UTC (rev 11751)
@@ -58,6 +58,9 @@
static SND_FXMixer *gFXMixerRight = 0;
static SND_DataConsumer *gFileWriter = 0;
+static SND_DataMultiplexer *gVisualDataMultiplexer = 0;
+
+
static SND_CallbackFunction *gCallbackFunction = 0;
static void *gCallbackUserData1 = 0;
static void *gCallbackUserData2 = 0;
@@ -100,6 +103,8 @@
gFXMixerRight = new SND_FXMixer();
gDataMultiplexer->assignSoundToChannel( gFXMixerLeft, 0 );
gDataMultiplexer->assignSoundToChannel( gFXMixerRight, 1 );
+
+ gVisualDataMultiplexer = new SND_DataMultiplexer();
gDevice->setInput( gDataMultiplexer );
// add callback for global frame counter
@@ -114,6 +119,7 @@
gDevice->setCallback( 0 );
gDevice->finalize();
+ delete gVisualDataMultiplexer;
delete gFXMixerLeft;
delete gFXMixerRight;
delete gDataMultiplexer;
@@ -626,7 +632,7 @@
sndInfo->frameRate = sound->mDataProvider->getSampleRate();
}
-char* SND_SoundGetVisualPCMData( SND_SoundIHandle soundHandle, int channelIdx )
+char* SND_SoundGetVisualPCMData( SND_SoundIHandle soundHandle )
{
assert( soundHandle != 0 );
@@ -637,13 +643,70 @@
if( sound->mVisualWaveBuffer == 0 )
{
// 4 KHz = 4000 sample/sec
- int size = (int)(4000.0 * sound->mDataProvider->getDuration());
- sound->mVisualWaveBuffer = new char[ size ];
+ int framesNum = (int)(4000.0 * sound->mDataProvider->getDuration());
+ float sampleRate = gDevice->getSampleRate();
+ char *buffer;
+ int framesDone;
+ int framesToProcess;
+ int channelsNum = sound->mSamples.size();
+
+ sound->mVisualWaveBuffer = new char[ framesNum * channelsNum ];
+
+ // detach from device to avoid of playing
+ gFXMixerLeft->removeSound( sound->mMixerLeft );
+ gFXMixerRight->removeSound( sound->mMixerRight );
+
+ gVisualDataMultiplexer->setNumChannels( channelsNum );
+ gVisualDataMultiplexer->setSampleFormat( SND_FORMAT_PCM_S8 );
+
+ for( int i = 0 ; i < channelsNum ; ++i )
+ {
+ // setup samplerate converters
+ sound->mSRCs[ i ]->setSampleRate( 4000.0 );
+ sound->mSRCs[ i ]->setConverterType( SRC_LINEAR );
+
+ // setup samples
+ sound->mSamples[ i ]->setMute( false );
+ sound->mSamples[ i ]->setGain( 1.0 );
+ sound->mSamples[ i ]->play();
+ gVisualDataMultiplexer->assignSoundToChannel( sound->mSRCs[ i ], i );
+ }
+
+ // fill the buffer
+ buffer = sound->mVisualWaveBuffer;
+ framesDone = 0;
+
+ while( framesDone < framesNum )
+ {
+
+ if( framesNum - framesDone > SND_MIX_BUFFER_FRAMES )
+ {
+ framesToProcess = SND_MIX_BUFFER_FRAMES;
+ }
+ else
+ {
+ framesToProcess = framesNum - framesDone;
+ }
+
+ gVisualDataMultiplexer->fillBuffer( &buffer[ framesDone * channelsNum ], framesToProcess );
+ framesDone += framesToProcess;
+ }
+
+
+ for( int i = 0 ; i < channelsNum ; ++i )
+ {
+ // reset samplerate converters
+ sound->mSRCs[ i ]->setSampleRate( sampleRate );
+ sound->mSRCs[ i ]->setConverterType( SRC_LINEAR );
+
+ // reset samples
+ sound->mSamples[ i ]->stop();
+ }
+
+ gFXMixerLeft->addSound( sound->mMixerLeft );
+ gFXMixerRight->addSound( sound->mMixerRight );
}
- // !!!! UNIMPLEMENTED YET !!!!
- // fill the buffer
-
return sound->mVisualWaveBuffer;
}
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-20 19:25:45 UTC (rev 11750)
+++ branches/soc-2007-hcube/intern/tinySND/blender/SND_C-api.h 2007-08-20 19:26:46 UTC (rev 11751)
@@ -69,7 +69,7 @@
extern void SND_SoundGetInfo( SND_SoundIHandle soundHandle, SND_SoundInfo *sndInfo );
-extern char* SND_SoundGetVisualPCMData( SND_SoundIHandle soundHandle, int channelIdx );
+extern char* SND_SoundGetVisualPCMData( SND_SoundIHandle soundHandle );
extern void SND_SoundStopAll(void);
Modified: branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h
===================================================================
--- branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h 2007-08-20 19:25:45 UTC (rev 11750)
+++ branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h 2007-08-20 19:26:46 UTC (rev 11751)
@@ -31,7 +31,7 @@
void audio_sample_unload(struct bSample *sample);
// pcm data parameters: 4KHz and 8 bit, it is just visual purpuses
-char* audio_sample_getvisualpcmdata(struct bSample *sample, int channelIdx);
+char* audio_sample_getvisualpcmdata(struct bSample *sample);
// bSound functions
// hint: a bSound->sample cant be NULL, always have to be a valid pointer
Modified: branches/soc-2007-hcube/source/blender/src/soundsystem.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/soundsystem.c 2007-08-20 19:25:45 UTC (rev 11750)
+++ branches/soc-2007-hcube/source/blender/src/soundsystem.c 2007-08-20 19:26:46 UTC (rev 11751)
@@ -336,12 +336,12 @@
}
// pcm data parameters: 4000KHz and 4 bit, it is just visual purpuses
-char* audio_sample_getvisualpcmdata( struct bSample *sample, int channelIdx )
+char* audio_sample_getvisualpcmdata( struct bSample *sample )
{
assert( sample != NULL );
assert( sample->snd_sample != NULL );
- return SND_SoundGetVisualPCMData( (SND_SoundIHandle)sample->snd_sample, channelIdx );
+ return SND_SoundGetVisualPCMData( (SND_SoundIHandle)sample->snd_sample );
}
struct bSound* audio_sound_new( char *name )
More information about the Bf-blender-cvs
mailing list