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! :)
This commit is contained in:
Ton Roosendaal 2004-04-21 13:38:54 +00:00
parent 6d9b6ccbbf
commit 9722b25637
4 changed files with 79 additions and 57 deletions

@ -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();
}
}

@ -406,8 +406,10 @@ void start_game(void)
BPY_end_python();
/* sound init is save, only handles once */
sound_init_audio();
sound_stop_all_sounds();
/* Before jumping into Ketsji, we configure some settings. */
space_set_commmandline_options();

@ -65,6 +65,7 @@
#include "DNA_object_types.h"
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_sound_types.h"
#include "BKE_blender.h"
#include "BKE_curve.h"
@ -477,13 +478,23 @@ static void initbuttons(void)
clear_matcopybuf();
}
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 BIF_init(void)
{
initscreen(); /* for (visuele) speed, this first, then setscreen */
initbuttons();
InitCursorData();
sound_init_listener();
init_draw_rects(); /* drawobject.c */
BIF_read_homefile();
init_gl_stuff(); /* drawview.c, after homefile */
@ -538,6 +549,7 @@ void exit_usiblender(void)
free_txt_data();
sound_exit_audio();
MEM_freeN(G.listener);
#ifdef WITH_QUICKTIME
quicktime_exit();

@ -414,6 +414,7 @@ int main(int argc, char **argv)
}
}
printf("before BPY_start_python\n");
BPY_start_python();
/**
@ -421,8 +422,9 @@ int main(int argc, char **argv)
* at least on FreeBSD.
*/
sound_init_audio();
//printf("before init_audio\n");
// sound_init_audio();
printf("before BIF_init\n");
BIF_init();
/**
@ -438,10 +440,12 @@ int main(int argc, char **argv)
}
else {
BPY_start_python();
SYS_WriteCommandLineInt(syshandle,"noaudio",1);
audio = 0;
sound_init_audio();
if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
// (ton) Commented out. I have no idea whats thisfor... will mail around!
// SYS_WriteCommandLineInt(syshandle,"noaudio",1);
// audio = 0;
// sound_init_audio();
// if (G.f & G_DEBUG) printf("setting audio to: %d\n", audio);
}
RE_init_filt_mask();