summaryrefslogtreecommitdiff
path: root/gst/spectrum
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sf.net>2011-03-22 16:29:53 +0200
committerStefan Kost <ensonic@users.sf.net>2011-03-24 11:27:34 +0200
commit3b552ae6f81d134040c1969ee3a1323dbf82df77 (patch)
tree1cc856eb81e16d7c166f99a30aac91d7aa065e40 /gst/spectrum
parent1979b04f464637c7937e34b4197bbdb0575dd83b (diff)
downloadgstreamer-plugins-good-3b552ae6f81d134040c1969ee3a1323dbf82df77.tar.gz
spectrum: simplify the have_interval calculation
Move some of the conditions to the places where the dependent variables change.
Diffstat (limited to 'gst/spectrum')
-rw-r--r--gst/spectrum/gstspectrum.c23
-rw-r--r--gst/spectrum/gstspectrum.h1
2 files changed, 12 insertions, 12 deletions
diff --git a/gst/spectrum/gstspectrum.c b/gst/spectrum/gstspectrum.c
index 135206c9d..cfd4032d9 100644
--- a/gst/spectrum/gstspectrum.c
+++ b/gst/spectrum/gstspectrum.c
@@ -953,6 +953,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
* interval is in ns */
spectrum->frames_per_interval =
gst_util_uint64_scale (spectrum->interval, rate, GST_SECOND);
+ spectrum->frames_todo = spectrum->frames_per_interval;
/* rounding error in ns, aggregated it in accumulated_error */
spectrum->error_per_interval = (spectrum->interval * rate) % GST_SECOND;
if (spectrum->frames_per_interval == 0)
@@ -988,12 +989,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
input_pos = (input_pos + 1) % nfft;
spectrum->num_frames++;
- have_full_interval = (
- (spectrum->accumulated_error < GST_SECOND
- && spectrum->num_frames == spectrum->frames_per_interval) ||
- (spectrum->accumulated_error >= GST_SECOND
- && spectrum->num_frames - 1 == spectrum->frames_per_interval)
- );
+ have_full_interval = (spectrum->num_frames == spectrum->frames_todo);
/* If we have enough frames for an FFT or we have all frames required for
* the interval and we haven't run a FFT, then run an FFT */
@@ -1015,6 +1011,10 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
else
spectrum->accumulated_error += spectrum->error_per_interval;
+ spectrum->frames_todo = spectrum->frames_per_interval;
+ if (spectrum->accumulated_error >= spectrum->frame_time)
+ spectrum->frames_todo++;
+
if (spectrum->post_messages) {
GstMessage *m;
@@ -1051,12 +1051,7 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
input_pos = (input_pos + 1) % nfft;
spectrum->num_frames++;
- have_full_interval = (
- (spectrum->accumulated_error < GST_SECOND
- && spectrum->num_frames == spectrum->frames_per_interval) ||
- (spectrum->accumulated_error >= GST_SECOND
- && spectrum->num_frames - 1 == spectrum->frames_per_interval)
- );
+ have_full_interval = (spectrum->num_frames == spectrum->frames_todo);
/* If we have enough frames for an FFT or we have all frames required for
* the interval and we haven't run a FFT, then run an FFT */
@@ -1082,6 +1077,10 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
else
spectrum->accumulated_error += spectrum->error_per_interval;
+ spectrum->frames_todo = spectrum->frames_per_interval;
+ if (spectrum->accumulated_error >= spectrum->frame_time)
+ spectrum->frames_todo++;
+
if (spectrum->post_messages) {
GstMessage *m;
diff --git a/gst/spectrum/gstspectrum.h b/gst/spectrum/gstspectrum.h
index 60ebd503e..b7e2be3c9 100644
--- a/gst/spectrum/gstspectrum.h
+++ b/gst/spectrum/gstspectrum.h
@@ -61,6 +61,7 @@ struct _GstSpectrum
gboolean message_phase;
guint64 interval; /* how many nanoseconds between emits */
guint64 frames_per_interval; /* how many frames per interval */
+ guint64 frames_todo;
guint bands; /* number of spectrum bands */
gint threshold; /* energy level treshold */
gboolean multi_channel; /* send separate channel results */