[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11702] branches/soc-2007-hcube/source/ blender: Added functions for mixdpwn to file feature.

Csaba Hruska csaba.hruska at gmail.com
Sun Aug 19 17:04:16 CEST 2007


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

Log Message:
-----------
Added functions for mixdpwn to file feature.

Modified Paths:
--------------
    branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h
    branches/soc-2007-hcube/source/blender/include/BSE_seqaudio.h
    branches/soc-2007-hcube/source/blender/src/buttons_scene.c
    branches/soc-2007-hcube/source/blender/src/seqaudio.c
    branches/soc-2007-hcube/source/blender/src/soundsystem.c

Modified: branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h
===================================================================
--- branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h	2007-08-19 15:02:58 UTC (rev 11701)
+++ branches/soc-2007-hcube/source/blender/include/BAU_soundsystem.h	2007-08-19 15:04:16 UTC (rev 11702)
@@ -10,6 +10,12 @@
 int     audio_getmixrate(void);
 int     audio_getglobalframecounter(void);
 void    audio_clearglobalframecounter(void);
+
+// file functions, used for mixdown
+// playing sound during writing into a file is disabled
+int     audio_file_openforwrite(char *name, int sampleRate);
+void    audio_file_writeframes(int framesNum);
+void    audio_file_close(void);
 	
 // bSample functions
 struct bSample* audio_sample_new(char *name);

Modified: branches/soc-2007-hcube/source/blender/include/BSE_seqaudio.h
===================================================================
--- branches/soc-2007-hcube/source/blender/include/BSE_seqaudio.h	2007-08-19 15:02:58 UTC (rev 11701)
+++ branches/soc-2007-hcube/source/blender/include/BSE_seqaudio.h	2007-08-19 15:04:16 UTC (rev 11702)
@@ -11,7 +11,7 @@
 int  seqaudio_getframeposition(void);
 void seqaudio_setframeposition(int framePos);
 
-void seqaudio_mixdown(void);
+int  seqaudio_mixdown(char *fileName, int sampleRate);
 
 // these functions are implemented in seqaudio.c
 #endif

Modified: branches/soc-2007-hcube/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/buttons_scene.c	2007-08-19 15:02:58 UTC (rev 11701)
+++ branches/soc-2007-hcube/source/blender/src/buttons_scene.c	2007-08-19 15:04:16 UTC (rev 11702)
@@ -58,6 +58,7 @@
 #include "BLI_blenlib.h"
 
 #include "BSE_filesel.h"
+#include "BSE_seqaudio.h"
 
 #include "BIF_gl.h"
 #include "BIF_graphics.h"
@@ -272,7 +273,42 @@
 
 	case B_SOUND_MIXDOWN:
         // by hcube
-		seqaudio_mixdown();
+		{
+			// create filename
+			char fileName[256];
+			char nameBuffer[256];
+			int result;
+	
+			fileName[0] = 0;
+	
+			strcpy( fileName, G.scene->r.pic );
+			BLI_convertstringcode( fileName, G.sce, G.scene->r.cfra );
+
+			BLI_make_existing_file( fileName );
+
+			if( BLI_strcasecmp( fileName + strlen(fileName) - 4, ".wav" ) )
+			{
+				sprintf( nameBuffer, "%04d_%04d.wav", (G.scene->r.sfra) , (G.scene->r.efra) );
+				strcat( fileName, nameBuffer );
+			}
+	
+			seqaudio_stop();
+			
+			waitcursor(1);
+			result = seqaudio_mixdown( fileName, G.scene->audio.mixrate );
+			waitcursor(0);
+			
+			if( !result )
+			{
+				// print error message
+				// !!!! UNIMPLEMNTED YET !!!!
+				printf( "Mixdown error filename[%s] \n", fileName );
+			}
+			else
+			{
+				printf( "Mixdown OK filename[%s] \n", fileName );
+			}
+		}
 		break;
 
 	default: 

Modified: branches/soc-2007-hcube/source/blender/src/seqaudio.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/seqaudio.c	2007-08-19 15:02:58 UTC (rev 11701)
+++ branches/soc-2007-hcube/source/blender/src/seqaudio.c	2007-08-19 15:04:16 UTC (rev 11702)
@@ -198,21 +198,134 @@
 {
 }
 
-void seqaudio_mixdown(void)
+int seqaudio_mixdown(char *fileName, int sampleRate)
 {
-	// !!!! UNIMPLEMNTED YET !!!!
+	int oldCFRA;
 	
-	// disable audio device
-	// setup file writer and sequence
-	// play sequence, and store output in file
-	// finalize file output
-	// enable audio device, if it was enabled 
+	// open file sound target
+	if( !audio_file_openforwrite( fileName, sampleRate ) )
+	{
+		return FALSE;
+	}
+	
+	// process sound
+	oldCFRA = CFRA;
+	CFRA = SFRA;	
+	
+	seqaudio_play();
+
+	while( CFRA < EFRA )
+	{
+		seqaudio_update();
+		CFRA = seqaudio_getframeposition();
+		
+		audio_file_writeframes( 64 );
+	}
+
+	seqaudio_stop();
+	
+	// close file sound target
+	audio_file_close();
+	
+	CFRA = oldCFRA;
+	
+	return TRUE;
 }
 
 ////////////////////////////////////
 // sequencing code OLD
 ////////////////////////////////////
 /*
+void audio_mixdown()
+{
+	int file, c, totlen, totframe, i, oldcfra;
+	char *buf;
+
+	buf = MEM_mallocN(65536, "audio_mixdown");
+	makewavstring(buf);
+
+	file = open(buf, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
+
+	if(file == -1) 
+	{
+		error("Can't open output file");
+		return;
+	}
+	
+	waitcursor(1);
+	
+	printf("Saving: %s ", buf);
+
+	strcpy(buf, "RIFFlengWAVEfmt fmln01ccRATEbsecBP16dataDLEN");
+	totframe = (EFRA - SFRA + 1);
+	totlen = (int) ( ((float)totframe / (float)G.scene->r.frs_sec) * (float)G.scene->audio.mixrate * 4.0);
+	printf(" totlen %d\n", totlen+36+8);
+	
+	totlen+= 36;	// len is filesize-8 in WAV spec, total header is 44 bytes 
+	memcpy(buf+4, &totlen, 4);
+	totlen-= 36;
+	
+	buf[16] = 0x10; buf[17] = buf[18] = buf[19] = 0; buf[20] = 1; buf[21] = 0;
+	buf[22] = 2; buf[23]= 0;
+	memcpy(buf+24, &G.scene->audio.mixrate, 4);
+	i = G.scene->audio.mixrate * 4;
+	memcpy(buf+28, &i, 4);
+	buf[32] = 4; buf[33] = 0; buf[34] = 16; buf[35] = 0;
+	i = totlen;
+	memcpy(buf+40, &i, 4);
+
+	if (G.order == B_ENDIAN) {
+		// swap the four ints to little endian 
+		
+		// length 
+		SWITCH_INT(buf[4]);
+		
+		// audio rate 
+		SWITCH_INT(buf[24]);
+
+		// audio mixrate * 4 
+		SWITCH_INT(buf[28]);
+		
+		// length 
+		SWITCH_INT(buf[40]);
+	}
+	
+	c = write(file, buf, 44);
+	
+	oldcfra = CFRA;
+	audiostream_play(SFRA, 0, 1);
+	
+	i= 0;
+	while ( totlen > 0 ) {
+		totlen -= 64;
+		
+		memset(buf+i, 0, 64);
+		
+		CFRA=(int) ( ((float)(audio_pos-64)/( G.scene->audio.mixrate*4 ))*(float)G.scene->r.frs_sec );
+			
+		audio_fill(buf+i, NULL, 64);
+		if (G.order == B_ENDIAN) {
+			char tbuf[64];
+			memcpy(tbuf, buf+i, 64);
+			swab(tbuf, buf+i, 64);
+		}
+		if (i == (65536-64)) {
+			i=0;
+			write(file, buf, 65536);			
+		} 
+		else i+=64;
+	}
+	write(file, buf, i);
+	
+	waitcursor(0);
+	CFRA = oldcfra;
+	close(file);
+	MEM_freeN(buf);
+
+	return;
+}
+
+
 static int audiostream_play_seq(Sequence * seq, Uint32 startframe)
 {
 	char name[FILE_MAXDIR+FILE_MAXFILE];

Modified: branches/soc-2007-hcube/source/blender/src/soundsystem.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/soundsystem.c	2007-08-19 15:02:58 UTC (rev 11701)
+++ branches/soc-2007-hcube/source/blender/src/soundsystem.c	2007-08-19 15:04:16 UTC (rev 11702)
@@ -110,6 +110,21 @@
 	SND_ClearGlobalFrameCounter();
 }
 
+int audio_file_openforwrite( char *name, int sampleRate )
+{
+	return SND_OpenFileForWrite( name, sampleRate );
+}
+
+void audio_file_writeframes(int framesNum)
+{
+	SND_WriteFramesToFile( framesNum );
+}
+
+void audio_file_close(void)
+{
+	SND_CloseFile();
+}
+
 struct bSample*	audio_sample_new( char *name )
 {
 	bSample *sample = NULL;





More information about the Bf-blender-cvs mailing list