2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
|
* sound.c (mar-2001 nzc)
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
2002-10-12 11:37:38 +00:00
|
|
|
* $Id$
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2005-10-09 16:57:49 +00:00
|
|
|
#include <stdlib.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
|
2010-02-08 23:07:53 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2010-02-07 23:41:17 +00:00
|
|
|
#include "DNA_sequence_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_packedFile_types.h"
|
2009-08-09 21:16:39 +00:00
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
|
|
#include "AUD_C-API.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_sound.h"
|
2009-08-09 21:16:39 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_library.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_packedFile.h"
|
2010-02-07 23:41:17 +00:00
|
|
|
#include "BKE_fcurve.h"
|
2010-02-10 09:30:22 +00:00
|
|
|
#include "BKE_animsys.h"
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-01-30 21:04:51 +00:00
|
|
|
static int force_device = -1;
|
2009-12-07 20:39:57 +00:00
|
|
|
|
2010-03-08 20:08:04 +00:00
|
|
|
#ifdef WITH_JACK
|
2010-02-21 18:01:41 +00:00
|
|
|
static void sound_sync_callback(void* data, int mode, float time)
|
|
|
|
|
{
|
2010-02-21 19:54:18 +00:00
|
|
|
struct Main* bmain = (struct Main*)data;
|
2010-02-21 18:01:41 +00:00
|
|
|
struct Scene* scene;
|
|
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
scene = bmain->scene.first;
|
2010-02-21 18:01:41 +00:00
|
|
|
while(scene)
|
|
|
|
|
{
|
|
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
{
|
|
|
|
|
if(mode)
|
|
|
|
|
sound_play_scene(scene);
|
|
|
|
|
else
|
|
|
|
|
sound_stop_scene(scene);
|
|
|
|
|
AUD_seek(scene->sound_scene_handle, time);
|
|
|
|
|
}
|
|
|
|
|
scene = scene->id.next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-08 20:08:04 +00:00
|
|
|
#endif
|
2010-02-21 18:01:41 +00:00
|
|
|
|
2010-01-31 18:32:19 +00:00
|
|
|
int sound_define_from_str(char *str)
|
|
|
|
|
{
|
|
|
|
|
if (BLI_strcaseeq(str, "NULL"))
|
|
|
|
|
return AUD_NULL_DEVICE;
|
|
|
|
|
if (BLI_strcaseeq(str, "SDL"))
|
|
|
|
|
return AUD_SDL_DEVICE;
|
|
|
|
|
if (BLI_strcaseeq(str, "OPENAL"))
|
|
|
|
|
return AUD_OPENAL_DEVICE;
|
|
|
|
|
if (BLI_strcaseeq(str, "JACK"))
|
|
|
|
|
return AUD_JACK_DEVICE;
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-30 21:04:51 +00:00
|
|
|
void sound_force_device(int device)
|
2009-12-07 20:39:57 +00:00
|
|
|
{
|
2010-01-30 21:04:51 +00:00
|
|
|
force_device = device;
|
2009-12-07 20:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
2010-04-24 16:35:16 +00:00
|
|
|
void sound_init_once()
|
|
|
|
|
{
|
|
|
|
|
AUD_initOnce();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
void sound_init(struct Main *bmain)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-01-01 05:09:30 +00:00
|
|
|
AUD_DeviceSpecs specs;
|
2009-08-26 08:09:29 +00:00
|
|
|
int device, buffersize;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
|
device = U.audiodevice;
|
|
|
|
|
buffersize = U.mixbufsize;
|
|
|
|
|
specs.channels = U.audiochannels;
|
|
|
|
|
specs.format = U.audioformat;
|
|
|
|
|
specs.rate = U.audiorate;
|
|
|
|
|
|
2010-01-30 21:04:51 +00:00
|
|
|
if(force_device >= 0)
|
|
|
|
|
device = force_device;
|
2009-12-07 20:39:57 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
if(buffersize < 128)
|
|
|
|
|
buffersize = AUD_DEFAULT_BUFFER_SIZE;
|
|
|
|
|
|
|
|
|
|
if(specs.rate < AUD_RATE_8000)
|
|
|
|
|
specs.rate = AUD_RATE_44100;
|
|
|
|
|
|
|
|
|
|
if(specs.format <= AUD_FORMAT_INVALID)
|
|
|
|
|
specs.format = AUD_FORMAT_S16;
|
|
|
|
|
|
|
|
|
|
if(specs.channels <= AUD_CHANNELS_INVALID)
|
|
|
|
|
specs.channels = AUD_CHANNELS_STEREO;
|
|
|
|
|
|
2009-08-26 08:09:29 +00:00
|
|
|
if(!AUD_init(device, specs, buffersize))
|
|
|
|
|
AUD_init(AUD_NULL_DEVICE, specs, buffersize);
|
2010-02-21 19:54:18 +00:00
|
|
|
|
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
|
AUD_setSyncCallback(sound_sync_callback, bmain);
|
|
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sound_exit()
|
|
|
|
|
{
|
|
|
|
|
AUD_exit();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
struct bSound* sound_new_file(struct Main *bmain, char* filename)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
|
bSound* sound = NULL;
|
|
|
|
|
|
|
|
|
|
char str[FILE_MAX];
|
2010-07-21 07:55:53 +00:00
|
|
|
char *path;
|
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
strcpy(str, filename);
|
2010-07-21 07:55:53 +00:00
|
|
|
|
|
|
|
|
path = /*bmain ? bmain->name :*/ G.sce;
|
|
|
|
|
|
|
|
|
|
BLI_path_abs(str, path);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
|
len = strlen(filename);
|
|
|
|
|
while(len > 0 && filename[len-1] != '/' && filename[len-1] != '\\')
|
|
|
|
|
len--;
|
|
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
sound = alloc_libblock(&bmain->sound, ID_SO, filename+len);
|
2010-02-28 11:02:06 +00:00
|
|
|
BLI_strncpy(sound->name, filename, FILE_MAX);
|
2009-08-26 14:19:29 +00:00
|
|
|
// XXX unused currently sound->type = SOUND_TYPE_FILE;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
sound_load(bmain, sound);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
if(!sound->playback_handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-21 19:54:18 +00:00
|
|
|
free_libblock(&bmain->sound, sound);
|
2009-08-09 21:16:39 +00:00
|
|
|
sound = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XXX unused currently
|
|
|
|
|
#if 0
|
|
|
|
|
struct bSound* sound_new_buffer(struct bContext *C, struct bSound *source)
|
|
|
|
|
{
|
|
|
|
|
bSound* sound = NULL;
|
|
|
|
|
|
|
|
|
|
char name[25];
|
|
|
|
|
strcpy(name, "buf_");
|
|
|
|
|
strcpy(name + 4, source->id.name);
|
|
|
|
|
|
|
|
|
|
sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name);
|
|
|
|
|
|
|
|
|
|
sound->child_sound = source;
|
|
|
|
|
sound->type = SOUND_TYPE_BUFFER;
|
|
|
|
|
|
2009-08-25 15:30:04 +00:00
|
|
|
sound_load(CTX_data_main(C), sound);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
if(!sound->playback_handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
|
free_libblock(&CTX_data_main(C)->sound, sound);
|
|
|
|
|
sound = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct bSound* sound_new_limiter(struct bContext *C, struct bSound *source, float start, float end)
|
|
|
|
|
{
|
|
|
|
|
bSound* sound = NULL;
|
|
|
|
|
|
|
|
|
|
char name[25];
|
|
|
|
|
strcpy(name, "lim_");
|
|
|
|
|
strcpy(name + 4, source->id.name);
|
|
|
|
|
|
|
|
|
|
sound = alloc_libblock(&CTX_data_main(C)->sound, ID_SO, name);
|
|
|
|
|
|
|
|
|
|
sound->child_sound = source;
|
|
|
|
|
sound->start = start;
|
|
|
|
|
sound->end = end;
|
|
|
|
|
sound->type = SOUND_TYPE_LIMITER;
|
|
|
|
|
|
2009-08-25 15:30:04 +00:00
|
|
|
sound_load(CTX_data_main(C), sound);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
if(!sound->playback_handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
|
free_libblock(&CTX_data_main(C)->sound, sound);
|
|
|
|
|
sound = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sound;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void sound_delete(struct bContext *C, struct bSound* sound)
|
|
|
|
|
{
|
|
|
|
|
if(sound)
|
|
|
|
|
{
|
|
|
|
|
sound_free(sound);
|
|
|
|
|
|
|
|
|
|
free_libblock(&CTX_data_main(C)->sound, sound);
|
2004-04-23 13:11:29 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
void sound_cache(struct bSound* sound, int ignore)
|
|
|
|
|
{
|
|
|
|
|
if(sound->cache && !ignore)
|
|
|
|
|
AUD_unload(sound->cache);
|
|
|
|
|
|
2009-08-26 14:19:29 +00:00
|
|
|
sound->cache = AUD_bufferSound(sound->handle);
|
2010-02-07 23:41:17 +00:00
|
|
|
sound->playback_handle = sound->cache;
|
2009-08-26 18:20:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sound_delete_cache(struct bSound* sound)
|
|
|
|
|
{
|
|
|
|
|
if(sound->cache)
|
|
|
|
|
{
|
|
|
|
|
AUD_unload(sound->cache);
|
|
|
|
|
sound->cache = NULL;
|
2010-02-07 23:41:17 +00:00
|
|
|
sound->playback_handle = sound->handle;
|
2009-08-26 18:20:17 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
void sound_load(struct Main *bmain, struct bSound* sound)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-08-09 21:16:39 +00:00
|
|
|
if(sound)
|
|
|
|
|
{
|
2009-08-26 14:19:29 +00:00
|
|
|
if(sound->handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2009-08-26 14:19:29 +00:00
|
|
|
AUD_unload(sound->handle);
|
|
|
|
|
sound->handle = NULL;
|
2010-02-07 23:41:17 +00:00
|
|
|
sound->playback_handle = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2009-08-26 14:19:29 +00:00
|
|
|
// XXX unused currently
|
|
|
|
|
#if 0
|
2009-08-09 21:16:39 +00:00
|
|
|
switch(sound->type)
|
|
|
|
|
{
|
|
|
|
|
case SOUND_TYPE_FILE:
|
2009-08-26 14:19:29 +00:00
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
|
char fullpath[FILE_MAX];
|
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
|
|
/* load sound */
|
|
|
|
|
PackedFile* pf = sound->packedfile;
|
|
|
|
|
|
|
|
|
|
/* dont modify soundact->sound->name, only change a copy */
|
|
|
|
|
BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
|
|
|
|
|
|
|
|
|
|
if(sound->id.lib)
|
2010-06-02 17:58:28 +00:00
|
|
|
path = sound->id.lib->filepath;
|
2009-08-09 21:16:39 +00:00
|
|
|
else
|
2010-07-21 07:55:53 +00:00
|
|
|
path = /*bmain ? bmain->name :*/ G.sce;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-03-09 17:36:23 +00:00
|
|
|
BLI_path_abs(fullpath, path);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
|
/* but we need a packed file then */
|
|
|
|
|
if (pf)
|
2009-08-26 14:19:29 +00:00
|
|
|
sound->handle = AUD_loadBuffer((unsigned char*) pf->data, pf->size);
|
2009-08-09 21:16:39 +00:00
|
|
|
/* or else load it from disk */
|
|
|
|
|
else
|
2009-08-26 14:19:29 +00:00
|
|
|
sound->handle = AUD_load(fullpath);
|
|
|
|
|
} // XXX
|
|
|
|
|
// XXX unused currently
|
|
|
|
|
#if 0
|
2009-08-09 21:16:39 +00:00
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
case SOUND_TYPE_BUFFER:
|
2009-08-26 14:19:29 +00:00
|
|
|
if(sound->child_sound && sound->child_sound->handle)
|
|
|
|
|
sound->handle = AUD_bufferSound(sound->child_sound->handle);
|
2009-08-09 21:16:39 +00:00
|
|
|
break;
|
|
|
|
|
case SOUND_TYPE_LIMITER:
|
2009-08-26 14:19:29 +00:00
|
|
|
if(sound->child_sound && sound->child_sound->handle)
|
|
|
|
|
sound->handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
|
2009-08-09 21:16:39 +00:00
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-08-26 14:19:29 +00:00
|
|
|
#endif
|
2010-02-07 23:41:17 +00:00
|
|
|
if(sound->cache)
|
|
|
|
|
sound->playback_handle = sound->cache;
|
|
|
|
|
else
|
|
|
|
|
sound->playback_handle = sound->handle;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
void sound_free(struct bSound* sound)
|
2006-11-25 13:07:28 +00:00
|
|
|
{
|
2009-08-09 21:16:39 +00:00
|
|
|
if (sound->packedfile)
|
|
|
|
|
{
|
|
|
|
|
freePackedFile(sound->packedfile);
|
|
|
|
|
sound->packedfile = NULL;
|
2006-11-25 13:07:28 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2009-08-26 14:19:29 +00:00
|
|
|
if(sound->handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2009-08-26 14:19:29 +00:00
|
|
|
AUD_unload(sound->handle);
|
|
|
|
|
sound->handle = NULL;
|
2010-02-07 23:41:17 +00:00
|
|
|
sound->playback_handle = NULL;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
static float sound_get_volume(Scene* scene, Sequence* sequence, float time)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-08 23:07:53 +00:00
|
|
|
AnimData *adt= BKE_animdata_from_id(&scene->id);
|
|
|
|
|
FCurve *fcu = NULL;
|
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
|
|
/* NOTE: this manually constructed path needs to be used here to avoid problems with RNA crashes */
|
|
|
|
|
sprintf(buf, "sequence_editor.sequences_all[\"%s\"].volume", sequence->name+2);
|
|
|
|
|
if (adt && adt->action && adt->action->curves.first)
|
|
|
|
|
fcu= list_find_fcurve(&adt->action->curves, buf, 0);
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
if(fcu)
|
|
|
|
|
return evaluate_fcurve(fcu, time * FPS);
|
|
|
|
|
else
|
|
|
|
|
return sequence->volume;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_Device* mixdown = AUD_openReadDevice(specs);
|
|
|
|
|
|
|
|
|
|
AUD_setDeviceVolume(mixdown, volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_playDevice(mixdown, scene->sound_scene, start / FPS);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
return mixdown;
|
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_create_scene(struct Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
scene->sound_scene = AUD_createSequencer(scene, (AUD_volumeFunction)&sound_get_volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_destroy_scene(struct Scene *scene)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
if(scene->sound_scene_handle)
|
|
|
|
|
AUD_stop(scene->sound_scene_handle);
|
|
|
|
|
if(scene->sound_scene)
|
|
|
|
|
AUD_destroySequencer(scene->sound_scene);
|
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-03-20 11:15:16 +00:00
|
|
|
void* sound_scene_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
|
|
|
|
|
{
|
2010-03-21 15:40:36 +00:00
|
|
|
if(scene != sequence->scene)
|
|
|
|
|
return AUD_addSequencer(scene->sound_scene, &(sequence->scene->sound_scene), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
|
|
|
|
|
return NULL;
|
2010-03-20 11:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void* sound_add_scene_sound(struct Scene *scene, struct Sequence* sequence, int startframe, int endframe, int frameskip)
|
|
|
|
|
{
|
|
|
|
|
return AUD_addSequencer(scene->sound_scene, &(sequence->sound->playback_handle), startframe / FPS, endframe / FPS, frameskip / FPS, sequence);
|
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_remove_scene_sound(struct Scene *scene, void* handle)
|
|
|
|
|
{
|
|
|
|
|
AUD_removeSequencer(scene->sound_scene, handle);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_mute_scene_sound(struct Scene *scene, void* handle, char mute)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_muteSequencer(scene->sound_scene, handle, mute);
|
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, int endframe, int frameskip)
|
|
|
|
|
{
|
|
|
|
|
AUD_moveSequencer(scene->sound_scene, handle, startframe / FPS, endframe / FPS, frameskip / FPS);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_start_play_scene(struct Scene *scene)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_Sound* sound;
|
|
|
|
|
sound = AUD_loopSound(scene->sound_scene);
|
|
|
|
|
scene->sound_scene_handle = AUD_play(sound, 1);
|
|
|
|
|
AUD_unload(sound);
|
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_play_scene(struct Scene *scene)
|
|
|
|
|
{
|
2010-02-21 18:01:41 +00:00
|
|
|
AUD_Status status;
|
2009-08-09 21:16:39 +00:00
|
|
|
AUD_lock();
|
|
|
|
|
|
2010-02-21 18:01:41 +00:00
|
|
|
status = AUD_getStatus(scene->sound_scene_handle);
|
|
|
|
|
|
|
|
|
|
if(status == AUD_STATUS_INVALID)
|
2010-02-07 23:41:17 +00:00
|
|
|
sound_start_play_scene(scene);
|
|
|
|
|
|
|
|
|
|
AUD_setLoop(scene->sound_scene_handle, -1, -1);
|
2010-02-21 18:01:41 +00:00
|
|
|
|
|
|
|
|
if(status != AUD_STATUS_PLAYING)
|
|
|
|
|
{
|
|
|
|
|
AUD_seek(scene->sound_scene_handle, CFRA / FPS);
|
|
|
|
|
AUD_resume(scene->sound_scene_handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
AUD_startPlayback();
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
|
AUD_unlock();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_stop_scene(struct Scene *scene)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_pause(scene->sound_scene_handle);
|
2010-02-21 18:01:41 +00:00
|
|
|
|
|
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
AUD_stopPlayback();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
void sound_seek_scene(struct bContext *C)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
struct Scene *scene = CTX_data_scene(C);
|
2010-02-21 18:01:41 +00:00
|
|
|
AUD_Status status;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_lock();
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-21 18:01:41 +00:00
|
|
|
status = AUD_getStatus(scene->sound_scene_handle);
|
|
|
|
|
|
|
|
|
|
if(status == AUD_STATUS_INVALID)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
|
|
|
|
sound_start_play_scene(scene);
|
|
|
|
|
AUD_pause(scene->sound_scene_handle);
|
|
|
|
|
}
|
2009-09-26 20:03:01 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
if(scene->audio.flag & AUDIO_SCRUB && !CTX_wm_screen(C)->animtimer)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_setLoop(scene->sound_scene_handle, -1, 1 / FPS);
|
2010-02-21 18:01:41 +00:00
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
|
|
|
|
|
else
|
|
|
|
|
AUD_seek(scene->sound_scene_handle, CFRA / FPS);
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_resume(scene->sound_scene_handle);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-02-07 23:41:17 +00:00
|
|
|
else
|
2010-02-21 18:01:41 +00:00
|
|
|
{
|
|
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
AUD_seekSequencer(scene->sound_scene_handle, CFRA / FPS);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(status == AUD_STATUS_PLAYING)
|
|
|
|
|
AUD_seek(scene->sound_scene_handle, CFRA / FPS);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-19 12:20:29 +00:00
|
|
|
float sound_sync_scene(struct Scene *scene)
|
|
|
|
|
{
|
2010-02-21 18:01:41 +00:00
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
return AUD_getSequencerPosition(scene->sound_scene_handle);
|
|
|
|
|
else
|
|
|
|
|
return AUD_getPosition(scene->sound_scene_handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sound_scene_playing(struct Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
if(scene->audio.flag & AUDIO_SYNC)
|
|
|
|
|
return AUD_doesPlayback();
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
2010-02-19 12:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-17 13:41:22 +00:00
|
|
|
int sound_read_sound_buffer(struct bSound* sound, float* buffer, int length, float start, float end)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2010-07-17 13:41:22 +00:00
|
|
|
AUD_Sound* limiter = AUD_limitSound(sound->cache, start, end);
|
|
|
|
|
return AUD_readSound(limiter, buffer, length);
|
|
|
|
|
AUD_unload(limiter);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|