37 #define DNA_DEPRECATED_ALLOW
50 # include "../../../intern/audaspace/intern/AUD_Set.h"
51 # include <AUD_Handle.h>
52 # include <AUD_Sequence.h>
53 # include <AUD_Sound.h>
54 # include <AUD_Special.h>
129 .offset_in_ID = offsetof(
bSound, waveform),
140 if (sound->
id.
us > 0 || is_undo) {
191 reader, sound->
id.
lib, &sound->
ipo);
204 .struct_size =
sizeof(
bSound),
206 .name_plural =
"sounds",
224 .blend_read_undo_preserve =
NULL,
226 .lib_override_apply_post =
NULL,
229 #ifdef WITH_AUDASPACE
231 static int sound_cfra;
232 static char **audio_device_names =
NULL;
317 #ifdef WITH_AUDASPACE
319 AUD_Sound_free(sound->
handle);
325 AUD_Sound_free(sound->
cache);
333 #ifdef WITH_AUDASPACE
335 static const char *force_device =
NULL;
340 static void sound_sync_callback(
void *
data,
int mode,
float time)
352 force_device = device;
361 static AUD_Device *sound_device =
NULL;
373 AUD_DeviceSpecs specs;
374 int device, buffersize;
375 const char *device_name;
377 device =
U.audiodevice;
378 buffersize =
U.mixbufsize;
379 specs.channels =
U.audiochannels;
380 specs.format =
U.audioformat;
381 specs.rate =
U.audiorate;
383 if (force_device ==
NULL) {
386 device_name =
names[0];
389 for (i = 0;
names[i]; i++) {
391 device_name =
names[i];
396 device_name = force_device;
399 if (buffersize < 128) {
403 if (specs.rate < AUD_RATE_8000) {
404 specs.rate = AUD_RATE_48000;
407 if (specs.format <= AUD_FORMAT_INVALID) {
408 specs.format = AUD_FORMAT_S16;
411 if (specs.channels <= AUD_CHANNELS_INVALID) {
412 specs.channels = AUD_CHANNELS_STEREO;
415 if (!(sound_device = AUD_init(device_name, specs, buffersize,
"Blender"))) {
416 sound_device = AUD_init(
"None", specs, buffersize,
"Blender");
426 AUD_setSynchronizerCallback(sound_sync_callback, bmain);
435 AUD_exit(sound_device);
441 AUD_exit(sound_device);
445 if (audio_device_names !=
NULL) {
447 for (i = 0; audio_device_names[i]; i++) {
448 free(audio_device_names[i]);
450 free(audio_device_names);
451 audio_device_names =
NULL;
462 strcpy(name,
"buf_");
463 strcpy(name + 4, source->
id.
name);
467 sound->child_sound = source;
468 sound->type = SOUND_TYPE_BUFFER;
470 sound_load(bmain, sound);
475 bSound *BKE_sound_new_limiter(
Main *bmain,
bSound *source,
float start,
float end)
480 strcpy(name,
"lim_");
481 strcpy(name + 4, source->
id.
name);
485 sound->child_sound = source;
486 sound->start = start;
488 sound->type = SOUND_TYPE_LIMITER;
490 sound_load(bmain, sound);
501 AUD_Sound_free(sound->
cache);
516 AUD_Sound_free(sound->
cache);
522 static void sound_load_audio(
Main *bmain,
bSound *sound,
bool free_waveform)
526 AUD_Sound_free(sound->
cache);
531 AUD_Sound_free(sound->
handle);
542 switch (sound->type) {
543 case SOUND_TYPE_FILE:
557 sound->
handle = AUD_Sound_bufferFile((
unsigned char *)
pf->data,
pf->size);
561 sound->
handle = AUD_Sound_file(fullpath);
568 case SOUND_TYPE_BUFFER:
569 if (sound->child_sound && sound->child_sound->
handle) {
570 sound->
handle = AUD_bufferSound(sound->child_sound->
handle);
573 case SOUND_TYPE_LIMITER:
574 if (sound->child_sound && sound->child_sound->
handle) {
575 sound->
handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
581 void *handle = AUD_Sound_rechannel(sound->
handle, AUD_CHANNELS_MONO);
582 AUD_Sound_free(sound->
handle);
601 sound_load_audio(bmain, sound,
true);
604 AUD_Device *BKE_sound_mixdown(
const Scene *
scene, AUD_DeviceSpecs specs,
int start,
float volume)
652 AUD_Device_lock(sound_device);
657 AUD_Device_unlock(sound_device);
667 specs.channels = AUD_Device_getChannels(sound_device);
668 specs.rate = AUD_Device_getRate(sound_device);
707 const double fps =
FPS;
735 const double fps =
FPS;
741 AUD_SequenceEntry_setMuted(handle, (sequence->
flag &
SEQ_MUTE) != 0);
742 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME,
CFRA, &sequence->
volume, 0);
743 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH,
CFRA, &sequence->
pitch, 0);
744 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING,
CFRA, &sequence->
pan, 0);
764 AUD_SequenceEntry_setMuted(handle, mute);
768 Scene *
scene,
void *handle,
int startframe,
int endframe,
int frameskip,
double audio_offset)
771 const double fps =
FPS;
772 AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps + audio_offset);
813 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
818 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
823 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
828 BLI_assert(!
"is not supposed to be used, is weird function.");
837 static void sound_start_play_scene(
Scene *
scene)
865 const double cur_time = get_cur_time(
scene);
867 AUD_Device_lock(sound_device);
872 if (status == AUD_STATUS_INVALID) {
873 sound_start_play_scene(
scene);
876 AUD_Device_unlock(sound_device);
881 if (status != AUD_STATUS_PLAYING) {
887 AUD_playSynchronizer();
890 AUD_Device_unlock(sound_device);
899 AUD_stopSynchronizer();
910 int animation_playing;
912 const double one_frame = 1.0 /
FPS;
915 AUD_Device_lock(sound_device);
920 if (status == AUD_STATUS_INVALID) {
921 sound_start_play_scene(
scene);
924 AUD_Device_unlock(sound_device);
931 animation_playing = 0;
934 animation_playing = 1;
961 if (status == AUD_STATUS_PLAYING) {
967 AUD_Device_unlock(sound_device);
975 if (
G.is_rendering) {
994 if (
G.is_rendering) {
999 if (AUD_Device_getRate(sound_device) == AUD_RATE_INVALID) {
1004 return AUD_isSynchronizerPlaying();
1015 if (waveform->
data) {
1029 bool need_close_audio_handles =
false;
1032 sound_load_audio(bmain, sound,
true);
1033 need_close_audio_handles =
true;
1039 if (info.length > 0) {
1043 waveform->
length = AUD_readSound(
1056 if (waveform->
data) {
1073 if (need_close_audio_handles) {
1100 if (speaker->
sound) {
1109 if (speaker->
sound) {
1132 AUD_SequenceEntry_setAnimationData(
1134 AUD_SequenceEntry_setAnimationData(
1136 AUD_SequenceEntry_setAnimationData(
1138 AUD_SequenceEntry_setAnimationData(
1162 sound_update_base(
scene,
object, new_set);
1173 AUD_Sequence_setAnimationData(
1184 return ((
bSound *)sound)->playback_handle;
1202 if (audio_device_names ==
NULL) {
1203 audio_device_names = AUD_getDeviceNames();
1206 return audio_device_names;
1209 static bool sound_info_from_playback_handle(
void *playback_handle,
SoundInfo *sound_info)
1211 if (playback_handle ==
NULL) {
1214 AUD_SoundInfo info = AUD_getInfo(playback_handle);
1216 sound_info->
length = info.length;
1224 return sound_info_from_playback_handle(sound->
playback_handle, sound_info);
1229 sound_load_audio(
main, sound,
false);
1316 double UNUSED(audio_offset))
1438 #if defined(WITH_AUDASPACE) && defined(WITH_JACK)
1450 if (
G.is_rendering) {
1460 #ifdef WITH_AUDASPACE
void * AUD_getSet(void *set)
void AUD_addSet(void *set, void *entry)
void AUD_destroySet(void *set)
char AUD_removeSet(void *set, void *entry)
@ IDTYPE_FLAGS_NO_ANIMDATA
void(* IDTypeForeachCacheFunctionCallback)(struct ID *id, const struct IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data)
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT
void id_us_plus(struct ID *id)
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
const char * BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL()
struct PackedFile * BKE_packedfile_duplicate(const struct PackedFile *pf_src)
void BKE_packedfile_blend_write(struct BlendWriter *writer, struct PackedFile *pf)
void BKE_packedfile_blend_read(struct BlendDataReader *reader, struct PackedFile **pf_p)
void BKE_packedfile_free(struct PackedFile *pf)
#define SOUND_WAVE_SAMPLES_PER_SECOND
void(* SoundJackSyncCallback)(struct Main *bmain, int mode, double time)
void * BKE_sound_get_factory(void *sound)
void * BKE_sound_get_device(void)
void BLI_kdtree_nd_() free(KDTree *tree)
void mat4_to_quat(float q[4], const float mat[4][4])
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
pthread_spinlock_t SpinLock
void BLI_spin_init(SpinLock *spin)
void BLI_spin_unlock(SpinLock *spin)
void BLI_spin_lock(SpinLock *spin)
void BLI_spin_end(SpinLock *spin)
#define UNUSED_VARS_NDEBUG(...)
bool BLO_read_data_is_undo(BlendDataReader *reader)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_expand(expander, id)
bool BLO_write_is_undo(BlendWriter *writer)
#define BLT_I18NCONTEXT_ID_SOUND
struct Depsgraph Depsgraph
void DEG_debug_print_eval(struct Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
bool DEG_id_type_any_exists(const struct Depsgraph *depsgraph, short id_type)
#define DEG_OBJECT_ITER_END
#define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT
@ LIB_TAG_COPIED_ON_WRITE
#define ID_BLEND_PATH(_bmain, _id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
Object is a sort of wrapper for general info.
#define AUDIO_VOLUME_ANIMATED
@ SOUND_TAGS_WAVEFORM_LOADING
@ SOUND_TAGS_WAVEFORM_NO_RELOAD
Read Guarded memory(de)allocation.
static void init_data(ModifierData *md)
void BKE_sound_jack_sync_callback_set(SoundJackSyncCallback callback)
bSound * BKE_sound_new_file_exists(Main *bmain, const char *filepath)
static void sound_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int UNUSED(flag))
BLI_INLINE void sound_verify_evaluated_id(const ID *id)
void * BKE_sound_scene_add_scene_sound(Scene *UNUSED(scene), Sequence *UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip))
void BKE_sound_init_once(void)
void BKE_sound_seek_scene(Main *UNUSED(bmain), Scene *UNUSED(scene))
static void sound_free_audio(bSound *sound)
void BKE_sound_load(Main *UNUSED(bmain), bSound *UNUSED(sound))
void BKE_sound_force_device(const char *UNUSED(device))
void * BKE_sound_add_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence))
void BKE_sound_lock(void)
void BKE_sound_set_scene_sound_volume(void *UNUSED(handle), float UNUSED(volume), char UNUSED(animated))
void BKE_sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute))
static void sound_free_data(ID *id)
static void sound_blend_read_lib(BlendLibReader *reader, ID *id)
void BKE_sound_play_scene(Scene *UNUSED(scene))
static void sound_blend_read_data(BlendDataReader *reader, ID *id)
void BKE_sound_set_scene_sound_pitch(void *UNUSED(handle), float UNUSED(pitch), char UNUSED(animated))
void BKE_sound_move_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence))
void BKE_sound_jack_scene_update(Scene *scene, int mode, double time)
int BKE_sound_scene_playing(Scene *UNUSED(scene))
void BKE_sound_update_sequencer(Main *UNUSED(main), bSound *UNUSED(sound))
char ** BKE_sound_get_device_names(void)
void BKE_sound_remove_scene_sound(Scene *UNUSED(scene), void *UNUSED(handle))
void * BKE_sound_add_scene_sound(Scene *UNUSED(scene), Sequence *UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip))
float BKE_sound_get_length(struct Main *UNUSED(bmain), bSound *UNUSED(sound))
void BKE_sound_destroy_scene(Scene *UNUSED(scene))
static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_address)
bSound * BKE_sound_new_file(Main *bmain, const char *filepath)
void BKE_sound_ensure_scene(struct Scene *scene)
void BKE_sound_cache(bSound *UNUSED(sound))
void BKE_sound_free_waveform(bSound *UNUSED(sound))
bool BKE_sound_info_get(struct Main *UNUSED(main), struct bSound *UNUSED(sound), SoundInfo *UNUSED(sound_info))
void BKE_sound_reset_runtime(bSound *sound)
void BKE_sound_set_scene_volume(Scene *UNUSED(scene), float UNUSED(volume))
void BKE_sound_update_scene_listener(Scene *UNUSED(scene))
void BKE_sound_reset_scene_specs(Scene *UNUSED(scene))
void BKE_sound_unlock(void)
void BKE_sound_set_scene_sound_pan(void *UNUSED(handle), float UNUSED(pan), char UNUSED(animated))
void BKE_sound_init_main(Main *UNUSED(bmain))
double BKE_sound_sync_scene(Scene *UNUSED(scene))
void * BKE_sound_scene_add_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence))
void BKE_sound_stop_scene(Scene *UNUSED(scene))
void BKE_sound_move_scene_sound(Scene *UNUSED(scene), void *UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip), double UNUSED(audio_offset))
void BKE_sound_create_scene(Scene *UNUSED(scene))
static void sound_foreach_cache(ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
void BKE_sound_reset_scene_runtime(Scene *scene)
void BKE_sound_init(Main *UNUSED(bmain))
void BKE_sound_set_cfra(int UNUSED(cfra))
void BKE_sound_update_scene(Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene))
void BKE_sound_exit_once(void)
void BKE_sound_delete_cache(bSound *UNUSED(sound))
void BKE_sound_mute_scene(Scene *UNUSED(scene), int UNUSED(muted))
bSound * BKE_sound_new_file_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
void BKE_sound_read_waveform(Main *bmain, bSound *sound, short *stop)
void BKE_sound_evaluate(Depsgraph *depsgraph, Main *bmain, bSound *sound)
void BKE_sound_update_scene_sound(void *UNUSED(handle), bSound *UNUSED(sound))
void BKE_sound_exit(void)
void BKE_sound_update_fps(Main *UNUSED(bmain), Scene *UNUSED(scene))
void BKE_sound_ensure_loaded(Main *bmain, bSound *sound)
static void sound_blend_read_expand(BlendExpander *expander, ID *id)
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
const Depsgraph * depsgraph
DEGForeachIDComponentCallback callback
#define pf(_x, _i)
Prefetch 64.
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)
int main(int argc, char **argv)
void SEQ_sound_update(Scene *scene, bSound *sound)
void SEQ_sound_update_length(Main *bmain, Scene *scene)
unsigned int id_session_uuid
void * sound_scrub_handle
struct SoundInfo::@62 specs
struct wmTimer * animtimer
struct PackedFile * packedfile
struct PackedFile * newpackedfile
static void sound_jack_sync_callback(Main *bmain, int mode, double time)