strawberry-audio-player-win.../ext/gstmoodbar/gstfastspectrum.h

97 lines
3.2 KiB
C
Raw Normal View History

2019-04-18 15:03:01 +02:00
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
// Adapted from gstspectrum for Clementine with the following changes:
// - Uses fftw instead of kiss fft (2x faster).
// - Hardcoded to 1 channel (use an audioconvert element to do the work
// instead, simplifies this code a lot).
// - Send output via a callback instead of GST messages (less overhead).
// - Removed all properties except interval and band.
2019-04-18 18:28:11 +02:00
#ifndef GST_MOODBAR_FASTSPECTRUM_H
#define GST_MOODBAR_FASTSPECTRUM_H
2019-04-18 15:03:01 +02:00
#include <functional>
#include <gst/gst.h>
#include <gst/audio/gstaudiofilter.h>
#include <fftw3.h>
G_BEGIN_DECLS
#define GST_TYPE_FASTSPECTRUM (gst_fastspectrum_get_type())
2021-10-30 00:48:21 +02:00
#define GST_FASTSPECTRUM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_FASTSPECTRUM, GstFastSpectrum))
#define GST_IS_FASTSPECTRUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_FASTSPECTRUM))
#define GST_FASTSPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_FASTSPECTRUM, GstFastSpectrumClass))
2019-04-18 15:03:01 +02:00
#define GST_IS_FASTSPECTRUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_FASTSPECTRUM))
class QMutex;
2021-10-30 00:48:21 +02:00
typedef void (*GstFastSpectrumInputData)(const guint8 *in, double *out, guint len, double max_value, guint op, guint nfft);
2019-04-18 15:03:01 +02:00
2022-10-13 22:39:31 +02:00
using OutputCallback = std::function<void(double *magnitudes, int size)>;
2019-04-18 15:03:01 +02:00
struct GstFastSpectrum {
GstAudioFilter parent;
2021-10-30 00:48:21 +02:00
// Properties
guint64 interval; // How many nanoseconds between emits
guint64 frames_per_interval; // How many frames per interval
2019-04-18 15:03:01 +02:00
guint64 frames_todo;
2021-10-30 00:48:21 +02:00
guint bands; // Number of spectrum bands
gboolean multi_channel; // Send separate channel results
2019-04-18 15:03:01 +02:00
2021-10-30 00:48:21 +02:00
guint64 num_frames; // Frame count (1 sample per channel) since last emit
guint64 num_fft; // Number of FFTs since last emit
GstClockTime message_ts; // Starttime for next message
2019-04-18 15:03:01 +02:00
2021-10-30 00:48:21 +02:00
// <private>
2020-10-17 17:29:09 +02:00
bool channel_data_initialized;
2021-10-30 00:48:21 +02:00
double *input_ring_buffer;
double *fft_input;
fftw_complex *fft_output;
double *spect_magnitude;
2019-04-18 15:03:01 +02:00
fftw_plan plan;
guint input_pos;
guint64 error_per_interval;
guint64 accumulated_error;
GMutex lock;
GstFastSpectrumInputData input_data;
OutputCallback output_callback;
};
struct GstFastSpectrumClass {
GstAudioFilterClass parent_class;
// Static lock for creating & destroying FFTW plans.
2021-10-30 00:48:21 +02:00
QMutex *fftw_lock;
2019-04-18 15:03:01 +02:00
};
2021-10-30 00:48:21 +02:00
GType gst_fastspectrum_get_type(void);
2019-04-18 15:03:01 +02:00
G_END_DECLS
2021-10-30 00:48:21 +02:00
#endif // GST_MOODBAR_FASTSPECTRUM_H