[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11775] branches/soc-2007-hcube/source/ blender/src/seqaudio.c: New feature: If animation playback is not synced with audio than audio is synced with blender\ 's frame counter (CFRA)

Csaba Hruska csaba.hruska at gmail.com
Tue Aug 21 20:39:40 CEST 2007


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

Log Message:
-----------
New feature: If animation playback is not synced with audio than audio is synced with blender\'s frame counter (CFRA)

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

Modified: branches/soc-2007-hcube/source/blender/src/seqaudio.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/seqaudio.c	2007-08-21 18:37:58 UTC (rev 11774)
+++ branches/soc-2007-hcube/source/blender/src/seqaudio.c	2007-08-21 18:39:40 UTC (rev 11775)
@@ -29,6 +29,8 @@
 	Handles blender structures: Sequence
 */
 
+#define SEQAUDIO_SYNC_DIFFERNCE		2
+
 typedef enum
 {
 	SEQAUDIO_STOP	= 0,	
@@ -99,12 +101,31 @@
 					if( !audio_sound_isplaying( seq->sound ) )
 					{
 						// start sound
-						float startPos = seq->startofs + CFRA - seq->startdisp;
+						float startPos = CFRA - seq->start;
 						startPos *= ((float)seq->sound->sample->rate) / ((float)G.scene->r.frs_sec);
 						
 						audio_sound_play( seq->sound );
 						audio_sound_setframeposition( seq->sound, (int)startPos );
 					}
+					else
+					{
+						// do sync only if we have to do: AUDIO_SYNC is disabled
+						if( !(G.scene->audio.flag & AUDIO_SYNC) )
+						{
+							// update sound's frame pos if it differs more from CFRA than SEQAUDIO_SYNC_DIFFERNCE
+						
+							float soundToFRA = ((float)G.scene->r.frs_sec) / ((float)seq->sound->sample->rate);
+							int soundPos = (int)((float)audio_sound_getframeposition( seq->sound ) * soundToFRA);
+							
+							if( 	soundPos < CFRA - seq->start - SEQAUDIO_SYNC_DIFFERNCE 
+								||	soundPos > CFRA - seq->start + SEQAUDIO_SYNC_DIFFERNCE + 1
+							)
+							{
+								soundPos = (int)((float)(CFRA - seq->start) / soundToFRA);
+								audio_sound_setframeposition( seq->sound, soundPos );
+							}
+						}
+					}
 				}
 				else
 				{
@@ -259,7 +280,7 @@
 	{
 		CFRA = seqaudio_getframeposition();
 		
-		audio_file_writeframes( 64 );
+		audio_file_writeframes( 128 );
 	}
 
 	seqaudio_stop();





More information about the Bf-blender-cvs mailing list