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