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., 51 Franklin St, Fifth Floor, 18 * Boston, MA 02110-1301, 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 typedef void (*GstSpectrumInputData)(const guint8 * in, gfloat * out, 41 guint len, guint channels, gfloat max_value, guint op, guint nfft); 42 43 struct _GstSpectrumChannel 44 { 45 gfloat *input; 46 gfloat *input_tmp; 47 GstFFTF32Complex *freqdata; 48 gfloat *spect_magnitude; /* accumulated mangitude and phase */ 49 gfloat *spect_phase; /* will be scaled by num_fft before sending */ 50 GstFFTF32 *fft_ctx; 51 }; 52 53 struct _GstSpectrum 54 { 55 GstAudioFilter parent; 56 57 /* properties */ 58 gboolean post_messages; /* whether or not to post messages */ 59 gboolean message_magnitude; 60 gboolean message_phase; 61 guint64 interval; /* how many nanoseconds between emits */ 62 guint64 frames_per_interval; /* how many frames per interval */ 63 guint64 frames_todo; 64 guint bands; /* number of spectrum bands */ 65 gint threshold; /* energy level threshold */ 66 gboolean multi_channel; /* send separate channel results */ 67 68 guint64 num_frames; /* frame count (1 sample per channel) 69 * since last emit */ 70 guint64 num_fft; /* number of FFTs since last emit */ 71 GstClockTime message_ts; /* starttime for next message */ 72 73 /* <private> */ 74 GstSpectrumChannel *channel_data; 75 guint num_channels; 76 77 guint input_pos; 78 guint64 error_per_interval; 79 guint64 accumulated_error; 80 81 GMutex lock; 82 83 GstSpectrumInputData input_data; 84 }; 85 86 struct _GstSpectrumClass 87 { 88 GstAudioFilterClass parent_class; 89 }; 90 91 GType gst_spectrum_get_type (void); 92 93 GST_ELEMENT_REGISTER_DECLARE (spectrum); 94 95 G_END_DECLS 96 97 #endif /* __GST_SPECTRUM_H__ */ 98