Revision: 38788
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38788
Author: nexyon
Date: 2011-07-28 13:58:59 +0000 (Thu, 28 Jul 2011)
Log Message:
-----------
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for
reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to
the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range
[-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1
right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume
property (animatable!), Update/Bake buttons for animation problems, moved
sampling rate and channel count here
Modified Paths:
--------------
branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerFactory.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.h
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.h
branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_game.py
branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_render.py
branches/soc-2011-pepper/release/scripts/startup/bl_ui/properties_scene.py
branches/soc-2011-pepper/release/scripts/startup/bl_ui/space_sequencer.py
branches/soc-2011-pepper/source/blender/blenkernel/BKE_fcurve.h
branches/soc-2011-pepper/source/blender/blenkernel/BKE_sound.h
branches/soc-2011-pepper/source/blender/blenkernel/intern/fcurve.c
branches/soc-2011-pepper/source/blender/blenkernel/intern/scene.c
branches/soc-2011-pepper/source/blender/blenkernel/intern/seqeffects.c
branches/soc-2011-pepper/source/blender/blenkernel/intern/sequencer.c
branches/soc-2011-pepper/source/blender/blenkernel/intern/sound.c
branches/soc-2011-pepper/source/blender/blenloader/intern/readfile.c
branches/soc-2011-pepper/source/blender/editors/sound/sound_ops.c
branches/soc-2011-pepper/source/blender/makesdna/DNA_scene_types.h
branches/soc-2011-pepper/source/blender/makesdna/DNA_sequence_types.h
branches/soc-2011-pepper/source/blender/makesrna/intern/rna_scene.c
branches/soc-2011-pepper/source/blender/makesrna/intern/rna_sequencer.c
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.cpp
===================================================================
---
branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.cpp
2011-07-28 13:44:36 UTC (rev 38787)
+++
branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.cpp
2011-07-28 13:58:59 UTC (rev 38788)
@@ -32,6 +32,7 @@
#include "AUD_AnimateableProperty.h"
#include <cstring>
+#include <cmath>
AUD_AnimateableProperty::AUD_AnimateableProperty(int count) :
AUD_Buffer(count * sizeof(float)), m_count(count), m_isAnimated(false),
m_changed(false)
@@ -78,16 +79,85 @@
lock();
m_isAnimated = true;
- m_changed = true;
+
+ int pos = getSize() / (sizeof(float) * m_count);
+
assureSize((count + position) * m_count * sizeof(float), true);
- memcpy(getBuffer() + position * m_count, data, count * m_count *
sizeof(float));
+ float* buf = getBuffer();
+
+ memcpy(buf + position * m_count, data, count * m_count * sizeof(float));
+
+ for(int i = pos; i < position; i++)
+ memcpy(buf + i * m_count, buf + (pos - 1) * m_count, m_count *
sizeof(float));
+
unlock();
}
-const float* AUD_AnimateableProperty::read(int position) const
+void AUD_AnimateableProperty::read(float position, float* out)
{
- return getBuffer() + position * m_count;
+ lock();
+
+ if(!m_isAnimated)
+ {
+ memcpy(out, getBuffer(), m_count * sizeof(float));
+ unlock();
+ return;
+ }
+
+ float last = (getSize() / (sizeof(float) * m_count) - 1);
+ float t = position - floor(position);
+
+ if(position > last)
+ {
+ position = last;
+ t = 0;
+ }
+
+ if(t == 0)
+ {
+ memcpy(out, getBuffer() + int(floor(position)) * m_count,
m_count * sizeof(float));
+ }
+ else
+ {
+ int pos = int(floor(position)) * m_count;
+ float t2 = t * t;
+ float t3 = t2 * t;
+ float m0, m1;
+ float* p0;
+ float* p1 = getBuffer() + pos;
+ float* p2;
+ float* p3;
+
+ if(pos == 0)
+ p0 = p1;
+ else
+ p0 = p1 - m_count;
+
+ if(pos > last)
+ {
+ p3 = p2 = p1;
+ }
+ else
+ {
+ p2 = p1 + m_count;
+ if(pos + m_count > last)
+ p3 = p2;
+ else
+ p3 = p2 + m_count;
+ }
+
+ for(int i = 0; i < m_count; i++)
+ {
+ m0 = (p2[i] - p0[i]) / 2.0f;
+ m1 = (p3[i] - p1[i]) / 2.0f;
+
+ out[i] = (2 * t3 - 3 * t2 + 1) * p0[i] + (-2 * t3 + 3 *
t2) * p1[i] +
+ (t3 - 2 * t2 + t) * m0 + (t3 - t2) *
m1;
+ }
+ }
+
+ unlock();
}
bool AUD_AnimateableProperty::isAnimated() const
@@ -97,6 +167,9 @@
bool AUD_AnimateableProperty::hasChanged()
{
+ if(m_isAnimated)
+ return true;
+
bool result = m_changed;
m_changed = false;
return result;
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.h
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_AnimateableProperty.h
2011-07-28 13:58:59 UTC (rev 38788)
@@ -84,7 +84,7 @@
void write(const float* data, int position, int count);
- const float* read(int position) const;
+ void read(float position, float* out);
bool isAnimated() const;
Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.cpp
2011-07-28 13:58:59 UTC (rev 38788)
@@ -938,6 +938,24 @@
(*entry)->setSound(AUD_Sound());
}
+void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType
type, int frame, float* data, char animated)
+{
+ AUD_AnimateableProperty* prop = (*entry)->getAnimProperty(type);
+ if(animated)
+ prop->write(data, frame, 1);
+ else
+ prop->write(data);
+}
+
+void AUD_setSequencerAnimData(AUD_Sound* sequencer,
AUD_AnimateablePropertyType type, int frame, float* data, char animated)
+{
+ AUD_AnimateableProperty* prop =
((AUD_SequencerFactory*)sequencer->get())->getAnimProperty(type);
+ if(animated)
+ prop->write(data, frame, 1);
+ else
+ prop->write(data);
+}
+
void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer)
{
((AUD_SequencerFactory*)sequencer->get())->setSpecs(AUD_device->getSpecs().specs);
Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_C-API.h
2011-07-28 13:58:59 UTC (rev 38788)
@@ -471,6 +471,10 @@
extern void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound);
+extern void AUD_setSequenceAnimData(AUD_SEntry* entry,
AUD_AnimateablePropertyType type, int frame, float* data, char animated);
+
+extern void AUD_setSequencerAnimData(AUD_Sound* sequencer,
AUD_AnimateablePropertyType type, int frame, float* data, char animated);
+
extern void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer);
extern void AUD_setSequencerSpecs(AUD_Sound* sequencer, AUD_Specs specs);
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.cpp
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.cpp
2011-07-28 13:58:59 UTC (rev 38788)
@@ -45,7 +45,7 @@
m_end(end),
m_skip(skip),
m_muted(false),
- m_relative(false),
+ m_relative(true),
m_volume_max(1.0f),
m_volume_min(0),
m_distance_max(std::numeric_limits<float>::max()),
@@ -88,6 +88,25 @@
return m_id;
}
+AUD_AnimateableProperty*
AUD_SequencerEntry::getAnimProperty(AUD_AnimateablePropertyType type)
+{
+ switch(type)
+ {
+ case AUD_AP_VOLUME:
+ return &m_volume;
+ case AUD_AP_PITCH:
+ return &m_pitch;
+ case AUD_AP_PANNING:
+ return &m_panning;
+ case AUD_AP_LOCATION:
+ return &m_location;
+ case AUD_AP_ORIENTATION:
+ return &m_orientation;
+ default:
+ return NULL;
+ }
+}
+
bool AUD_SequencerEntry::isRelative()
{
return m_relative;
Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.h
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerEntry.h
2011-07-28 13:58:59 UTC (rev 38788)
@@ -76,6 +76,8 @@
int getID() const;
+ AUD_AnimateableProperty* getAnimProperty(AUD_AnimateablePropertyType
type);
+
/**
* Checks whether the source location, velocity and orientation are
relative
* to the listener.
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerFactory.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerFactory.cpp
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerFactory.cpp
2011-07-28 13:58:59 UTC (rev 38788)
@@ -48,6 +48,8 @@
{
AUD_Quaternion q;
m_orientation.write(q.get());
+ float f = 1;
+ m_volume.write(&f);
}
AUD_SequencerFactory::~AUD_SequencerFactory()
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.cpp
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.cpp
2011-07-28 13:58:59 UTC (rev 38788)
@@ -66,7 +66,7 @@
m_handle->stop();
}
-void AUD_SequencerHandle::update(float position)
+void AUD_SequencerHandle::update(float position, float frame)
{
if(!m_handle.isNull())
{
@@ -111,8 +111,17 @@
m_status = m_entry->m_status;
}
- // AUD_XXX TODO: Animation data
+ float value;
+ m_entry->m_volume.read(frame, &value);
+ m_handle->setVolume(value);
+ m_entry->m_pitch.read(frame, &value);
+ m_handle->setPitch(value);
+ m_entry->m_panning.read(frame, &value);
+ AUD_SoftwareDevice::setPanning(m_handle.get(), value);
+
+ // AUD_XXX: TODO: animation data
+
if(m_entry->m_muted)
m_handle->setVolume(0);
}
Modified: branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.h
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.h
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerHandle.h
2011-07-28 13:58:59 UTC (rev 38788)
@@ -54,7 +54,7 @@
~AUD_SequencerHandle();
int compare(AUD_Reference<AUD_SequencerEntry> entry) const;
void stop();
- void update(float position);
+ void update(float position, float frame);
void seek(float position);
};
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp
2011-07-28 13:44:36 UTC (rev 38787)
+++ branches/soc-2011-pepper/intern/audaspace/intern/AUD_SequencerReader.cpp
2011-07-28 13:58:59 UTC (rev 38788)
@@ -144,19 +144,27 @@
AUD_Specs specs = m_factory->m_specs;
int pos = 0;
float time = float(m_position) / float(specs.rate);
- int len;
+ float value, frame;
+ int len, cfra;
while(pos < length)
{
- len = int(ceil((int(floor(time * m_factory->m_fps)) + 1) /
m_factory->m_fps * specs.rate)) - m_position;
+ frame = time * m_factory->m_fps;
+ cfra = int(floor(frame));
+
+ len = int(ceil((cfra + 1) / m_factory->m_fps * specs.rate)) -
m_position;
len = AUD_MIN(length - pos, len);
len = AUD_MAX(len, 1);
for(AUD_HandleIterator it = m_handles.begin(); it !=
m_handles.end(); it++)
{
- (*it)->update(time);
+ (*it)->update(time, frame);
}
+ m_factory->m_volume.read(frame, &value);
+
+ m_device.setVolume(value);
+
m_device.read(reinterpret_cast<data_t*>(buffer + specs.channels
* pos), len);
pos += len;
Modified:
branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
===================================================================
--- branches/soc-2011-pepper/intern/audaspace/intern/AUD_SoftwareDevice.cpp
2011-07-28 13:44:36 UTC (rev 38787)
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs