[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11674] branches/soc-2007-hcube/intern/ tinySND/portaudio: API change, SND_Device inherits SND_DataConsumer.

Csaba Hruska csaba.hruska at gmail.com
Sun Aug 19 12:27:53 CEST 2007


Revision: 11674
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11674
Author:   hcube
Date:     2007-08-19 12:27:52 +0200 (Sun, 19 Aug 2007)

Log Message:
-----------
API change, SND_Device inherits SND_DataConsumer.

Modified Paths:
--------------
    branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.cpp
    branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.h

Modified: branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.cpp
===================================================================
--- branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.cpp	2007-08-19 10:27:41 UTC (rev 11673)
+++ branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.cpp	2007-08-19 10:27:52 UTC (rev 11674)
@@ -9,14 +9,22 @@
 const double SAMPLE_RATE = 44100.0;
 const int FRAMES_PER_BUFFER = 512;
 
+portaudioDevice::portaudioDevice()
+{
+	mInput = 0;
+	// clear callback
+	mCallback = 0;
+	mUserData1 = 0;
+	mUserData2 = 0;
+}
+
+portaudioDevice::~portaudioDevice()
+{
+}
+
 bool portaudioDevice::initialize()
 {
-    // all channel is free
-    for( int i = 0 ; i < 6 ; i++ )
-    {
-        mSounds[ i ] = 0;
-    }
-    
+	
     // Initialize the portaudio library
     try
     {	
@@ -110,88 +118,98 @@
 int portaudioDevice::generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, 
     const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags)
 {
-    float *buffer[6];
     int framesNum = framesPerBuffer; // requested data len per channel
-    int i, j;
     
     assert(outputBuffer != NULL);
 
-    float **out = static_cast<float **>(outputBuffer);
     
-    // processing sound calculations, and getting the final pcm data to buffer
-    for( i = 0 ; i < 6 ; i++ )
-    {
-		if( mSounds[i] != 0 && mSounds[i]->isDataAvailable() )
-		{
-		    buffer[i] = mSounds[i]->getPCMDataPtr( framesNum );
-		}
-	else
+ 	// call callback
+	if( mCallback != 0 )
 	{
-	    buffer[i] = 0;
+		(*mCallback)( framesNum, mUserData1, mUserData2 );
 	}
-    }
-    
-    for( i = 0 ; i < framesNum ; i++ )
+ 
+	if( mInput )
 	{
-		for( j = 0 ; j < 2 ; j++ )
+	 	mInput->fillBuffer( (char*)outputBuffer, framesNum );
+	}
+	else
+	{
+	    float **out = static_cast<float **>(outputBuffer);
+		int channelsNum = getNumChannels();
+		
+	    for( int i = 0 ; i < framesNum ; i++ )
 		{
-		    if( buffer[j] != 0 )
-		    {
-				out[j][i] = buffer[j][0];
-				buffer[j]++;
-		    }
-		    else
-		    {
+			for( int j = 0 ; j < channelsNum ; j++ )
+			{
 				out[j][i] = 0.0;
-		    }
-		}
-    }
-    
+			}
+	    }
+	}
+
     return paContinue;
 }
 
-int portaudioDevice::getNumChannels(void)
+bool portaudioDevice::isEnabled(void)
 {
-    return 2;
+	return mIsEnabled;
 }
 
-char* portaudioDevice::getChannelName( int hwChannelIdx )
+void portaudioDevice::enable(void)
 {
-    // more descriptive name will come soon. ex: left, right, center, etc
-    return "portaudio Audio Channel";
+	mIsEnabled = true;
 }
 
-void portaudioDevice::assignSoundToChannel( int hwChannelIdx, SND_SoundInterface *sound )
+void portaudioDevice::disable(void)
 {
-    if( hwChannelIdx < 0 || hwChannelIdx >=6 )
-    {
-		return;
-    }
-    mSounds[ hwChannelIdx ] = sound;
+	mIsEnabled = false;
 }
 
-bool portaudioDevice::isEnabled(void)
+int portaudioDevice::getAudioBufferSize()
 {
-	return mIsEnabled;
+	// !!!! NOT IMPLEMENTED YET !!!!
+	return 512;
 }
 
-void portaudioDevice::enable(void)
+void portaudioDevice::setAudioBufferSize( int bufferSize )
 {
-	mIsEnabled = true;
+	// !!!! NOT IMPLEMENTED YET !!!!
 }
+	
 
-void portaudioDevice::disable(void)
+float portaudioDevice::getSampleRate(void)
 {
-	mIsEnabled = false;
+	return (float)SAMPLE_RATE;
 }
 
-float portaudioDevice::getSampleRate(void)
+void portaudioDevice::setSampleRate( float sampleRate )
 {
-	return (float)SAMPLE_RATE;
+	// !!!! NOT IMPLEMENTED YET !!!!
 }
 
-int portaudioDevice::getBitRate(void)
+int portaudioDevice::getSampleFormat(void)
 {
-	return 16;
+	return SND_FORMAT_FLOAT;
 }
 
+void portaudioDevice::setSampleFormat( int sampleFormat )
+{
+	// !!!! NOT IMPLEMENTED YET !!!!
+}
+
+int portaudioDevice::getNumChannels(void)
+{
+    return 2;
+}
+
+void portaudioDevice::setNumChannels( int channelsNum )
+{
+	// !!!! NOT IMPLEMENTED YET !!!!
+}
+
+char* portaudioDevice::getChannelName( int hwChannelIdx )
+{
+    // more descriptive name will come soon. ex: left, right, center, etc
+    return "portaudio Audio Channel";
+}
+

Modified: branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.h
===================================================================
--- branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.h	2007-08-19 10:27:41 UTC (rev 11673)
+++ branches/soc-2007-hcube/intern/tinySND/portaudio/portaudioDevice.h	2007-08-19 10:27:52 UTC (rev 11674)
@@ -8,6 +8,9 @@
 {
 public:
     
+			portaudioDevice();
+			~portaudioDevice();
+			
     bool    initialize();
     bool    finalize();
 
@@ -15,18 +18,24 @@
 	void	enable();
 	void	disable();
 
+	int		getAudioBufferSize();
+	void	setAudioBufferSize( int bufferSize );
+	
+    float	getSampleRate();
+	void	setSampleRate( float sampleRate );
+	
+    int		getSampleFormat();
+	void	setSampleFormat( int sampleFormat );
+	
     int     getNumChannels();
+	void	setNumChannels( int channelsNum );
+	
     char*   getChannelName( int hwChannelIdx );
-    void    assignSoundToChannel( int hwChannelIdx, SND_SoundInterface *sound );
 
-    float	getSampleRate();
-    int		getBitRate();
-    
     int generate(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, 
 	const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags);
 
 private:
-    SND_SoundInterface		*mSounds[6];
     portaudio::AutoSystem	*mAutoSys;
     portaudio::MemFunCallbackStream<portaudioDevice>    *mStream;
 	bool					mIsEnabled;





More information about the Bf-blender-cvs mailing list