[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11774] branches/soc-2007-hcube/source/ blender/src/drawseq.c: Added sequence sound drawing feature implementation.

Csaba Hruska csaba.hruska at gmail.com
Tue Aug 21 20:38:00 CEST 2007


Revision: 11774
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11774
Author:   hcube
Date:     2007-08-21 20:37:58 +0200 (Tue, 21 Aug 2007)

Log Message:
-----------
Added sequence sound drawing feature implementation.

Modified Paths:
--------------
    branches/soc-2007-hcube/source/blender/src/drawseq.c

Modified: branches/soc-2007-hcube/source/blender/src/drawseq.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/drawseq.c	2007-08-21 18:37:00 UTC (rev 11773)
+++ branches/soc-2007-hcube/source/blender/src/drawseq.c	2007-08-21 18:37:58 UTC (rev 11774)
@@ -293,7 +293,7 @@
 	wavesample, /* inner loop storage if the current wave sample value, used to make the 2 values below */
 	wavesamplemin, /* used for finding the min and max wave peaks */
 	wavesamplemax, /* ditto */
-	subsample_step=4; /* when the sample step is 4 every sample of
+	subsample_step=1; /* when the sample step is 4 every sample of
 	the wave is evaluated for min and max values used to draw the wave,
 	however this is slow ehrn zoomed out so when the sample step is above
 	1 (the larger the further out the zoom is) so not evaluate all samples, only some. */
@@ -301,16 +301,17 @@
 	signed char* s;
 	bSound *sound;
 	signed char *stream;
+	int samples;
 	
     // by hcube
-	return;
 	if(seq->sound==NULL) return;
 	
+	samples = ((float)seq->sound->sample->len) / ((float)seq->sound->sample->rate) * 4000.0;
+
 	if (seq->flag & SEQ_MUTE) glColor3ub(0x70, 0x80, 0x80); else glColor3ub(0x70, 0xc0, 0xc0);
 	
-	//audio_getmixrate() ???
-	sofs = ((int)( (((float)(seq->startdisp-seq->start))/(float)G.scene->r.frs_sec)*(float)G.scene->audio.mixrate*4.0 )) & (~3);
-	eofs = ((int)( (((float)(seq->enddisp-seq->start))/(float)G.scene->r.frs_sec)*(float)G.scene->audio.mixrate*4.0 )) & (~3);
+	sofs = ((int)( (((float)(seq->startdisp-seq->start))/(float)G.scene->r.frs_sec)*4000.0 ));
+	eofs = ((int)( (((float)(seq->enddisp-seq->start))/(float)G.scene->r.frs_sec)*4000.0 ));
 	
 	/* clip the drawing area to the screen bounds to save time */
 	sample_step= (G.v2d->cur.xmax - G.v2d->cur.xmin)/winx;
@@ -318,7 +319,7 @@
 	clipxmax= MIN2(x2, G.v2d->cur.xmax);
 	
 	if (sample_step > 1)
-		subsample_step= ((int)(subsample_step*sample_step*8)) & (~3);
+		subsample_step= ((int)(subsample_step*sample_step));
 	
 	/* for speedy access */
 	midy = (y1+y2)/2;
@@ -327,25 +328,26 @@
 	sound_width= x2-x1;
 	sound = seq->sound;
 	
-	// currently the first channel
-	stream = audio_sample_getvisualpcmdata(sound->sample);
+	// !!! TODO: support multi channel sounds
+	// audio_sample_getvisualpcmdata gives multiplexed data
+	// so this code work only for mono channel sounds
+	stream = (signed char*)audio_sample_getvisualpcmdata(sound->sample);
 	
-	wavemulti = (y2-y1)/196605; /*y2-y1 is the height*/
+	wavemulti = (y2-y1)/196605*512; /*y2-y1 is the height*/
 	wavesample=0;
 	
 	/* we need to get the starting offset value, excuse the duplicate code */
 	f=clipxmin;
-	offset= (int) (fsofs + ((f-x1)/sound_width) * feofs_sofs) & (~3);
+	offset= (int) (fsofs + ((f-x1)/sound_width) * feofs_sofs);
 	
 	/* start the loop, draw a line per sample_step -sample_step is about 1 line drawn per pixel */
 	glBegin(GL_LINES);
 	for (f=x1+sample_step; f<=clipxmax; f+=sample_step) {
 		
-		offset_next = (int) (fsofs + ((f-x1)/sound_width) * feofs_sofs) & (~3);
+		offset_next = (int) (fsofs + ((f-x1)/sound_width) * feofs_sofs);
 		if (f > G.v2d->cur.xmin) {
 			/* if this is close to the last sample just exit */
-			// by hcube
-			if (offset_next >= sound->sample->len) break;
+			if (offset_next >= samples) break;
 			
 			wavesamplemin = 131070;
 			wavesamplemax = -131070;
@@ -353,10 +355,9 @@
 			/*find with high and low of the waveform for this draw,
 			evaluate small samples to find this range */
 			while (offset < offset_next) {
-				// by hcube, edit this to enable wave drawing
-				//s = (signed short*)(stream+offset);
+				s = (signed char*)(stream+offset);
 				
-				wavesample = (10*offset)&0xffff;//s[0]*2 + s[1];
+				wavesample = s[0]*2 + s[1];
 				if (wavesamplemin>wavesample)
 					wavesamplemin=wavesample;
 				if (wavesamplemax<wavesample)
@@ -712,7 +713,7 @@
 	draw_shadedstrip(seq, col, x1, y1, x2, y2);
 	
 	/* draw additional info and controls */
-	if (seq->type == SEQ_RAM_SOUND) drawseqwave(seq, x1, y1, x2, y2, sa->winx);
+	if (seq->type == SEQ_RAM_SOUND || seq->type == SEQ_HD_SOUND) drawseqwave(seq, x1, y1, x2, y2, sa->winx);
 	draw_seq_extensions(seq, sseq);
 	draw_seq_handle(seq, sseq, SEQ_LEFTHANDLE);
 	draw_seq_handle(seq, sseq, SEQ_RIGHTHANDLE);





More information about the Bf-blender-cvs mailing list