Blender  V3.3
blenkernel/intern/sound.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_blenlib.h"
14 #include "BLI_iterator.h"
15 #include "BLI_math.h"
16 #include "BLI_threads.h"
17 
18 #include "BLT_translation.h"
19 
20 /* Allow using deprecated functionality for .blend file I/O. */
21 #define DNA_DEPRECATED_ALLOW
22 
23 #include "DNA_anim_types.h"
24 #include "DNA_object_types.h"
25 #include "DNA_packedFile_types.h"
26 #include "DNA_scene_types.h"
27 #include "DNA_screen_types.h"
28 #include "DNA_sequence_types.h"
29 #include "DNA_sound_types.h"
30 #include "DNA_speaker_types.h"
32 
33 #ifdef WITH_AUDASPACE
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>
39 #endif
40 
41 #include "BKE_bpath.h"
42 #include "BKE_global.h"
43 #include "BKE_idtype.h"
44 #include "BKE_lib_id.h"
45 #include "BKE_main.h"
46 #include "BKE_packedFile.h"
47 #include "BKE_scene.h"
48 #include "BKE_sound.h"
49 
50 #include "DEG_depsgraph.h"
51 #include "DEG_depsgraph_query.h"
52 
53 #include "BLO_read_write.h"
54 
55 #include "SEQ_sequencer.h"
56 #include "SEQ_sound.h"
57 #include "SEQ_time.h"
58 
59 static void sound_free_audio(bSound *sound);
60 
61 static void sound_copy_data(Main *UNUSED(bmain),
62  ID *id_dst,
63  const ID *id_src,
64  const int UNUSED(flag))
65 {
66  bSound *sound_dst = (bSound *)id_dst;
67  const bSound *sound_src = (const bSound *)id_src;
68 
69  sound_dst->handle = NULL;
70  sound_dst->cache = NULL;
71  sound_dst->waveform = NULL;
72  sound_dst->playback_handle = NULL;
73  sound_dst->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
74  BLI_spin_init(sound_dst->spinlock);
75 
76  /* Just to be sure, should not have any value actually after reading time. */
77  sound_dst->ipo = NULL;
78  sound_dst->newpackedfile = NULL;
79 
80  if (sound_src->packedfile != NULL) {
81  sound_dst->packedfile = BKE_packedfile_duplicate(sound_src->packedfile);
82  }
83 
84  BKE_sound_reset_runtime(sound_dst);
85 }
86 
87 static void sound_free_data(ID *id)
88 {
89  bSound *sound = (bSound *)id;
90 
91  /* No animation-data here. */
92 
93  if (sound->packedfile) {
95  sound->packedfile = NULL;
96  }
97 
98  sound_free_audio(sound);
100 
101  if (sound->spinlock) {
102  BLI_spin_end(sound->spinlock);
103  MEM_freeN(sound->spinlock);
104  sound->spinlock = NULL;
105  }
106 }
107 
108 static void sound_foreach_cache(ID *id,
109  IDTypeForeachCacheFunctionCallback function_callback,
110  void *user_data)
111 {
112  bSound *sound = (bSound *)id;
113  IDCacheKey key = {
114  .id_session_uuid = id->session_uuid,
115  .offset_in_ID = offsetof(bSound, waveform),
116  };
117 
118  function_callback(id, &key, &sound->waveform, 0, user_data);
119 }
120 
121 static void sound_foreach_path(ID *id, BPathForeachPathData *bpath_data)
122 {
123  bSound *sound = (bSound *)id;
124  if (sound->packedfile != NULL && (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_PACKED) != 0) {
125  return;
126  }
127 
128  /* FIXME: This does not check for empty path... */
130 }
131 
132 static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_address)
133 {
134  bSound *sound = (bSound *)id;
135  const bool is_undo = BLO_write_is_undo(writer);
136 
137  /* Clean up, important in undo case to reduce false detection of changed datablocks. */
138  sound->tags = 0;
139  sound->handle = NULL;
140  sound->playback_handle = NULL;
141  sound->spinlock = NULL;
142 
143  /* Do not store packed files in case this is a library override ID. */
144  if (ID_IS_OVERRIDE_LIBRARY(sound) && !is_undo) {
145  sound->packedfile = NULL;
146  }
147 
148  /* write LibData */
149  BLO_write_id_struct(writer, bSound, id_address, &sound->id);
150  BKE_id_blend_write(writer, &sound->id);
151 
152  BKE_packedfile_blend_write(writer, sound->packedfile);
153 }
154 
155 static void sound_blend_read_data(BlendDataReader *reader, ID *id)
156 {
157  bSound *sound = (bSound *)id;
158  sound->tags = 0;
159  sound->handle = NULL;
160  sound->playback_handle = NULL;
161 
162  /* versioning stuff, if there was a cache, then we enable caching: */
163  if (sound->cache) {
164  sound->flags |= SOUND_FLAGS_CACHING;
165  sound->cache = NULL;
166  }
167 
168  if (BLO_read_data_is_undo(reader)) {
170  }
171 
172  sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
173  BLI_spin_init(sound->spinlock);
174 
175  /* clear waveform loading flag */
177 
178  BKE_packedfile_blend_read(reader, &sound->packedfile);
179  BKE_packedfile_blend_read(reader, &sound->newpackedfile);
180 }
181 
182 static void sound_blend_read_lib(BlendLibReader *reader, ID *id)
183 {
184  bSound *sound = (bSound *)id;
185  /* XXX: deprecated - old animation system. */
186  BLO_read_id_address(reader, sound->id.lib, &sound->ipo);
187 }
188 
189 static void sound_blend_read_expand(BlendExpander *expander, ID *id)
190 {
191  bSound *snd = (bSound *)id;
192  BLO_expand(expander, snd->ipo); /* XXX deprecated - old animation system */
193 }
194 
196  .id_code = ID_SO,
197  .id_filter = FILTER_ID_SO,
198  .main_listbase_index = INDEX_ID_SO,
199  .struct_size = sizeof(bSound),
200  .name = "Sound",
201  .name_plural = "sounds",
202  .translation_context = BLT_I18NCONTEXT_ID_SOUND,
204  .asset_type_info = NULL,
205 
206  /* A fuzzy case, think NULLified content is OK here... */
207  .init_data = NULL,
208  .copy_data = sound_copy_data,
209  .free_data = sound_free_data,
210  .make_local = NULL,
211  .foreach_id = NULL,
212  .foreach_cache = sound_foreach_cache,
213  .foreach_path = sound_foreach_path,
214  .owner_get = NULL,
215 
216  .blend_write = sound_blend_write,
217  .blend_read_data = sound_blend_read_data,
218  .blend_read_lib = sound_blend_read_lib,
219  .blend_read_expand = sound_blend_read_expand,
220 
221  .blend_read_undo_preserve = NULL,
222 
223  .lib_override_apply_post = NULL,
224 };
225 
226 #ifdef WITH_AUDASPACE
227 /* evil globals ;-) */
228 static int sound_cfra;
229 static char **audio_device_names = NULL;
230 #endif
231 
233 {
234  UNUSED_VARS_NDEBUG(id);
235  /* This is a bit tricky and not quite reliable, but good enough check.
236  *
237  * We don't want audio system handles to be allocated on an original data-blocks, and only want
238  * them to be allocated on a data-blocks which are result of dependency graph evaluation.
239  *
240  * Data-blocks which are covered by a copy-on-write system of dependency graph will have
241  * LIB_TAG_COPIED_ON_WRITE tag set on them. But if some of data-blocks during its evaluation
242  * decides to re-allocate its nested one (for example, object evaluation could re-allocate mesh
243  * when evaluating modifier stack). Such data-blocks will have
244  * LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT tag set on them.
245  *
246  * Additionally, we also allow data-blocks outside of main database. Those can not be "original"
247  * and could be used as a temporary evaluated result during operations like baking.
248  *
249  * NOTE: We consider ID evaluated if ANY of those flags is set. We do NOT require ALL of them.
250  */
251  BLI_assert(id->tag &
253 }
254 
255 bSound *BKE_sound_new_file(Main *bmain, const char *filepath)
256 {
257  bSound *sound;
258  const char *blendfile_path = BKE_main_blendfile_path(bmain);
259  char str[FILE_MAX];
260 
261  BLI_strncpy(str, filepath, sizeof(str));
262  BLI_path_abs(str, blendfile_path);
263 
264  sound = BKE_libblock_alloc(bmain, ID_SO, BLI_path_basename(filepath), 0);
265  BLI_strncpy(sound->filepath, filepath, FILE_MAX);
266  /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */
267 
268  /* Extract sound specs for bSound */
269  SoundInfo info;
270  bool success = BKE_sound_info_get(bmain, sound, &info);
271  if (success) {
272  sound->samplerate = info.specs.samplerate;
273  sound->audio_channels = info.specs.channels;
274  }
275 
276  sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
277  BLI_spin_init(sound->spinlock);
278 
280 
281  return sound;
282 }
283 
284 bSound *BKE_sound_new_file_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
285 {
286  bSound *sound;
287  char str[FILE_MAX], strtest[FILE_MAX];
288 
289  BLI_strncpy(str, filepath, sizeof(str));
291 
292  /* first search an identical filepath */
293  for (sound = bmain->sounds.first; sound; sound = sound->id.next) {
294  BLI_strncpy(strtest, sound->filepath, sizeof(sound->filepath));
295  BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &sound->id));
296 
297  if (BLI_path_cmp(strtest, str) == 0) {
298  id_us_plus(&sound->id); /* officially should not, it doesn't link here! */
299  if (r_exists) {
300  *r_exists = true;
301  }
302  return sound;
303  }
304  }
305 
306  if (r_exists) {
307  *r_exists = false;
308  }
309  return BKE_sound_new_file(bmain, filepath);
310 }
311 
312 bSound *BKE_sound_new_file_exists(Main *bmain, const char *filepath)
313 {
314  return BKE_sound_new_file_exists_ex(bmain, filepath, NULL);
315 }
316 
317 static void sound_free_audio(bSound *sound)
318 {
319 #ifdef WITH_AUDASPACE
320  if (sound->handle) {
321  AUD_Sound_free(sound->handle);
322  sound->handle = NULL;
323  sound->playback_handle = NULL;
324  }
325 
326  if (sound->cache) {
327  AUD_Sound_free(sound->cache);
328  sound->cache = NULL;
329  }
330 #else
331  UNUSED_VARS(sound);
332 #endif /* WITH_AUDASPACE */
333 }
334 
335 #ifdef WITH_AUDASPACE
336 
337 static const char *force_device = NULL;
338 
339 # ifdef WITH_JACK
341 
342 static void sound_sync_callback(void *data, int mode, float time)
343 {
345  return;
346  }
347  Main *bmain = (Main *)data;
348  sound_jack_sync_callback(bmain, mode, time);
349 }
350 # endif
351 
352 void BKE_sound_force_device(const char *device)
353 {
354  force_device = device;
355 }
356 
357 void BKE_sound_init_once(void)
358 {
359  AUD_initOnce();
360  atexit(BKE_sound_exit_once);
361 }
362 
363 static AUD_Device *sound_device = NULL;
364 
365 void *BKE_sound_get_device(void)
366 {
367  return sound_device;
368 }
369 
370 void BKE_sound_init(Main *bmain)
371 {
372  /* Make sure no instance of the sound system is running, otherwise we get leaks. */
373  BKE_sound_exit();
374 
375  AUD_DeviceSpecs specs;
376  int device, buffersize;
377  const char *device_name;
378 
379  device = U.audiodevice;
380  buffersize = U.mixbufsize;
381  specs.channels = U.audiochannels;
382  specs.format = U.audioformat;
383  specs.rate = U.audiorate;
384 
385  if (force_device == NULL) {
386  int i;
388  device_name = names[0];
389 
390  /* make sure device is within the bounds of the array */
391  for (i = 0; names[i]; i++) {
392  if (i == device) {
393  device_name = names[i];
394  }
395  }
396  }
397  else {
398  device_name = force_device;
399  }
400 
401  if (buffersize < 128) {
402  buffersize = 1024;
403  }
404 
405  if (specs.rate < AUD_RATE_8000) {
406  specs.rate = AUD_RATE_48000;
407  }
408 
409  if (specs.format <= AUD_FORMAT_INVALID) {
410  specs.format = AUD_FORMAT_S16;
411  }
412 
413  if (specs.channels <= AUD_CHANNELS_INVALID) {
414  specs.channels = AUD_CHANNELS_STEREO;
415  }
416 
417  if (!(sound_device = AUD_init(device_name, specs, buffersize, "Blender"))) {
418  sound_device = AUD_init("None", specs, buffersize, "Blender");
419  }
420 
421  BKE_sound_init_main(bmain);
422 }
423 
424 void BKE_sound_init_main(Main *bmain)
425 {
426 # ifdef WITH_JACK
427  if (sound_device) {
428  AUD_setSynchronizerCallback(sound_sync_callback, bmain);
429  }
430 # else
431  UNUSED_VARS(bmain);
432 # endif
433 }
434 
435 void BKE_sound_exit(void)
436 {
437  AUD_exit(sound_device);
438  sound_device = NULL;
439 }
440 
441 void BKE_sound_exit_once(void)
442 {
443  AUD_exit(sound_device);
444  sound_device = NULL;
445  AUD_exitOnce();
446 
447  if (audio_device_names != NULL) {
448  int i;
449  for (i = 0; audio_device_names[i]; i++) {
450  free(audio_device_names[i]);
451  }
452  free(audio_device_names);
453  audio_device_names = NULL;
454  }
455 }
456 
457 /* XXX unused currently */
458 # if 0
459 bSound *BKE_sound_new_buffer(Main *bmain, bSound *source)
460 {
461  bSound *sound = NULL;
462 
463  char name[MAX_ID_NAME + 5];
464  strcpy(name, "buf_");
465  strcpy(name + 4, source->id.name);
466 
467  sound = BKE_libblock_alloc(bmain, ID_SO, name);
468 
469  sound->child_sound = source;
470  sound->type = SOUND_TYPE_BUFFER;
471 
472  sound_load(bmain, sound);
473 
474  return sound;
475 }
476 
477 bSound *BKE_sound_new_limiter(Main *bmain, bSound *source, float start, float end)
478 {
479  bSound *sound = NULL;
480 
481  char name[MAX_ID_NAME + 5];
482  strcpy(name, "lim_");
483  strcpy(name + 4, source->id.name);
484 
485  sound = BKE_libblock_alloc(bmain, ID_SO, name);
486 
487  sound->child_sound = source;
488  sound->start = start;
489  sound->end = end;
490  sound->type = SOUND_TYPE_LIMITER;
491 
492  sound_load(bmain, sound);
493 
494  return sound;
495 }
496 # endif
497 
498 void BKE_sound_cache(bSound *sound)
499 {
500  sound_verify_evaluated_id(&sound->id);
501 
502  if (sound->cache) {
503  AUD_Sound_free(sound->cache);
504  }
505 
506  sound->cache = AUD_Sound_cache(sound->handle);
507  if (sound->cache) {
508  sound->playback_handle = sound->cache;
509  }
510  else {
511  sound->playback_handle = sound->handle;
512  }
513 }
514 
515 void BKE_sound_delete_cache(bSound *sound)
516 {
517  if (sound->cache) {
518  AUD_Sound_free(sound->cache);
519  sound->cache = NULL;
520  sound->playback_handle = sound->handle;
521  }
522 }
523 
524 static void sound_load_audio(Main *bmain, bSound *sound, bool free_waveform)
525 {
526 
527  if (sound->cache) {
528  AUD_Sound_free(sound->cache);
529  sound->cache = NULL;
530  }
531 
532  if (sound->handle) {
533  AUD_Sound_free(sound->handle);
534  sound->handle = NULL;
535  sound->playback_handle = NULL;
536  }
537 
538  if (free_waveform) {
540  }
541 
542 /* XXX unused currently */
543 # if 0
544  switch (sound->type) {
545  case SOUND_TYPE_FILE:
546 # endif
547  {
548  char fullpath[FILE_MAX];
549 
550  /* load sound */
551  PackedFile *pf = sound->packedfile;
552 
553  /* don't modify soundact->sound->filepath, only change a copy */
554  BLI_strncpy(fullpath, sound->filepath, sizeof(fullpath));
555  BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id));
556 
557  /* but we need a packed file then */
558  if (pf) {
559  sound->handle = AUD_Sound_bufferFile((unsigned char *)pf->data, pf->size);
560  }
561  else {
562  /* or else load it from disk */
563  sound->handle = AUD_Sound_file(fullpath);
564  }
565  }
566 /* XXX unused currently */
567 # if 0
568  break;
569  }
570  case SOUND_TYPE_BUFFER:
571  if (sound->child_sound && sound->child_sound->handle) {
572  sound->handle = AUD_bufferSound(sound->child_sound->handle);
573  }
574  break;
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);
578  }
579  break;
580  }
581 # endif
582  if (sound->flags & SOUND_FLAGS_MONO) {
583  void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO);
584  AUD_Sound_free(sound->handle);
585  sound->handle = handle;
586  }
587 
588  if (sound->flags & SOUND_FLAGS_CACHING) {
589  sound->cache = AUD_Sound_cache(sound->handle);
590  }
591 
592  if (sound->cache) {
593  sound->playback_handle = sound->cache;
594  }
595  else {
596  sound->playback_handle = sound->handle;
597  }
598 }
599 
600 void BKE_sound_load(Main *bmain, bSound *sound)
601 {
602  sound_verify_evaluated_id(&sound->id);
603  sound_load_audio(bmain, sound, true);
604 }
605 
606 AUD_Device *BKE_sound_mixdown(const Scene *scene, AUD_DeviceSpecs specs, int start, float volume)
607 {
609  return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS);
610 }
611 
613 {
615 
616  /* should be done in version patch, but this gets called before */
617  if (scene->r.frs_sec_base == 0) {
618  scene->r.frs_sec_base = 1;
619  }
620 
621  scene->sound_scene = AUD_Sequence_create(FPS, scene->audio.flag & AUDIO_MUTE);
622  AUD_Sequence_setSpeedOfSound(scene->sound_scene, scene->audio.speed_of_sound);
623  AUD_Sequence_setDopplerFactor(scene->sound_scene, scene->audio.doppler_factor);
624  AUD_Sequence_setDistanceModel(scene->sound_scene, scene->audio.distance_model);
628 }
629 
631 {
632  if (scene->playback_handle) {
633  AUD_Handle_stop(scene->playback_handle);
634  }
635  if (scene->sound_scrub_handle) {
636  AUD_Handle_stop(scene->sound_scrub_handle);
637  }
638  if (scene->speaker_handles) {
639  void *handle;
640 
641  while ((handle = AUD_getSet(scene->speaker_handles))) {
642  AUD_Sequence_remove(scene->sound_scene, handle);
643  }
644 
646  }
647  if (scene->sound_scene) {
648  AUD_Sequence_free(scene->sound_scene);
649  }
650 }
651 
652 void BKE_sound_lock()
653 {
654  AUD_Device_lock(sound_device);
655 }
656 
657 void BKE_sound_unlock()
658 {
659  AUD_Device_unlock(sound_device);
660 }
661 
663 {
665 
666  if (scene->sound_scene) {
667  AUD_Specs specs;
668 
669  specs.channels = AUD_Device_getChannels(sound_device);
670  specs.rate = AUD_Device_getRate(sound_device);
671 
672  AUD_Sequence_setSpecs(scene->sound_scene, specs);
673  }
674 }
675 
676 void BKE_sound_mute_scene(Scene *scene, int muted)
677 {
679  if (scene->sound_scene) {
680  AUD_Sequence_setMuted(scene->sound_scene, muted);
681  }
682 }
683 
684 void BKE_sound_update_fps(Main *bmain, Scene *scene)
685 {
687 
688  if (scene->sound_scene) {
689  AUD_Sequence_setFPS(scene->sound_scene, FPS);
690  }
691 
693 }
694 
696 {
698 
699  AUD_Sequence_setSpeedOfSound(scene->sound_scene, scene->audio.speed_of_sound);
700  AUD_Sequence_setDopplerFactor(scene->sound_scene, scene->audio.doppler_factor);
701  AUD_Sequence_setDistanceModel(scene->sound_scene, scene->audio.distance_model);
702 }
703 
705  Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip)
706 {
708  if (sequence->scene && scene != sequence->scene) {
709  const double fps = FPS;
710  return AUD_Sequence_add(scene->sound_scene,
711  sequence->scene->sound_scene,
712  startframe / fps,
713  endframe / fps,
714  frameskip / fps);
715  }
716  return NULL;
717 }
718 
720 {
722  sequence,
725  sequence->startofs + sequence->anim_startofs);
726 }
727 
729  Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip)
730 {
732  /* Happens when sequence's sound data-block was removed. */
733  if (sequence->sound == NULL) {
734  return NULL;
735  }
736  sound_verify_evaluated_id(&sequence->sound->id);
737  const double fps = FPS;
738  return AUD_Sequence_add(scene->sound_scene,
739  sequence->sound->playback_handle,
740  startframe / fps,
741  endframe / fps,
742  frameskip / fps + sequence->sound->offset_time);
743 }
744 
746 {
748  sequence,
751  sequence->startofs + sequence->anim_startofs);
752 }
753 
754 void BKE_sound_remove_scene_sound(Scene *scene, void *handle)
755 {
756  AUD_Sequence_remove(scene->sound_scene, handle);
757 }
758 
759 void BKE_sound_mute_scene_sound(void *handle, char mute)
760 {
761  AUD_SequenceEntry_setMuted(handle, mute);
762 }
763 
765  void *handle,
766  int startframe,
767  int endframe,
768  int frameskip,
769  double audio_offset)
770 {
772  const double fps = FPS;
773  AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps + audio_offset);
774 }
775 
777 {
779  if (sequence->scene_sound) {
781  sequence->scene_sound,
784  sequence->startofs + sequence->anim_startofs,
785  0.0);
786  }
787 }
788 
789 void BKE_sound_update_scene_sound(void *handle, bSound *sound)
790 {
791  AUD_SequenceEntry_setSound(handle, sound->playback_handle);
792 }
793 
794 void BKE_sound_set_cfra(int cfra)
795 {
796  sound_cfra = cfra;
797 }
798 
799 void BKE_sound_set_scene_volume(Scene *scene, float volume)
800 {
802  if (scene->sound_scene == NULL) {
803  return;
804  }
805  AUD_Sequence_setAnimationData(scene->sound_scene,
806  AUD_AP_VOLUME,
807  scene->r.cfra,
808  &volume,
810 }
811 
812 void BKE_sound_set_scene_sound_volume(void *handle, float volume, char animated)
813 {
814  AUD_SequenceEntry_setAnimationData(handle, AUD_AP_VOLUME, sound_cfra, &volume, animated);
815 }
816 
817 void BKE_sound_set_scene_sound_pitch(void *handle, float pitch, char animated)
818 {
819  AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PITCH, sound_cfra, &pitch, animated);
820 }
821 
822 void BKE_sound_set_scene_sound_pan(void *handle, float pan, char animated)
823 {
824  AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
825 }
826 
828 {
829  BLI_assert_msg(0, "is not supposed to be used, is weird function.");
830 
831  Scene *scene;
832 
833  for (scene = main->scenes.first; scene; scene = scene->id.next) {
834  SEQ_sound_update(scene, sound);
835  }
836 }
837 
838 static void sound_start_play_scene(Scene *scene)
839 {
841 
842  if (scene->playback_handle) {
843  AUD_Handle_stop(scene->playback_handle);
844  }
845 
847 
848  if ((scene->playback_handle = AUD_Device_play(sound_device, scene->sound_scene, 1))) {
849  AUD_Handle_setLoopCount(scene->playback_handle, -1);
850  }
851 }
852 
853 static double get_cur_time(Scene *scene)
854 {
855  /* We divide by the current framelen to take into account time remapping.
856  * Otherwise we will get the wrong starting time which will break A/V sync.
857  * See T74111 for further details. */
858  return FRA2TIME((scene->r.cfra + scene->r.subframe) / (double)scene->r.framelen);
859 }
860 
862 {
864 
865  AUD_Status status;
866  const double cur_time = get_cur_time(scene);
867 
868  AUD_Device_lock(sound_device);
869 
870  status = scene->playback_handle ? AUD_Handle_getStatus(scene->playback_handle) :
871  AUD_STATUS_INVALID;
872 
873  if (status == AUD_STATUS_INVALID) {
874  sound_start_play_scene(scene);
875 
876  if (!scene->playback_handle) {
877  AUD_Device_unlock(sound_device);
878  return;
879  }
880  }
881 
882  if (status != AUD_STATUS_PLAYING) {
883  AUD_Handle_setPosition(scene->playback_handle, cur_time);
884  AUD_Handle_resume(scene->playback_handle);
885  }
886 
887  if (scene->audio.flag & AUDIO_SYNC) {
888  AUD_playSynchronizer();
889  }
890 
891  AUD_Device_unlock(sound_device);
892 }
893 
895 {
896  if (scene->playback_handle) {
897  AUD_Handle_pause(scene->playback_handle);
898 
899  if (scene->audio.flag & AUDIO_SYNC) {
900  AUD_stopSynchronizer();
901  }
902  }
903 }
904 
905 void BKE_sound_seek_scene(Main *bmain, Scene *scene)
906 {
908 
909  AUD_Status status;
910  bScreen *screen;
911  int animation_playing;
912 
913  const double one_frame = 1.0 / FPS;
914  const double cur_time = FRA2TIME(scene->r.cfra);
915 
916  AUD_Device_lock(sound_device);
917 
918  status = scene->playback_handle ? AUD_Handle_getStatus(scene->playback_handle) :
919  AUD_STATUS_INVALID;
920 
921  if (status == AUD_STATUS_INVALID) {
922  sound_start_play_scene(scene);
923 
924  if (!scene->playback_handle) {
925  AUD_Device_unlock(sound_device);
926  return;
927  }
928 
929  AUD_Handle_pause(scene->playback_handle);
930  }
931 
932  animation_playing = 0;
933  for (screen = bmain->screens.first; screen; screen = screen->id.next) {
934  if (screen->animtimer) {
935  animation_playing = 1;
936  break;
937  }
938  }
939 
940  if (scene->audio.flag & AUDIO_SCRUB && !animation_playing) {
941  AUD_Handle_setPosition(scene->playback_handle, cur_time);
942  if (scene->audio.flag & AUDIO_SYNC) {
943  AUD_seekSynchronizer(scene->playback_handle, cur_time);
944  }
945  AUD_Handle_resume(scene->playback_handle);
946  if (scene->sound_scrub_handle &&
947  AUD_Handle_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) {
948  AUD_Handle_setPosition(scene->sound_scrub_handle, 0);
949  }
950  else {
951  if (scene->sound_scrub_handle) {
952  AUD_Handle_stop(scene->sound_scrub_handle);
953  }
954  scene->sound_scrub_handle = AUD_pauseAfter(scene->playback_handle, one_frame);
955  }
956  }
957  else {
958  if (scene->audio.flag & AUDIO_SYNC) {
959  AUD_seekSynchronizer(scene->playback_handle, cur_time);
960  }
961  else {
962  if (status == AUD_STATUS_PLAYING) {
963  AUD_Handle_setPosition(scene->playback_handle, cur_time);
964  }
965  }
966  }
967 
968  AUD_Device_unlock(sound_device);
969 }
970 
972 {
974 
975  /* Ugly: Blender doesn't like it when the animation is played back during rendering */
976  if (G.is_rendering) {
977  return NAN_FLT;
978  }
979 
980  if (scene->playback_handle) {
981  if (scene->audio.flag & AUDIO_SYNC) {
982  return AUD_getSynchronizerPosition(scene->playback_handle);
983  }
984 
985  return AUD_Handle_getPosition(scene->playback_handle);
986  }
987  return NAN_FLT;
988 }
989 
991 {
993 
994  /* Ugly: Blender doesn't like it when the animation is played back during rendering */
995  if (G.is_rendering) {
996  return -1;
997  }
998 
999  /* In case of a "None" audio device, we have no playback information. */
1000  if (AUD_Device_getRate(sound_device) == AUD_RATE_INVALID) {
1001  return -1;
1002  }
1003 
1004  if (scene->audio.flag & AUDIO_SYNC) {
1005  return AUD_isSynchronizerPlaying();
1006  }
1007 
1008  return -1;
1009 }
1010 
1011 void BKE_sound_free_waveform(bSound *sound)
1012 {
1013  if ((sound->tags & SOUND_TAGS_WAVEFORM_NO_RELOAD) == 0) {
1014  SoundWaveform *waveform = sound->waveform;
1015  if (waveform) {
1016  if (waveform->data) {
1017  MEM_freeN(waveform->data);
1018  }
1019  MEM_freeN(waveform);
1020  }
1021 
1022  sound->waveform = NULL;
1023  }
1024  /* This tag is only valid once. */
1026 }
1027 
1028 void BKE_sound_read_waveform(Main *bmain, bSound *sound, short *stop)
1029 {
1030  bool need_close_audio_handles = false;
1031  if (sound->playback_handle == NULL) {
1032  /* TODO(sergey): Make it fully independent audio handle. */
1033  sound_load_audio(bmain, sound, true);
1034  need_close_audio_handles = true;
1035  }
1036 
1037  AUD_SoundInfo info = AUD_getInfo(sound->playback_handle);
1038  SoundWaveform *waveform = MEM_mallocN(sizeof(SoundWaveform), "SoundWaveform");
1039 
1040  if (info.length > 0) {
1041  int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
1042 
1043  waveform->data = MEM_mallocN(sizeof(float[3]) * length, "SoundWaveform.samples");
1044  waveform->length = AUD_readSound(
1045  sound->playback_handle, waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND, stop);
1046  }
1047  else {
1048  /* Create an empty waveform here if the sound couldn't be
1049  * read. This indicates that reading the waveform is "done",
1050  * whereas just setting sound->waveform to NULL causes other
1051  * code to think the waveform still needs to be created. */
1052  waveform->data = NULL;
1053  waveform->length = 0;
1054  }
1055 
1056  if (*stop) {
1057  if (waveform->data) {
1058  MEM_freeN(waveform->data);
1059  }
1060  MEM_freeN(waveform);
1061  BLI_spin_lock(sound->spinlock);
1062  sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;
1063  BLI_spin_unlock(sound->spinlock);
1064  return;
1065  }
1066 
1067  BKE_sound_free_waveform(sound);
1068 
1069  BLI_spin_lock(sound->spinlock);
1070  sound->waveform = waveform;
1071  sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;
1072  BLI_spin_unlock(sound->spinlock);
1073 
1074  if (need_close_audio_handles) {
1075  sound_free_audio(sound);
1076  }
1077 }
1078 
1079 static void sound_update_base(Scene *scene, Object *object, void *new_set)
1080 {
1081  NlaTrack *track;
1082  NlaStrip *strip;
1083  Speaker *speaker;
1084  float quat[4];
1085 
1087  sound_verify_evaluated_id(&object->id);
1088 
1089  if ((object->type != OB_SPEAKER) || !object->adt) {
1090  return;
1091  }
1092 
1093  for (track = object->adt->nla_tracks.first; track; track = track->next) {
1094  for (strip = track->strips.first; strip; strip = strip->next) {
1095  if (strip->type != NLASTRIP_TYPE_SOUND) {
1096  continue;
1097  }
1098  speaker = (Speaker *)object->data;
1099 
1101  if (speaker->sound) {
1102  AUD_SequenceEntry_move(strip->speaker_handle, (double)strip->start / FPS, FLT_MAX, 0);
1103  }
1104  else {
1105  AUD_Sequence_remove(scene->sound_scene, strip->speaker_handle);
1106  strip->speaker_handle = NULL;
1107  }
1108  }
1109  else {
1110  if (speaker->sound) {
1111  strip->speaker_handle = AUD_Sequence_add(scene->sound_scene,
1112  speaker->sound->playback_handle,
1113  (double)strip->start / FPS,
1114  FLT_MAX,
1115  0);
1116  AUD_SequenceEntry_setRelative(strip->speaker_handle, 0);
1117  }
1118  }
1119 
1120  if (strip->speaker_handle) {
1121  const bool mute = ((strip->flag & NLASTRIP_FLAG_MUTED) || (speaker->flag & SPK_MUTED));
1122  AUD_addSet(new_set, strip->speaker_handle);
1123  AUD_SequenceEntry_setVolumeMaximum(strip->speaker_handle, speaker->volume_max);
1124  AUD_SequenceEntry_setVolumeMinimum(strip->speaker_handle, speaker->volume_min);
1125  AUD_SequenceEntry_setDistanceMaximum(strip->speaker_handle, speaker->distance_max);
1126  AUD_SequenceEntry_setDistanceReference(strip->speaker_handle, speaker->distance_reference);
1127  AUD_SequenceEntry_setAttenuation(strip->speaker_handle, speaker->attenuation);
1128  AUD_SequenceEntry_setConeAngleOuter(strip->speaker_handle, speaker->cone_angle_outer);
1129  AUD_SequenceEntry_setConeAngleInner(strip->speaker_handle, speaker->cone_angle_inner);
1130  AUD_SequenceEntry_setConeVolumeOuter(strip->speaker_handle, speaker->cone_volume_outer);
1131 
1132  mat4_to_quat(quat, object->obmat);
1133  AUD_SequenceEntry_setAnimationData(
1134  strip->speaker_handle, AUD_AP_LOCATION, scene->r.cfra, object->obmat[3], 1);
1135  AUD_SequenceEntry_setAnimationData(
1136  strip->speaker_handle, AUD_AP_ORIENTATION, scene->r.cfra, quat, 1);
1137  AUD_SequenceEntry_setAnimationData(
1138  strip->speaker_handle, AUD_AP_VOLUME, scene->r.cfra, &speaker->volume, 1);
1139  AUD_SequenceEntry_setAnimationData(
1140  strip->speaker_handle, AUD_AP_PITCH, scene->r.cfra, &speaker->pitch, 1);
1141  AUD_SequenceEntry_setSound(strip->speaker_handle, speaker->sound->playback_handle);
1142  AUD_SequenceEntry_setMuted(strip->speaker_handle, mute);
1143  }
1144  }
1145  }
1146 }
1147 
1149 {
1151 
1152  void *new_set = AUD_createSet();
1153  void *handle;
1154  float quat[4];
1155 
1156  /* cheap test to skip looping over all objects (no speakers is a common case) */
1159  object,
1163  sound_update_base(scene, object, new_set);
1164  }
1166  }
1167 
1168  while ((handle = AUD_getSet(scene->speaker_handles))) {
1169  AUD_Sequence_remove(scene->sound_scene, handle);
1170  }
1171 
1172  if (scene->camera) {
1173  mat4_to_quat(quat, scene->camera->obmat);
1174  AUD_Sequence_setAnimationData(
1175  scene->sound_scene, AUD_AP_LOCATION, scene->r.cfra, scene->camera->obmat[3], 1);
1176  AUD_Sequence_setAnimationData(scene->sound_scene, AUD_AP_ORIENTATION, scene->r.cfra, quat, 1);
1177  }
1178 
1180  scene->speaker_handles = new_set;
1181 }
1182 
1183 void *BKE_sound_get_factory(void *sound)
1184 {
1185  return ((bSound *)sound)->playback_handle;
1186 }
1187 
1188 float BKE_sound_get_length(Main *bmain, bSound *sound)
1189 {
1190  if (sound->playback_handle != NULL) {
1191  AUD_SoundInfo info = AUD_getInfo(sound->playback_handle);
1192  return info.length;
1193  }
1194  SoundInfo info;
1195  if (!BKE_sound_info_get(bmain, sound, &info)) {
1196  return 0.0f;
1197  }
1198  return info.length;
1199 }
1200 
1201 char **BKE_sound_get_device_names(void)
1202 {
1203  if (audio_device_names == NULL) {
1204  audio_device_names = AUD_getDeviceNames();
1205  }
1206 
1207  return audio_device_names;
1208 }
1209 
1210 static bool sound_info_from_playback_handle(void *playback_handle, SoundInfo *sound_info)
1211 {
1212  if (playback_handle == NULL) {
1213  return false;
1214  }
1215  AUD_SoundInfo info = AUD_getInfo(playback_handle);
1216  sound_info->specs.channels = (eSoundChannels)info.specs.channels;
1217  sound_info->length = info.length;
1218  sound_info->specs.samplerate = info.specs.rate;
1219  return true;
1220 }
1221 
1222 bool BKE_sound_info_get(struct Main *main, struct bSound *sound, SoundInfo *sound_info)
1223 {
1224  if (sound->playback_handle != NULL) {
1225  return sound_info_from_playback_handle(sound->playback_handle, sound_info);
1226  }
1227  /* TODO(sergey): Make it fully independent audio handle. */
1228  /* Don't free waveforms during non-destructive queries.
1229  * This causes unnecessary recalculation - see T69921 */
1230  sound_load_audio(main, sound, false);
1231  const bool result = sound_info_from_playback_handle(sound->playback_handle, sound_info);
1232  sound_free_audio(sound);
1233  return result;
1234 }
1235 
1236 bool BKE_sound_stream_info_get(struct Main *main,
1237  const char *filepath,
1238  int stream,
1239  SoundStreamInfo *sound_info)
1240 {
1241  const char *blendfile_path = BKE_main_blendfile_path(main);
1242  char str[FILE_MAX];
1243  AUD_Sound *sound;
1244  AUD_StreamInfo *stream_infos;
1245  int stream_count;
1246 
1247  BLI_strncpy(str, filepath, sizeof(str));
1248  BLI_path_abs(str, blendfile_path);
1249 
1250  sound = AUD_Sound_file(str);
1251  if (!sound) {
1252  return false;
1253  }
1254 
1255  stream_count = AUD_Sound_getFileStreams(sound, &stream_infos);
1256 
1257  AUD_Sound_free(sound);
1258 
1259  if (!stream_infos) {
1260  return false;
1261  }
1262 
1263  if ((stream < 0) || (stream >= stream_count)) {
1264  free(stream_infos);
1265  return false;
1266  }
1267 
1268  sound_info->start = stream_infos[stream].start;
1269  sound_info->duration = stream_infos[stream].duration;
1270 
1271  free(stream_infos);
1272 
1273  return true;
1274 }
1275 
1276 #else /* WITH_AUDASPACE */
1277 
1278 # include "BLI_utildefines.h"
1279 
1280 void BKE_sound_force_device(const char *UNUSED(device))
1281 {
1282 }
1284 {
1285 }
1287 {
1288 }
1289 void BKE_sound_exit(void)
1290 {
1291 }
1293 {
1294 }
1296 {
1297 }
1299 {
1300 }
1301 void BKE_sound_load(Main *UNUSED(bmain), bSound *UNUSED(sound))
1302 {
1303 }
1305 {
1306 }
1308 {
1309 }
1310 void BKE_sound_lock(void)
1311 {
1312 }
1314 {
1315 }
1317 {
1318 }
1320 {
1321 }
1323  Sequence *UNUSED(sequence),
1324  int UNUSED(startframe),
1325  int UNUSED(endframe),
1326  int UNUSED(frameskip))
1327 {
1328  return NULL;
1329 }
1331 {
1332  return NULL;
1333 }
1335  Sequence *UNUSED(sequence),
1336  int UNUSED(startframe),
1337  int UNUSED(endframe),
1338  int UNUSED(frameskip))
1339 {
1340  return NULL;
1341 }
1343 {
1344  return NULL;
1345 }
1347 {
1348 }
1349 void BKE_sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute))
1350 {
1351 }
1353  void *UNUSED(handle),
1354  int UNUSED(startframe),
1355  int UNUSED(endframe),
1356  int UNUSED(frameskip),
1357  double UNUSED(audio_offset))
1358 {
1359 }
1361 {
1362 }
1364 {
1365 }
1367 {
1368 }
1370 {
1371 }
1373 {
1374  return NAN_FLT;
1375 }
1377 {
1378  return -1;
1379 }
1381  bSound *sound,
1382  /* NOLINTNEXTLINE: readability-non-const-parameter. */
1383  short *stop)
1384 {
1385  UNUSED_VARS(sound, stop, bmain);
1386 }
1388 {
1389 }
1391 {
1392 }
1394 {
1395 }
1397 {
1398 }
1399 void BKE_sound_update_scene_sound(void *UNUSED(handle), bSound *UNUSED(sound))
1400 {
1401 }
1403 {
1404 }
1406 {
1407 }
1409  float UNUSED(volume),
1410  char UNUSED(animated))
1411 {
1412 }
1413 void BKE_sound_set_scene_sound_pan(void *UNUSED(handle), float UNUSED(pan), char UNUSED(animated))
1414 {
1415 }
1417 {
1418 }
1420  float UNUSED(pitch),
1421  char UNUSED(animated))
1422 {
1423 }
1424 float BKE_sound_get_length(struct Main *UNUSED(bmain), bSound *UNUSED(sound))
1425 {
1426  return 0;
1427 }
1429 {
1430  static char *names[1] = {NULL};
1431  return names;
1432 }
1433 
1435 {
1436 }
1437 
1439  struct bSound *UNUSED(sound),
1440  SoundInfo *UNUSED(sound_info))
1441 {
1442  return false;
1443 }
1444 
1446  const char *UNUSED(filepath),
1447  int UNUSED(stream),
1448  SoundStreamInfo *UNUSED(sound_info))
1449 {
1450  return false;
1451 }
1452 
1453 #endif /* WITH_AUDASPACE */
1454 
1456 {
1457  scene->sound_scene = NULL;
1461 }
1462 
1464 {
1465  if (scene->sound_scene != NULL) {
1466  return;
1467  }
1469 }
1470 
1472 {
1473  sound->cache = NULL;
1474  sound->playback_handle = NULL;
1475 }
1476 
1478 {
1479  if (sound->cache != NULL) {
1480  return;
1481  }
1482  BKE_sound_load(bmain, sound);
1483 }
1484 
1486 {
1487 #if defined(WITH_AUDASPACE) && defined(WITH_JACK)
1489 #else
1491 #endif
1492 }
1493 
1495 {
1497 
1498  /* Ugly: Blender doesn't like it when the animation is played back during rendering. */
1499  if (G.is_rendering) {
1500  return;
1501  }
1502 
1503  if (mode) {
1505  }
1506  else {
1508  }
1509 #ifdef WITH_AUDASPACE
1510  if (scene->playback_handle != NULL) {
1511  AUD_Handle_setPosition(scene->playback_handle, time);
1512  }
1513 #else
1514  UNUSED_VARS(time);
1515 #endif
1516 }
1517 
1519 {
1520  DEG_debug_print_eval(depsgraph, __func__, sound->id.name, sound);
1521  if (sound->id.recalc & ID_RECALC_AUDIO) {
1522  BKE_sound_load(bmain, sound);
1523  return;
1524  }
1525  BKE_sound_ensure_loaded(bmain, sound);
1526 }
void * AUD_createSet()
Definition: AUD_Set.cpp:12
void * AUD_getSet(void *set)
Definition: AUD_Set.cpp:35
void AUD_addSet(void *set, void *entry)
Definition: AUD_Set.cpp:29
void AUD_destroySet(void *set)
Definition: AUD_Set.cpp:17
char AUD_removeSet(void *set, void *entry)
Definition: AUD_Set.cpp:22
bool BKE_bpath_foreach_path_fixed_process(struct BPathForeachPathData *bpath_data, char *path)
Definition: bpath.c:121
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
Definition: BKE_bpath.h:37
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition: BKE_idtype.h:39
@ IDTYPE_FLAGS_NO_ANIMDATA
Definition: BKE_idtype.h:41
void(* IDTypeForeachCacheFunctionCallback)(struct ID *id, const struct IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data)
Definition: BKE_idtype.h:77
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, int flag) ATTR_WARN_UNUSED_RESULT
Definition: lib_id.c:1050
void id_us_plus(struct ID *id)
Definition: lib_id.c:305
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2008
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)
Definition: packedFile.c:855
void BKE_packedfile_blend_read(struct BlendDataReader *reader, struct PackedFile **pf_p)
Definition: packedFile.c:864
void BKE_packedfile_free(struct PackedFile *pf)
Definition: packedFile.c:140
#define SOUND_WAVE_SAMPLES_PER_SECOND
Definition: BKE_sound.h:13
void(* SoundJackSyncCallback)(struct Main *bmain, int mode, double time)
Definition: BKE_sound.h:183
void * BKE_sound_get_factory(void *sound)
void * BKE_sound_get_device(void)
eSoundChannels
Definition: BKE_sound.h:67
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
#define BLI_INLINE
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:102
#define NAN_FLT
Definition: BLI_math_base.h:63
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
Definition: path_util.c:1653
#define FILE_MAX
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
Definition: path_util.c:897
#define BLI_path_cmp
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
pthread_spinlock_t SpinLock
Definition: BLI_threads.h:110
void BLI_spin_init(SpinLock *spin)
Definition: threads.cc:419
void BLI_spin_unlock(SpinLock *spin)
Definition: threads.cc:452
void BLI_spin_lock(SpinLock *spin)
Definition: threads.cc:433
void BLI_spin_end(SpinLock *spin)
Definition: threads.cc:467
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
bool BLO_read_data_is_undo(BlendDataReader *reader)
Definition: readfile.c:5288
#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)
Definition: writefile.c:1608
#define BLT_I18NCONTEXT_ID_SOUND
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
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
@ ID_RECALC_AUDIO
Definition: DNA_ID.h:848
#define FILTER_ID_SO
Definition: DNA_ID.h:921
@ INDEX_ID_SO
Definition: DNA_ID.h:1002
#define MAX_ID_NAME
Definition: DNA_ID.h:337
#define ID_BLEND_PATH(_bmain, _id)
Definition: DNA_ID.h:559
@ LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT
Definition: DNA_ID.h:730
@ LIB_TAG_COPIED_ON_WRITE
Definition: DNA_ID.h:720
@ LIB_TAG_NO_MAIN
Definition: DNA_ID.h:744
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
@ ID_SO
Definition: DNA_ID_enums.h:64
@ ID_SPK
Definition: DNA_ID_enums.h:63
@ NLASTRIP_FLAG_MUTED
@ NLASTRIP_TYPE_SOUND
Object is a sort of wrapper for general info.
@ OB_SPEAKER
#define AUDIO_SCRUB
#define AUDIO_VOLUME_ANIMATED
#define AUDIO_SYNC
#define AUDIO_MUTE
#define FPS
#define FRA2TIME(a)
@ SOUND_FLAGS_MONO
@ SOUND_FLAGS_CACHING
struct bSound bSound
@ SOUND_TAGS_WAVEFORM_LOADING
@ SOUND_TAGS_WAVEFORM_NO_RELOAD
#define SPK_MUTED
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))
IDTypeInfo IDType_ID_SO
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)
unsigned int U
Definition: btGjkEpa3.h:78
double time
Scene scene
const Depsgraph * depsgraph
void * user_data
DEGForeachIDComponentCallback callback
#define str(s)
#define pf(_x, _i)
Prefetch 64.
Definition: gim_memory.h:48
static char ** names
Definition: makesdna.c:65
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
#define G(x, y, z)
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)
Definition: strip_time.c:506
int SEQ_time_right_handle_frame_get(const Scene *scene, const Sequence *seq)
Definition: strip_time.c:515
ListBase nla_tracks
float doppler_factor
float speed_of_sound
eBPathForeachFlag flag
Definition: BKE_bpath.h:78
unsigned int id_session_uuid
Definition: BKE_idtype.h:46
short id_code
Definition: BKE_idtype.h:114
Definition: DNA_ID.h:368
int tag
Definition: DNA_ID.h:387
struct Library * lib
Definition: DNA_ID.h:372
int recalc
Definition: DNA_ID.h:390
void * next
Definition: DNA_ID.h:369
char name[66]
Definition: DNA_ID.h:378
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
ListBase sounds
Definition: BKE_main.h:188
ListBase screens
Definition: BKE_main.h:183
struct NlaStrip * next
void * speaker_handle
ListBase strips
struct NlaTrack * next
float obmat[4][4]
struct AnimData * adt
void * data
float frs_sec_base
void * sound_scrub_handle
void * sound_scene
struct RenderData r
void * speaker_handles
struct Object * camera
struct AudioData audio
void * playback_handle
struct Scene * scene
void * scene_sound
struct bSound * sound
struct SoundInfo::@63 specs
int samplerate
Definition: BKE_sound.h:82
eSoundChannels channels
Definition: BKE_sound.h:81
float length
Definition: BKE_sound.h:84
double start
Definition: BKE_sound.h:89
double duration
Definition: BKE_sound.h:88
float * data
Definition: BKE_sound.h:27
float cone_angle_outer
float volume_max
float distance_reference
float cone_volume_outer
float distance_max
float attenuation
float volume_min
struct bSound * sound
float cone_angle_inner
struct wmTimer * animtimer
int samplerate
void * playback_handle
struct PackedFile * packedfile
struct PackedFile * newpackedfile
char filepath[1024]
void * handle
struct Ipo * ipo
void * cache
void * spinlock
void * waveform
int audio_channels
short flags
short tags
double offset_time
static void sound_jack_sync_callback(Main *bmain, int mode, double time)
Definition: wm_init_exit.c:186