[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10970] branches/soc-2007-hcube: sound. c splitted, sound sequencing skeleton added.
Csaba Hruska
csaba.hruska at gmail.com
Tue Jun 19 16:41:35 CEST 2007
Revision: 10970
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10970
Author: hcube
Date: 2007-06-19 16:41:35 +0200 (Tue, 19 Jun 2007)
Log Message:
-----------
sound.c splitted, sound sequencing skeleton added.
Modified Paths:
--------------
branches/soc-2007-hcube/intern/tinySND/SND_SoundInterface.h
branches/soc-2007-hcube/intern/tinySND/intern/SND_FXSample.cpp
branches/soc-2007-hcube/source/blender/include/BSE_sound.h
Added Paths:
-----------
branches/soc-2007-hcube/source/blender/src/sequence_sound.c
branches/soc-2007-hcube/source/blender/src/soundsystem.c
Removed Paths:
-------------
branches/soc-2007-hcube/source/blender/src/sound.c
Modified: branches/soc-2007-hcube/intern/tinySND/SND_SoundInterface.h
===================================================================
--- branches/soc-2007-hcube/intern/tinySND/SND_SoundInterface.h 2007-06-19 14:21:48 UTC (rev 10969)
+++ branches/soc-2007-hcube/intern/tinySND/SND_SoundInterface.h 2007-06-19 14:41:35 UTC (rev 10970)
@@ -13,6 +13,8 @@
// we can request sound data. do not request big part, only few kilobytes are recommended
virtual float* getPCMDataPtr( int framesNum ) = 0; // incremets frame counter according play state
+
+ // add callback feature
};
Modified: branches/soc-2007-hcube/intern/tinySND/intern/SND_FXSample.cpp
===================================================================
--- branches/soc-2007-hcube/intern/tinySND/intern/SND_FXSample.cpp 2007-06-19 14:21:48 UTC (rev 10969)
+++ branches/soc-2007-hcube/intern/tinySND/intern/SND_FXSample.cpp 2007-06-19 14:41:35 UTC (rev 10970)
@@ -23,7 +23,7 @@
if( frames < size )
{
- size = frames;
+ size = frames;
}
mSourceBufferSize = size;
mSourceBufferPos = 0;
Modified: branches/soc-2007-hcube/source/blender/include/BSE_sound.h
===================================================================
--- branches/soc-2007-hcube/source/blender/include/BSE_sound.h 2007-06-19 14:21:48 UTC (rev 10969)
+++ branches/soc-2007-hcube/source/blender/include/BSE_sound.h 2007-06-19 14:41:35 UTC (rev 10970)
@@ -7,7 +7,10 @@
void sound_finalize(void);
struct bSound* sound_new_sound(char *name);
+
void sound_play_sound(struct bSound *sound);
+void sound_stop_sound(struct bSound *sound);
+
void sound_stop_all_sounds(void);
void sound_play_seq(void);
Added: branches/soc-2007-hcube/source/blender/src/sequence_sound.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/sequence_sound.c (rev 0)
+++ branches/soc-2007-hcube/source/blender/src/sequence_sound.c 2007-06-19 14:41:35 UTC (rev 10970)
@@ -0,0 +1,238 @@
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_ipo_types.h"
+#include "DNA_sequence_types.h"
+#include "DNA_packedFile_types.h"
+
+#include "BKE_utildefines.h"
+#include "BKE_global.h"
+#include "BKE_ipo.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_sound.h"
+#include "BKE_packedFile.h"
+
+#include "BSE_sound.h"
+
+#include "SND_C-api.h"
+
+typedef enum
+{
+ SEQAUDIO_STOP = 0,
+ SEQAUDIO_PLAY = 1
+
+} SeqAudioState;
+
+SeqAudioState gSeqAudioState = SEQAUDIO_STOP;
+
+////////////////////////////////////
+// sequencing code NEW
+////////////////////////////////////
+void sound_play_seq(void)
+{
+ if( !SND_IsInitialized() )
+ {
+ return;
+ }
+ gSeqAudioState = SEQAUDIO_PLAY;
+ sound_update_seq();
+}
+
+void sound_stop_seq(void)
+{
+ if( !SND_IsInitialized() )
+ {
+ return;
+ }
+ gSeqAudioState = SEQAUDIO_STOP;
+ sound_update_seq();
+}
+
+// this will be called before mixing has been done by tinySND
+static void do_sound_update_seq_ipo_cb( void *userData )
+{
+ Sequence *seq = (Sequence*)userData;
+ float facf;
+
+ if( seq->ipo && seq->ipo->curve.first )
+ {
+ do_seq_ipo(seq);
+ facf = seq->facf0;
+ }
+ else
+ {
+ facf = 1.0;
+ }
+ /*
+ cvtbuf = malloc(len);
+ memcpy(cvtbuf, ((Uint8*)sound->stream)+(seq->curpos & (~3)), len);
+ audio_levels(cvtbuf, len, seq->level, facf, seq->pan);
+ if (!mixdown) {
+ SDL_MixAudio(sstream, cvtbuf, len, SDL_MIX_MAXVOLUME);
+ } else {
+ SDL_MixAudio((Uint8*)mixdown, cvtbuf, len, SDL_MIX_MAXVOLUME);
+ }
+ */
+}
+
+static void do_sound_update_seq( Sequence *seq )
+{
+ while( seq )
+ {
+ if( seq->type == SEQ_META )
+ {
+ do_sound_update_seq( seq->seqbase.first );
+ }
+
+ if( (seq->type == SEQ_RAM_SOUND) || (seq->type == SEQ_HD_SOUND) )
+ {
+ /*
+ seq->curpos = (int)( (((float)((float)startframe
+ -(float)seq->start)
+ / (float)G.scene->r.frs_sec)
+ * ((float)G.scene->audio.mixrate)
+ * 4 ));
+ */
+ //only Play/Stop
+ if( gSeqAudioState == SEQAUDIO_STOP )
+ {
+ sound_stop_sound( seq->sound );
+ }
+ else
+ {
+ //if ((seq->curpos<sound->streamlen -len) && (seq->curpos>=0) &&
+ // (seq->startdisp <= CFRA) && ((seq->enddisp) > CFRA))
+ }
+ }
+ seq = seq->next;
+ }
+}
+
+void sound_update_seq(void)
+{
+ Editing *ed;
+
+ assert( gSeqAudioState == SEQAUDIO_STOP || gSeqAudioState == SEQAUDIO_PLAY );
+
+ ed = G.scene->ed;
+ if( !SND_IsInitialized() || !ed )
+ {
+ return;
+ }
+ do_sound_update_seq( ed->seqbasep->first );
+}
+
+////////////////////////////////////
+// sequencing code OLD
+////////////////////////////////////
+/*
+static int audiostream_play_seq(Sequence * seq, Uint32 startframe)
+{
+ char name[FILE_MAXDIR+FILE_MAXFILE];
+ int have_sound = 0;
+
+ while(seq) {
+ if (seq->type == SEQ_META) {
+ if (audiostream_play_seq(
+ seq->seqbase.first, startframe)) {
+ have_sound = 1;
+ }
+ }
+ if ((seq->type == SEQ_RAM_SOUND) && (seq->sound)) {
+ have_sound = 1;
+ seq->curpos = (int)( (((float)((float)startframe
+ -(float)seq->start)
+ / (float)G.scene->r.frs_sec)
+ * ((float)G.scene->audio.mixrate)
+ * 4 ));
+ }
+ if ((seq->type == SEQ_HD_SOUND)) {
+ have_sound = 1;
+ if (!seq->hdaudio) {
+ strncpy(name, seq->strip->dir, FILE_MAXDIR-1);
+ strncat(name, seq->strip->stripdata->name,
+ FILE_MAXFILE-1);
+
+ seq->hdaudio = sound_open_hdaudio(name);
+ }
+ seq->curpos = (int)( (((float)((float)startframe
+ - (float)seq->start)
+ / (float)G.scene->r.frs_sec)
+ * ((float)G.scene->audio.mixrate)
+ * 4 ));
+ }
+ seq= seq->next;
+ }
+ return have_sound;
+}
+
+void audiostream_play(Uint32 startframe, Uint32 duration, int mixdown)
+{
+ static SDL_AudioSpec desired;
+
+ if (!audio_initialised && !(duration + mixdown)) {
+ desired.freq=G.scene->audio.mixrate;
+ desired.format=AUDIO_S16SYS;
+ desired.channels=2;
+ desired.samples=U.mixbufsize;
+ desired.userdata=0;
+ if (audio_init(&desired)==0) {
+ U.mixbufsize = 0; // no audio
+ }
+ }
+
+ audio_pos = ( ((int)( (((float)startframe)
+ /(float)G.scene->r.frs_sec)
+ *(G.scene->audio.mixrate)*4 )) & (~3) );
+
+ audio_scrub = duration;
+ if (!mixdown) {
+ SDL_PauseAudio(0);
+ audio_playing++;
+ }
+}
+
+void audiostream_start(Uint32 frame)
+{
+ audiostream_play(frame, 0, 0);
+}
+
+static void audio_fill_ram_sound(Sequence *seq, void * mixdown,
+ Uint8 * sstream, int len)
+{
+ Uint8* cvtbuf;
+ bSound* sound;
+ float facf;
+
+ sound = seq->sound;
+ audio_makestream(sound);
+ if ((seq->curpos<sound->streamlen -len) && (seq->curpos>=0) &&
+ (seq->startdisp <= CFRA) && ((seq->enddisp) > CFRA))
+ {
+ if(seq->ipo && seq->ipo->curve.first) {
+ do_seq_ipo(seq);
+ facf = seq->facf0;
+ } else {
+ facf = 1.0;
+ }
+ cvtbuf = malloc(len);
+ memcpy(cvtbuf, ((Uint8*)sound->stream)+(seq->curpos & (~3)), len);
+ audio_levels(cvtbuf, len, seq->level, facf, seq->pan);
+ if (!mixdown) {
+ SDL_MixAudio(sstream, cvtbuf, len, SDL_MIX_MAXVOLUME);
+ } else {
+ SDL_MixAudio((Uint8*)mixdown, cvtbuf, len, SDL_MIX_MAXVOLUME);
+ }
+ free(cvtbuf);
+ }
+ seq->curpos += len;
+}
+*/
+
Deleted: branches/soc-2007-hcube/source/blender/src/sound.c
===================================================================
--- branches/soc-2007-hcube/source/blender/src/sound.c 2007-06-19 14:21:48 UTC (rev 10969)
+++ branches/soc-2007-hcube/source/blender/src/sound.c 2007-06-19 14:41:35 UTC (rev 10970)
@@ -1,214 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-
-#include "DNA_scene_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_packedFile_types.h"
-
-#include "BKE_utildefines.h"
-#include "BKE_global.h"
-#include "BKE_library.h"
-#include "BKE_main.h"
-#include "BKE_sound.h"
-#include "BKE_packedFile.h"
-
-#include "BSE_sound.h"
-
-#include "SND_C-api.h"
-
-bSound* sound_new_sound(char *name)
-{
- bSound *sound = NULL;
- SND_SoundIHandle soundHandle;
-// char str[FILE_MAXDIR+FILE_MAXFILE];
-
- // allocate some memory for the sound
- sound = alloc_libblock(&G.main->sound, ID_SO, "sound");
- strcpy(sound->name, name);
-
- soundHandle = SND_NewSound( name );
- if (soundHandle == NULL)
- {
- free_libblock(&G.main->sound, sound);
- sound = NULL;
- }
- else
- {
- sound->volume = 1.0;
- sound->attenuation = 1.0;
- sound->distance = 1.0;
- sound->min_gain = 0.0;
- sound->max_gain = 1.0;
- sound->snd_sound = soundHandle;
- }
-
- return (sound);
-}
-
-void sound_play_sound(struct bSound *sound)
-{
- assert( sound != NULL );
- assert( sound->snd_sound != NULL );
-
- SND_PlaySound( (SND_SoundIHandle)sound->snd_sound );
-}
-
-void sound_stop_all_sounds(void)
-{
- SND_StopAllSounds();
-}
-
-void sound_initialize(void)
-{
- SND_Initialize();
-}
-
-void sound_finalize(void)
-{
- if( SND_IsInitialized() )
- {
- SND_Finalize();
- }
-}
-
-////////////////////////////////////
-// sequencing code NEW
-////////////////////////////////////
-
-void sound_play_seq(void)
-{
-}
-
-void sound_stop_seq(void)
-{
-}
-
-void sound_update_seq(void)
-{
-}
-
-////////////////////////////////////
-// sequencing code OLD
-////////////////////////////////////
-/*
-static int audiostream_play_seq(Sequence * seq, Uint32 startframe)
-{
- char name[FILE_MAXDIR+FILE_MAXFILE];
- int have_sound = 0;
-
- while(seq) {
- if (seq->type == SEQ_META) {
- if (audiostream_play_seq(
- seq->seqbase.first, startframe)) {
- have_sound = 1;
- }
- }
- if ((seq->type == SEQ_RAM_SOUND) && (seq->sound)) {
- have_sound = 1;
- seq->curpos = (int)( (((float)((float)startframe
- -(float)seq->start)
- / (float)G.scene->r.frs_sec)
- * ((float)G.scene->audio.mixrate)
- * 4 ));
- }
- if ((seq->type == SEQ_HD_SOUND)) {
- have_sound = 1;
- if (!seq->hdaudio) {
- strncpy(name, seq->strip->dir, FILE_MAXDIR-1);
- strncat(name, seq->strip->stripdata->name,
- FILE_MAXFILE-1);
-
- seq->hdaudio = sound_open_hdaudio(name);
- }
- seq->curpos = (int)( (((float)((float)startframe
- - (float)seq->start)
- / (float)G.scene->r.frs_sec)
- * ((float)G.scene->audio.mixrate)
- * 4 ));
- }
- seq= seq->next;
- }
- return have_sound;
-}
-
-void audiostream_play(Uint32 startframe, Uint32 duration, int mixdown)
-{
- static SDL_AudioSpec desired;
- Editing *ed;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list