Sound: Fix 3D sound coming from scene strips
Need to pull in speakers from scene strips and make sure they are properly updated.
This commit is contained in:
parent
bda6f7df48
commit
bf417d640b
Notes:
blender-bot
2023-02-14 06:17:17 +01:00
Referenced by issue #65613, Memory leak in Audaspace with 3D sound
|
@ -27,6 +27,7 @@
|
|||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_iterator.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
|
@ -931,27 +932,26 @@ void BKE_sound_read_waveform(bSound *sound, short *stop)
|
|||
BLI_spin_unlock(sound->spinlock);
|
||||
}
|
||||
|
||||
static void sound_update_base(Scene *scene, Base *base, void *new_set)
|
||||
static void sound_update_base(Scene *scene, Object *object, void *new_set)
|
||||
{
|
||||
Object *ob = base->object;
|
||||
NlaTrack *track;
|
||||
NlaStrip *strip;
|
||||
Speaker *speaker;
|
||||
float quat[4];
|
||||
|
||||
sound_verify_evaluated_id(&scene->id);
|
||||
sound_verify_evaluated_id(&ob->id);
|
||||
sound_verify_evaluated_id(&object->id);
|
||||
|
||||
if ((ob->type != OB_SPEAKER) || !ob->adt) {
|
||||
if ((object->type != OB_SPEAKER) || !object->adt) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (track = ob->adt->nla_tracks.first; track; track = track->next) {
|
||||
for (track = object->adt->nla_tracks.first; track; track = track->next) {
|
||||
for (strip = track->strips.first; strip; strip = strip->next) {
|
||||
if (strip->type != NLASTRIP_TYPE_SOUND) {
|
||||
continue;
|
||||
}
|
||||
speaker = (Speaker *)ob->data;
|
||||
speaker = (Speaker *)object->data;
|
||||
|
||||
if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) {
|
||||
if (speaker->sound) {
|
||||
|
@ -985,9 +985,9 @@ static void sound_update_base(Scene *scene, Base *base, void *new_set)
|
|||
AUD_SequenceEntry_setConeAngleInner(strip->speaker_handle, speaker->cone_angle_inner);
|
||||
AUD_SequenceEntry_setConeVolumeOuter(strip->speaker_handle, speaker->cone_volume_outer);
|
||||
|
||||
mat4_to_quat(quat, ob->obmat);
|
||||
mat4_to_quat(quat, object->obmat);
|
||||
AUD_SequenceEntry_setAnimationData(
|
||||
strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
|
||||
strip->speaker_handle, AUD_AP_LOCATION, CFRA, object->obmat[3], 1);
|
||||
AUD_SequenceEntry_setAnimationData(
|
||||
strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
|
||||
AUD_SequenceEntry_setAnimationData(
|
||||
|
@ -1005,25 +1005,20 @@ void BKE_sound_update_scene(Depsgraph *depsgraph, Scene *scene)
|
|||
{
|
||||
sound_verify_evaluated_id(&scene->id);
|
||||
|
||||
Base *base;
|
||||
Scene *sce_it;
|
||||
|
||||
void *new_set = AUD_createSet();
|
||||
void *handle;
|
||||
float quat[4];
|
||||
|
||||
/* cheap test to skip looping over all objects (no speakers is a common case) */
|
||||
if (DEG_id_type_any_exists(depsgraph, ID_SPK)) {
|
||||
for (ViewLayer *view_layer = scene->view_layers.first; view_layer;
|
||||
view_layer = view_layer->next) {
|
||||
for (base = view_layer->object_bases.first; base; base = base->next) {
|
||||
sound_update_base(scene, base, new_set);
|
||||
}
|
||||
}
|
||||
|
||||
for (SETLOOPER_SET_ONLY(scene, sce_it, base)) {
|
||||
sound_update_base(scene, base, new_set);
|
||||
DEG_OBJECT_ITER_BEGIN (depsgraph,
|
||||
object,
|
||||
(DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
|
||||
DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY |
|
||||
DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET)) {
|
||||
sound_update_base(scene, object, new_set);
|
||||
}
|
||||
DEG_OBJECT_ITER_END;
|
||||
}
|
||||
|
||||
while ((handle = AUD_getSet(scene->speaker_handles))) {
|
||||
|
|
|
@ -79,6 +79,7 @@ extern "C" {
|
|||
#include "BKE_image.h"
|
||||
#include "BKE_key.h"
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_mask.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_mesh.h"
|
||||
|
@ -1597,10 +1598,12 @@ void DepsgraphNodeBuilder::build_scene_sequencer(Scene *scene)
|
|||
if (seq->scene != NULL) {
|
||||
build_scene_parameters(seq->scene);
|
||||
}
|
||||
if (seq->type == SEQ_TYPE_SCENE && seq->flag & SEQ_SCENE_STRIPS) {
|
||||
if (seq->scene != NULL) {
|
||||
if (seq->type == SEQ_TYPE_SCENE && seq->scene != NULL) {
|
||||
if (seq->flag & SEQ_SCENE_STRIPS) {
|
||||
build_scene_sequencer(seq->scene);
|
||||
}
|
||||
ViewLayer *sequence_view_layer = BKE_view_layer_default_render(seq->scene);
|
||||
build_scene_speakers(seq->scene, sequence_view_layer);
|
||||
}
|
||||
/* TODO(sergey): Movie clip, scene, camera, mask. */
|
||||
}
|
||||
|
@ -1615,6 +1618,18 @@ void DepsgraphNodeBuilder::build_scene_audio(Scene *scene)
|
|||
add_operation_node(&scene->id, NodeType::AUDIO, OperationCode::SOUND_EVAL);
|
||||
}
|
||||
|
||||
void DepsgraphNodeBuilder::build_scene_speakers(Scene * /*scene*/, ViewLayer *view_layer)
|
||||
{
|
||||
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
||||
Object *object = base->object;
|
||||
if (object->type != OB_SPEAKER || !need_pull_base_into_graph(base)) {
|
||||
continue;
|
||||
}
|
||||
/* NOTE: Can not use base because it does not belong to a current view layer. */
|
||||
build_object(-1, base->object, DEG_ID_LINKED_INDIRECTLY, true);
|
||||
}
|
||||
}
|
||||
|
||||
/* **** ID traversal callbacks functions **** */
|
||||
|
||||
void DepsgraphNodeBuilder::modifier_walk(void *user_data,
|
||||
|
|
|
@ -214,6 +214,7 @@ class DepsgraphNodeBuilder : public DepsgraphBuilder {
|
|||
void build_sound(bSound *sound);
|
||||
void build_scene_sequencer(Scene *scene);
|
||||
void build_scene_audio(Scene *scene);
|
||||
void build_scene_speakers(Scene *scene, ViewLayer *view_layer);
|
||||
|
||||
/* Per-ID information about what was already in the dependency graph.
|
||||
* Allows to re-use certain values, to speed up following evaluation. */
|
||||
|
|
|
@ -76,6 +76,7 @@ extern "C" {
|
|||
#include "BKE_fcurve.h"
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_key.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_mball.h"
|
||||
#include "BKE_modifier.h"
|
||||
|
@ -2349,12 +2350,14 @@ void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene)
|
|||
/* This is to support 3D audio. */
|
||||
has_audio_strips = true;
|
||||
}
|
||||
if (seq->type == SEQ_TYPE_SCENE && seq->flag & SEQ_SCENE_STRIPS) {
|
||||
if (seq->scene != NULL) {
|
||||
if (seq->type == SEQ_TYPE_SCENE && seq->scene != NULL) {
|
||||
if (seq->flag & SEQ_SCENE_STRIPS) {
|
||||
build_scene_sequencer(seq->scene);
|
||||
ComponentKey sequence_scene_audio_key(&seq->scene->id, NodeType::AUDIO);
|
||||
add_relation(sequence_scene_audio_key, scene_audio_key, "Sequence Audio -> Scene Audio");
|
||||
}
|
||||
ViewLayer *sequence_view_layer = BKE_view_layer_default_render(seq->scene);
|
||||
build_scene_speakers(seq->scene, sequence_view_layer);
|
||||
}
|
||||
/* TODO(sergey): Movie clip, camera, mask. */
|
||||
}
|
||||
|
@ -2368,6 +2371,17 @@ void DepsgraphRelationBuilder::build_scene_audio(Scene * /*scene*/)
|
|||
{
|
||||
}
|
||||
|
||||
void DepsgraphRelationBuilder::build_scene_speakers(Scene * /*scene*/, ViewLayer *view_layer)
|
||||
{
|
||||
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
|
||||
Object *object = base->object;
|
||||
if (object->type != OB_SPEAKER || !need_pull_base_into_graph(base)) {
|
||||
continue;
|
||||
}
|
||||
build_object(NULL, base->object);
|
||||
}
|
||||
}
|
||||
|
||||
void DepsgraphRelationBuilder::build_copy_on_write_relations()
|
||||
{
|
||||
for (IDNode *id_node : graph_->id_nodes) {
|
||||
|
|
|
@ -275,6 +275,7 @@ class DepsgraphRelationBuilder : public DepsgraphBuilder {
|
|||
void build_sound(bSound *sound);
|
||||
void build_scene_sequencer(Scene *scene);
|
||||
void build_scene_audio(Scene *scene);
|
||||
void build_scene_speakers(Scene *scene, ViewLayer *view_layer);
|
||||
|
||||
void build_nested_datablock(ID *owner, ID *id);
|
||||
void build_nested_nodetree(ID *owner, bNodeTree *ntree);
|
||||
|
|
Loading…
Reference in New Issue