21 #define DNA_DEPRECATED_ALLOW
34 # include "../../../intern/audaspace/intern/AUD_Set.h"
35 # include <AUD_Handle.h>
36 # include <AUD_Sequence.h>
37 # include <AUD_Sound.h>
38 # include <AUD_Special.h>
115 .offset_in_ID = offsetof(
bSound, waveform),
199 .struct_size =
sizeof(
bSound),
201 .name_plural =
"sounds",
204 .asset_type_info =
NULL,
221 .blend_read_undo_preserve =
NULL,
223 .lib_override_apply_post =
NULL,
226 #ifdef WITH_AUDASPACE
228 static int sound_cfra;
229 static char **audio_device_names =
NULL;
319 #ifdef WITH_AUDASPACE
321 AUD_Sound_free(sound->
handle);
327 AUD_Sound_free(sound->
cache);
335 #ifdef WITH_AUDASPACE
337 static const char *force_device =
NULL;
342 static void sound_sync_callback(
void *
data,
int mode,
float time)
354 force_device = device;
363 static AUD_Device *sound_device =
NULL;
375 AUD_DeviceSpecs specs;
376 int device, buffersize;
377 const char *device_name;
379 device =
U.audiodevice;
380 buffersize =
U.mixbufsize;
381 specs.channels =
U.audiochannels;
382 specs.format =
U.audioformat;
383 specs.rate =
U.audiorate;
385 if (force_device ==
NULL) {
388 device_name =
names[0];
391 for (i = 0;
names[i]; i++) {
393 device_name =
names[i];
398 device_name = force_device;
401 if (buffersize < 128) {
405 if (specs.rate < AUD_RATE_8000) {
406 specs.rate = AUD_RATE_48000;
409 if (specs.format <= AUD_FORMAT_INVALID) {
410 specs.format = AUD_FORMAT_S16;
413 if (specs.channels <= AUD_CHANNELS_INVALID) {
414 specs.channels = AUD_CHANNELS_STEREO;
417 if (!(sound_device = AUD_init(device_name, specs, buffersize,
"Blender"))) {
418 sound_device = AUD_init(
"None", specs, buffersize,
"Blender");
428 AUD_setSynchronizerCallback(sound_sync_callback, bmain);
437 AUD_exit(sound_device);
443 AUD_exit(sound_device);
447 if (audio_device_names !=
NULL) {
449 for (i = 0; audio_device_names[i]; i++) {
450 free(audio_device_names[i]);
452 free(audio_device_names);
453 audio_device_names =
NULL;
464 strcpy(name,
"buf_");
465 strcpy(name + 4, source->
id.
name);
469 sound->child_sound = source;
470 sound->type = SOUND_TYPE_BUFFER;
472 sound_load(bmain, sound);
477 bSound *BKE_sound_new_limiter(
Main *bmain,
bSound *source,
float start,
float end)
482 strcpy(name,
"lim_");
483 strcpy(name + 4, source->
id.
name);
487 sound->child_sound = source;
488 sound->start = start;
490 sound->type = SOUND_TYPE_LIMITER;
492 sound_load(bmain, sound);
503 AUD_Sound_free(sound->
cache);
518 AUD_Sound_free(sound->
cache);
524 static void sound_load_audio(
Main *bmain,
bSound *sound,
bool free_waveform)
528 AUD_Sound_free(sound->
cache);
533 AUD_Sound_free(sound->
handle);
544 switch (sound->type) {
545 case SOUND_TYPE_FILE:
559 sound->
handle = AUD_Sound_bufferFile((
unsigned char *)
pf->data,
pf->size);
563 sound->
handle = AUD_Sound_file(fullpath);
570 case SOUND_TYPE_BUFFER:
571 if (sound->child_sound && sound->child_sound->
handle) {
572 sound->
handle = AUD_bufferSound(sound->child_sound->
handle);
575 case SOUND_TYPE_LIMITER:
576 if (sound->child_sound && sound->child_sound->
handle) {
577 sound->
handle = AUD_limitSound(sound->child_sound, sound->start, sound->end);
583 void *handle = AUD_Sound_rechannel(sound->
handle, AUD_CHANNELS_MONO);
584 AUD_Sound_free(sound->
handle);
603 sound_load_audio(bmain, sound,
true);
606 AUD_Device *BKE_sound_mixdown(
const Scene *
scene, AUD_DeviceSpecs specs,
int start,
float volume)
654 AUD_Device_lock(sound_device);
659 AUD_Device_unlock(sound_device);
669 specs.channels = AUD_Device_getChannels(sound_device);
670 specs.rate = AUD_Device_getRate(sound_device);
709 const double fps =
FPS;
737 const double fps =
FPS;
761 AUD_SequenceEntry_setMuted(handle, mute);
772 const double fps =
FPS;
773 AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps + audio_offset);
814 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
819 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
824 AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
829 BLI_assert_msg(0,
"is not supposed to be used, is weird function.");
838 static void sound_start_play_scene(
Scene *
scene)
866 const double cur_time = get_cur_time(
scene);
868 AUD_Device_lock(sound_device);
873 if (status == AUD_STATUS_INVALID) {
874 sound_start_play_scene(
scene);
877 AUD_Device_unlock(sound_device);
882 if (status != AUD_STATUS_PLAYING) {
888 AUD_playSynchronizer();
891 AUD_Device_unlock(sound_device);
900 AUD_stopSynchronizer();
911 int animation_playing;
913 const double one_frame = 1.0 /
FPS;
916 AUD_Device_lock(sound_device);
921 if (status == AUD_STATUS_INVALID) {
922 sound_start_play_scene(
scene);
925 AUD_Device_unlock(sound_device);
932 animation_playing = 0;
935 animation_playing = 1;
962 if (status == AUD_STATUS_PLAYING) {
968 AUD_Device_unlock(sound_device);
976 if (
G.is_rendering) {
995 if (
G.is_rendering) {
1000 if (AUD_Device_getRate(sound_device) == AUD_RATE_INVALID) {
1005 return AUD_isSynchronizerPlaying();
1016 if (waveform->
data) {
1030 bool need_close_audio_handles =
false;
1033 sound_load_audio(bmain, sound,
true);
1034 need_close_audio_handles =
true;
1040 if (info.length > 0) {
1044 waveform->
length = AUD_readSound(
1057 if (waveform->
data) {
1074 if (need_close_audio_handles) {
1101 if (speaker->
sound) {
1110 if (speaker->
sound) {
1133 AUD_SequenceEntry_setAnimationData(
1135 AUD_SequenceEntry_setAnimationData(
1137 AUD_SequenceEntry_setAnimationData(
1139 AUD_SequenceEntry_setAnimationData(
1163 sound_update_base(
scene,
object, new_set);
1174 AUD_Sequence_setAnimationData(
1185 return ((
bSound *)sound)->playback_handle;
1203 if (audio_device_names ==
NULL) {
1204 audio_device_names = AUD_getDeviceNames();
1207 return audio_device_names;
1210 static bool sound_info_from_playback_handle(
void *playback_handle,
SoundInfo *sound_info)
1212 if (playback_handle ==
NULL) {
1215 AUD_SoundInfo info = AUD_getInfo(playback_handle);
1217 sound_info->
length = info.length;
1225 return sound_info_from_playback_handle(sound->
playback_handle, sound_info);
1230 sound_load_audio(
main, sound,
false);
1237 const char *filepath,
1244 AUD_StreamInfo *stream_infos;
1250 sound = AUD_Sound_file(
str);
1255 stream_count = AUD_Sound_getFileStreams(sound, &stream_infos);
1257 AUD_Sound_free(sound);
1259 if (!stream_infos) {
1263 if ((stream < 0) || (stream >= stream_count)) {
1268 sound_info->
start = stream_infos[stream].start;
1269 sound_info->
duration = stream_infos[stream].duration;
1357 double UNUSED(audio_offset))
1446 const char *
UNUSED(filepath),
1487 #if defined(WITH_AUDASPACE) && defined(WITH_JACK)
1499 if (
G.is_rendering) {
1509 #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)
bool BKE_bpath_foreach_path_fixed_process(struct BPathForeachPathData *bpath_data, char *path)
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
@ 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, 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)
#define BLI_assert_msg(a, msg)
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, 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
#define ID_BLEND_PATH(_bmain, _id)
@ LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT
@ LIB_TAG_COPIED_ON_WRITE
#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)
int main(int argc, char *argv[])
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_stream_info_get(struct Main *UNUSED(main), const char *UNUSED(filepath), int UNUSED(stream), SoundStreamInfo *UNUSED(sound_info))
static void sound_foreach_path(ID *id, BPathForeachPathData *bpath_data)
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(const 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)
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)
T length(const vec_base< T, Size > &a)
void SEQ_sound_update(Scene *scene, bSound *sound)
void SEQ_sound_update_length(Main *bmain, Scene *scene)
int SEQ_time_left_handle_frame_get(const Scene *UNUSED(scene), const Sequence *seq)
int SEQ_time_right_handle_frame_get(const Scene *scene, const Sequence *seq)
unsigned int id_session_uuid
void * sound_scrub_handle
struct SoundInfo::@63 specs
struct wmTimer * animtimer
struct PackedFile * packedfile
struct PackedFile * newpackedfile
static void sound_jack_sync_callback(Main *bmain, int mode, double time)