spectrum: add a GstSpecrtumChannel context structure
[platform/upstream/gst-plugins-good.git] / gst / spectrum / gstspectrum.h
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21
22 #ifndef __GST_SPECTRUM_H__
23 #define __GST_SPECTRUM_H__
24
25 #include <gst/gst.h>
26 #include <gst/audio/gstaudiofilter.h>
27 #include <gst/fft/gstfftf32.h>
28
29 G_BEGIN_DECLS
30
31 #define GST_TYPE_SPECTRUM            (gst_spectrum_get_type())
32 #define GST_SPECTRUM(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPECTRUM,GstSpectrum))
33 #define GST_IS_SPECTRUM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPECTRUM))
34 #define GST_SPECTRUM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_SPECTRUM,GstSpectrumClass))
35 #define GST_IS_SPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_SPECTRUM))
36 typedef struct _GstSpectrum GstSpectrum;
37 typedef struct _GstSpectrumClass GstSpectrumClass;
38 typedef struct _GstSpectrumChannel GstSpectrumChannel;
39
40 struct _GstSpectrumChannel
41 {
42   gfloat *input;
43   gfloat *input_tmp;
44   GstFFTF32Complex *freqdata;
45   gfloat *spect_magnitude;      /* accumulated mangitude and phase */
46   gfloat *spect_phase;          /* will be scaled by num_fft before sending */
47   GstFFTF32 *fft_ctx;
48 };
49
50 struct _GstSpectrum
51 {
52   GstAudioFilter parent;
53
54   /* properties */
55   gboolean post_messages;       /* whether or not to post messages */
56   gboolean message_magnitude;
57   gboolean message_phase;
58   guint64 interval;             /* how many nanoseconds between emits */
59   guint64 frames_per_interval;  /* how many frames per interval */
60   guint bands;                  /* number of spectrum bands */
61   gint threshold;               /* energy level treshold */
62
63   guint64 num_frames;           /* frame count (1 sample per channel)
64                                  * since last emit */
65   guint64 num_fft;              /* number of FFTs since last emit */
66   GstClockTime message_ts;      /* starttime for next message */
67
68   /* <private> */
69   GstSpectrumChannel *channel_data;
70
71   guint input_pos;
72   guint64 error_per_interval;
73   guint64 accumulated_error;
74 };
75
76 struct _GstSpectrumClass
77 {
78   GstAudioFilterClass parent_class;
79 };
80
81 GType gst_spectrum_get_type (void);
82
83 G_END_DECLS
84
85 #endif /* __GST_SPECTRUM_H__ */