summaryrefslogtreecommitdiffstats
path: root/gst/audiofx
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-01-24 18:28:06 +0100
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-01-24 18:30:55 +0100
commitfb8a2b359d49480ac118578bf9090405674175c5 (patch)
tree1e03f723e358a0257e2e6a47c4be3eb0913afe2f /gst/audiofx
parentba0e0a6e1479ed75256e131596b8a2987e0bb634 (diff)
Save some allocations if the echo delay is increased often
Save some allocations if the echo delay is increased often during playback by always allocating enough memory to hold data up to the next complete second, i.e. in the worst case allocate memory for one additional second.
Diffstat (limited to 'gst/audiofx')
-rw-r--r--gst/audiofx/audioecho.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/gst/audiofx/audioecho.c b/gst/audiofx/audioecho.c
index 451506d6..dd209a23 100644
--- a/gst/audiofx/audioecho.c
+++ b/gst/audiofx/audioecho.c
@@ -188,7 +188,10 @@ gst_audio_echo_set_property (GObject * object, guint prop_id,
if (self->buffer && rate > 0) {
guint new_echo =
MAX (gst_util_uint64_scale (self->delay, rate, GST_SECOND), 1);
- guint new_size = new_echo * width * channels;
+ guint new_size_frames = MAX (new_echo,
+ gst_util_uint64_scale (self->delay + (GST_SECOND -
+ self->delay % GST_SECOND), rate, GST_SECOND));
+ guint new_size = new_size_frames * width * channels;
if (new_size > self->buffer_size) {
guint i;
@@ -203,7 +206,8 @@ gst_audio_echo_set_property (GObject * object, guint prop_id,
self->buffer_pos) % self->buffer_size_frames) *
width * channels], channels * width);
}
- self->buffer_size_frames = self->delay_frames = new_echo;
+ self->buffer_size_frames = new_size_frames;
+ self->delay_frames = new_echo;
self->buffer_pos = 0;
}
} else if (self->buffer) {
@@ -353,14 +357,18 @@ gst_audio_echo_transform_ip (GstBaseTransform * base, GstBuffer * buf)
if (self->buffer == NULL) {
guint width, rate, channels;
+
width = GST_AUDIO_FILTER (self)->format.width / 8;
rate = GST_AUDIO_FILTER (self)->format.rate;
channels = GST_AUDIO_FILTER (self)->format.channels;
self->delay_frames =
MAX (gst_util_uint64_scale (self->delay, rate, GST_SECOND), 1);
+ self->buffer_size_frames =
+ MAX (self->delay_frames,
+ gst_util_uint64_scale (self->delay + (GST_SECOND -
+ self->delay % GST_SECOND), rate, GST_SECOND));
- self->buffer_size_frames = MAX (self->delay_frames, 1000);
self->buffer_size = self->buffer_size_frames * width * channels;
self->buffer = g_malloc0 (self->buffer_size);
self->buffer_pos = 0;