Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2004-04-21 17:38:54 +0400
committerTon Roosendaal <ton@blender.org>2004-04-21 17:38:54 +0400
commit9722b256377ac47a8f357caafdf37d309f0fb5bd (patch)
tree5ed7bb194a787c7d2634627b334f723c8b1f6061 /source/blender/src/editsound.c
parent6d9b6ccbbfb2cceddc14bef61bfe0067d8131b48 (diff)
Fix for slow starting of Blender.
This was caused by calling sound_init_audio() at startup. In situations where Blender was first started, or when other applications used memory, this could take 5-15 seconds. I have moved the init call to 'start ketsji', and made sure any call to an audio play routine will invoke an init as well. Tested with engine and loading/play sound in F10 menu. I don't know how the BlenderPlayer handles it... should be investigated. Result: At OSX Blender starts in a second again! :)
Diffstat (limited to 'source/blender/src/editsound.c')
-rw-r--r--source/blender/src/editsound.c102
1 files changed, 53 insertions, 49 deletions
diff --git a/source/blender/src/editsound.c b/source/blender/src/editsound.c
index 2e7a2375ce4..95699032e86 100644
--- a/source/blender/src/editsound.c
+++ b/source/blender/src/editsound.c
@@ -83,8 +83,8 @@
/* this might move to the external header */
void* sound_get_libraryinterface(void);
-static SND_SceneHandle ghSoundScene;
-static SND_AudioDeviceInterfaceHandle ghAudioDeviceInterface;
+static SND_SceneHandle ghSoundScene=NULL;
+static SND_AudioDeviceInterfaceHandle ghAudioDeviceInterface=NULL;
/* que? why only here? because of the type define? */
bSound *sound_find_sound(char *id_name);
@@ -181,16 +181,19 @@ void sound_initialize_sounds(void)
{
bSound* sound;
- /* clear the soundscene */
- SND_RemoveAllSounds(ghSoundScene);
- SND_RemoveAllSamples(ghSoundScene);
+ if(ghSoundScene) {
- /* initialize sounds */
- sound = G.main->sound.first;
- while (sound)
- {
- sound_sample_is_null(sound);
- sound = (bSound *) sound->id.next;
+ /* clear the soundscene */
+ SND_RemoveAllSounds(ghSoundScene);
+ SND_RemoveAllSamples(ghSoundScene);
+
+ /* initialize sounds */
+ sound = G.main->sound.first;
+ while (sound)
+ {
+ sound_sample_is_null(sound);
+ sound = (bSound *) sound->id.next;
+ }
}
}
@@ -202,6 +205,8 @@ bSound* sound_make_copy(bSound* originalsound)
char name[160];
int len;
+ if(ghSoundScene==NULL) sound_init_audio();
+
/* only copy sounds that are sounds */
if (originalsound)
{
@@ -248,6 +253,8 @@ bSound* sound_make_copy(bSound* originalsound)
void sound_initialize_sample(bSound* sound)
{
+ if(ghSoundScene==NULL) sound_init_audio();
+
if (sound && sound->sample == NULL)
sound_sample_is_null(sound);
}
@@ -569,6 +576,8 @@ int sound_load_sample(bSound* sound)
int freePF = FALSE;
int buffer = -1;
+ if(ghSoundScene==NULL) sound_init_audio();
+
/* check the sample (valid?) */
if (sound->sample->type == SAMPLE_UNKNOWN || sound->snd_sound == NULL)
{
@@ -653,6 +662,8 @@ bSound* sound_new_sound(char* name)
int len, file;
char str[FILE_MAXDIR+FILE_MAXFILE];
+ if(ghSoundScene==NULL) sound_init_audio();
+
if (!G.scene->audio.mixrate) G.scene->audio.mixrate = 44100;
/* convert the name to absolute path */
strcpy(str, name);
@@ -704,6 +715,9 @@ bSound* sound_new_sound(char* name)
int sound_set_sample(bSound *sound, bSample *sample)
{
int result = TRUE;
+
+ if(ghSoundScene==NULL) sound_init_audio();
+
/* decrease the usernumber for this sample */
if (sound->sample)
sound->sample->id.us--;
@@ -822,6 +836,8 @@ int sound_sample_is_null(bSound* sound)
int result = FALSE;
bSample* sample;
+ if(ghSoundScene==NULL) sound_init_audio();
+
/* find the right sample or else create one */
if (sound->sample == NULL)
{
@@ -844,8 +860,10 @@ int sound_sample_is_null(bSound* sound)
void sound_stop_all_sounds(void)
{
#if GAMEBLENDER == 1
- SND_StopAllSounds(ghSoundScene);
- SND_Proceed(ghAudioDeviceInterface, ghSoundScene);
+ if(ghSoundScene) {
+ SND_StopAllSounds(ghSoundScene);
+ SND_Proceed(ghAudioDeviceInterface, ghSoundScene);
+ }
#endif
}
@@ -854,8 +872,10 @@ void sound_stop_all_sounds(void)
void sound_end_all_sounds(void)
{
#if GAMEBLENDER == 1
- sound_stop_all_sounds();
- SND_RemoveAllSounds(ghSoundScene);
+ if(ghSoundScene) {
+ sound_stop_all_sounds();
+ SND_RemoveAllSounds(ghSoundScene);
+ }
#endif
}
@@ -864,6 +884,8 @@ void sound_end_all_sounds(void)
void sound_play_sound(bSound* sound)
{
#if GAMEBLENDER == 1
+ if(ghSoundScene==NULL) sound_init_audio();
+
/* first check if we want sound or not */
SND_IsPlaybackWanted(ghSoundScene);
@@ -970,55 +992,37 @@ bSound *sound_find_sound(char *id_name)
return sound;
}
-
-
-static void sound_init_listener(void)
-{
- G.listener = MEM_callocN(sizeof(bSoundListener), "soundlistener");
- G.listener->gain = 1.0;
- G.listener->dopplerfactor = 1.0;
- G.listener->dopplervelocity = 1.0;
-}
-
-
-
void sound_init_audio(void)
{
int noaudio;
SYS_SystemHandle hSystem = NULL;
- ghAudioDeviceInterface = NULL;
- hSystem = SYS_GetSystem();
- noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0);
+ if(ghSoundScene==NULL) {
+
+ printf("sound init audio\n");
- if (noaudio)/*(noaudio) intrr: disable game engine audio (openal) */
- SND_SetDeviceType(snd_e_dummydevice);
-
- ghAudioDeviceInterface = SND_GetAudioDevice();
- ghSoundScene = SND_CreateScene(ghAudioDeviceInterface);
-
- sound_init_listener();
+ hSystem = SYS_GetSystem();
+ noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0);
+
+ if (noaudio)/*(noaudio) intrr: disable game engine audio (openal) */
+ SND_SetDeviceType(snd_e_dummydevice);
+
+ ghAudioDeviceInterface = SND_GetAudioDevice();
+ ghSoundScene = SND_CreateScene(ghAudioDeviceInterface);
+ }
}
-
int sound_get_mixrate(void)
{
return MIXRATE;
}
-
-static void sound_exit_listener(void)
-{
- MEM_freeN(G.listener);
-}
-
-
-
void sound_exit_audio(void)
{
- SND_DeleteScene(ghSoundScene);
- SND_ReleaseDevice();
- sound_exit_listener();
+ if(ghSoundScene) {
+ SND_DeleteScene(ghSoundScene);
+ SND_ReleaseDevice();
+ }
}