mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
pitch: refactor some variables names
- use the `GST_PITCH_GET_PRIVATE` accessor when needed - rename `out_seg_rate` to `output_rate` to use the same name as the parameter - rename `seg_arate` to `segment_applied_rate` to improve readability - apply gst-indent to gstpitch.hh/cc Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6247>
This commit is contained in:
parent
7f4c0e6fb1
commit
9f5bb30d3a
2 changed files with 84 additions and 74 deletions
|
@ -37,7 +37,6 @@
|
|||
#include <gst/audio/audio.h>
|
||||
|
||||
#include "gstpitch.hh"
|
||||
#include <math.h>
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (pitch_debug);
|
||||
#define GST_CAT_DEFAULT pitch_debug
|
||||
|
@ -55,7 +54,7 @@ struct _GstPitchPrivate
|
|||
enum
|
||||
{
|
||||
ARG_0,
|
||||
ARG_OUT_RATE,
|
||||
ARG_OUTPUT_RATE,
|
||||
ARG_RATE,
|
||||
ARG_TEMPO,
|
||||
ARG_PITCH
|
||||
|
@ -69,14 +68,14 @@ enum
|
|||
#endif
|
||||
|
||||
#if defined(SOUNDTOUCH_FLOAT_SAMPLES)
|
||||
#define SUPPORTED_CAPS \
|
||||
#define SUPPORTED_CAPS \
|
||||
"audio/x-raw, " \
|
||||
"format = (string) " GST_AUDIO_NE (F32) ", " \
|
||||
"rate = (int) [ 8000, MAX ], " \
|
||||
"channels = (int) [ 1, MAX ], " \
|
||||
"layout = (string) interleaved"
|
||||
#elif defined(SOUNDTOUCH_INTEGER_SAMPLES)
|
||||
#define SUPPORTED_CAPS \
|
||||
#define SUPPORTED_CAPS \
|
||||
"audio/x-raw, " \
|
||||
"format = (string) " GST_AUDIO_NE (S16) ", " \
|
||||
"rate = (int) [ 8000, MAX ], " \
|
||||
|
@ -120,8 +119,7 @@ static gboolean gst_pitch_src_query (GstPad * pad, GstObject * parent,
|
|||
|
||||
#define gst_pitch_parent_class parent_class
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GstPitch, gst_pitch, GST_TYPE_ELEMENT);
|
||||
GST_ELEMENT_REGISTER_DEFINE (pitch, "pitch", GST_RANK_NONE,
|
||||
GST_TYPE_PITCH);
|
||||
GST_ELEMENT_REGISTER_DEFINE (pitch, "pitch", GST_RANK_NONE, GST_TYPE_PITCH);
|
||||
|
||||
static void
|
||||
gst_pitch_class_init (GstPitchClass * klass)
|
||||
|
@ -157,7 +155,7 @@ gst_pitch_class_init (GstPitchClass * klass)
|
|||
(GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
|
||||
G_PARAM_STATIC_STRINGS)));
|
||||
|
||||
g_object_class_install_property (gobject_class, ARG_OUT_RATE,
|
||||
g_object_class_install_property (gobject_class, ARG_OUTPUT_RATE,
|
||||
g_param_spec_float ("output-rate", "Output Rate",
|
||||
"Output rate on downstream segment events", 0.1, 10.0, 1.0,
|
||||
(GParamFlags) (G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE |
|
||||
|
@ -165,8 +163,10 @@ gst_pitch_class_init (GstPitchClass * klass)
|
|||
|
||||
element_class->change_state = GST_DEBUG_FUNCPTR (gst_pitch_change_state);
|
||||
|
||||
gst_element_class_add_static_pad_template (element_class, &gst_pitch_src_template);
|
||||
gst_element_class_add_static_pad_template (element_class, &gst_pitch_sink_template);
|
||||
gst_element_class_add_static_pad_template (element_class,
|
||||
&gst_pitch_src_template);
|
||||
gst_element_class_add_static_pad_template (element_class,
|
||||
&gst_pitch_sink_template);
|
||||
|
||||
gst_element_class_set_static_metadata (element_class, "Pitch controller",
|
||||
"Filter/Effect/Audio", "Control the pitch of an audio stream",
|
||||
|
@ -176,7 +176,9 @@ gst_pitch_class_init (GstPitchClass * klass)
|
|||
static void
|
||||
gst_pitch_init (GstPitch * pitch)
|
||||
{
|
||||
pitch->priv = (GstPitchPrivate *) gst_pitch_get_instance_private (pitch);
|
||||
GstPitchPrivate *priv =
|
||||
(GstPitchPrivate *) gst_pitch_get_instance_private (pitch);
|
||||
GST_PITCH_GET_PRIVATE (pitch) = priv;
|
||||
|
||||
pitch->sinkpad =
|
||||
gst_pad_new_from_static_template (&gst_pitch_sink_template, "sink");
|
||||
|
@ -196,21 +198,21 @@ gst_pitch_init (GstPitch * pitch)
|
|||
GST_PAD_SET_PROXY_CAPS (pitch->sinkpad);
|
||||
gst_element_add_pad (GST_ELEMENT (pitch), pitch->srcpad);
|
||||
|
||||
pitch->priv->st = new soundtouch::SoundTouch ();
|
||||
priv->st = new soundtouch::SoundTouch ();
|
||||
|
||||
pitch->tempo = 1.0;
|
||||
pitch->rate = 1.0;
|
||||
pitch->out_seg_rate = 1.0;
|
||||
pitch->seg_arate = 1.0;
|
||||
pitch->output_rate = 1.0;
|
||||
pitch->segment_applied_rate = 1.0;
|
||||
pitch->pitch = 1.0;
|
||||
pitch->next_buffer_time = GST_CLOCK_TIME_NONE;
|
||||
pitch->next_buffer_offset = 0;
|
||||
|
||||
pitch->priv->st->setRate (pitch->rate);
|
||||
pitch->priv->st->setTempo (pitch->tempo * pitch->seg_arate);
|
||||
pitch->priv->st->setPitch (pitch->pitch);
|
||||
priv->st->setRate (pitch->rate);
|
||||
priv->st->setTempo (pitch->tempo * pitch->segment_applied_rate);
|
||||
priv->st->setPitch (pitch->pitch);
|
||||
|
||||
pitch->priv->stream_time_ratio = 1.0;
|
||||
priv->stream_time_ratio = 1.0;
|
||||
pitch->min_latency = pitch->max_latency = 0;
|
||||
}
|
||||
|
||||
|
@ -219,11 +221,11 @@ static void
|
|||
gst_pitch_dispose (GObject * object)
|
||||
{
|
||||
GstPitch *pitch = GST_PITCH (object);
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
if (pitch->priv->st) {
|
||||
delete pitch->priv->st;
|
||||
|
||||
pitch->priv->st = NULL;
|
||||
if (priv->st) {
|
||||
delete priv->st;
|
||||
priv->st = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
|
@ -243,33 +245,34 @@ gst_pitch_set_property (GObject * object, guint prop_id,
|
|||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstPitch *pitch = GST_PITCH (object);
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
GST_OBJECT_LOCK (pitch);
|
||||
switch (prop_id) {
|
||||
case ARG_TEMPO:
|
||||
pitch->tempo = g_value_get_float (value);
|
||||
pitch->priv->stream_time_ratio =
|
||||
pitch->tempo * pitch->rate * pitch->seg_arate;
|
||||
pitch->priv->st->setTempo (pitch->tempo * pitch->seg_arate);
|
||||
priv->stream_time_ratio =
|
||||
pitch->tempo * pitch->rate * pitch->segment_applied_rate;
|
||||
priv->st->setTempo (pitch->tempo * pitch->segment_applied_rate);
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
gst_pitch_update_duration (pitch);
|
||||
break;
|
||||
case ARG_RATE:
|
||||
pitch->rate = g_value_get_float (value);
|
||||
pitch->priv->stream_time_ratio =
|
||||
pitch->tempo * pitch->rate * pitch->seg_arate;
|
||||
pitch->priv->st->setRate (pitch->rate);
|
||||
priv->stream_time_ratio =
|
||||
pitch->tempo * pitch->rate * pitch->segment_applied_rate;
|
||||
priv->st->setRate (pitch->rate);
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
gst_pitch_update_duration (pitch);
|
||||
break;
|
||||
case ARG_OUT_RATE:
|
||||
case ARG_OUTPUT_RATE:
|
||||
/* Has no effect until the next input segment */
|
||||
pitch->out_seg_rate = g_value_get_float (value);
|
||||
pitch->output_rate = g_value_get_float (value);
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
break;
|
||||
case ARG_PITCH:
|
||||
pitch->pitch = g_value_get_float (value);
|
||||
pitch->priv->st->setPitch (pitch->pitch);
|
||||
priv->st->setPitch (pitch->pitch);
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
break;
|
||||
default:
|
||||
|
@ -293,8 +296,8 @@ gst_pitch_get_property (GObject * object, guint prop_id,
|
|||
case ARG_RATE:
|
||||
g_value_set_float (value, pitch->rate);
|
||||
break;
|
||||
case ARG_OUT_RATE:
|
||||
g_value_set_float (value, pitch->out_seg_rate);
|
||||
case ARG_OUTPUT_RATE:
|
||||
g_value_set_float (value, pitch->output_rate);
|
||||
break;
|
||||
case ARG_PITCH:
|
||||
g_value_set_float (value, pitch->pitch);
|
||||
|
@ -361,14 +364,15 @@ gst_pitch_prepare_buffer (GstPitch * pitch)
|
|||
|
||||
GST_LOG_OBJECT (pitch, "preparing buffer");
|
||||
|
||||
samples = pitch->priv->st->numSamples ();
|
||||
samples = priv->st->numSamples ();
|
||||
if (samples == 0)
|
||||
return NULL;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (samples * pitch->info.bpf);
|
||||
|
||||
gst_buffer_map (buffer, &info, (GstMapFlags) GST_MAP_READWRITE);
|
||||
samples = priv->st->receiveSamples ((soundtouch::SAMPLETYPE *) info.data, samples);
|
||||
samples =
|
||||
priv->st->receiveSamples ((soundtouch::SAMPLETYPE *) info.data, samples);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
if (samples <= 0) {
|
||||
|
@ -391,10 +395,11 @@ static GstFlowReturn
|
|||
gst_pitch_flush_buffer (GstPitch * pitch, gboolean send)
|
||||
{
|
||||
GstBuffer *buffer;
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
if (pitch->priv->st->numUnprocessedSamples() != 0) {
|
||||
if (priv->st->numUnprocessedSamples () != 0) {
|
||||
GST_DEBUG_OBJECT (pitch, "flushing buffer");
|
||||
pitch->priv->st->flush ();
|
||||
priv->st->flush ();
|
||||
}
|
||||
|
||||
if (!send)
|
||||
|
@ -429,8 +434,10 @@ gst_pitch_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|||
gfloat stream_time_ratio;
|
||||
guint32 seqnum;
|
||||
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
GST_OBJECT_LOCK (pitch);
|
||||
stream_time_ratio = pitch->priv->stream_time_ratio;
|
||||
stream_time_ratio = priv->stream_time_ratio;
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
|
||||
gst_event_parse_seek (event, &rate, &format, &flags,
|
||||
|
@ -555,11 +562,12 @@ gst_pitch_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
|
|||
GstClockTime next_buffer_time;
|
||||
|
||||
pitch = GST_PITCH (parent);
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
GST_LOG ("%s query", GST_QUERY_TYPE_NAME (query));
|
||||
|
||||
GST_OBJECT_LOCK (pitch);
|
||||
stream_time_ratio = pitch->priv->stream_time_ratio;
|
||||
stream_time_ratio = priv->stream_time_ratio;
|
||||
next_buffer_time = pitch->next_buffer_time;
|
||||
next_buffer_offset = pitch->next_buffer_offset;
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
|
@ -680,15 +688,17 @@ static gboolean
|
|||
gst_pitch_process_segment (GstPitch * pitch, GstEvent ** event)
|
||||
{
|
||||
gint seqnum;
|
||||
gdouble out_seg_rate, our_arate;
|
||||
gdouble output_rate, segment_applied_rate;
|
||||
gfloat stream_time_ratio;
|
||||
GstSegment seg;
|
||||
|
||||
g_return_val_if_fail (event, FALSE);
|
||||
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
GST_OBJECT_LOCK (pitch);
|
||||
stream_time_ratio = pitch->priv->stream_time_ratio;
|
||||
out_seg_rate = pitch->out_seg_rate;
|
||||
stream_time_ratio = priv->stream_time_ratio;
|
||||
output_rate = pitch->output_rate;
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
|
||||
gst_event_copy_segment (*event, &seg);
|
||||
|
@ -704,14 +714,14 @@ gst_pitch_process_segment (GstPitch * pitch, GstEvent ** event)
|
|||
}
|
||||
|
||||
/* Figure out how much of the incoming 'rate' we'll apply ourselves */
|
||||
our_arate = seg.rate / out_seg_rate;
|
||||
segment_applied_rate = seg.rate / output_rate;
|
||||
/* update the output rate variables */
|
||||
seg.rate = out_seg_rate;
|
||||
seg.applied_rate *= our_arate;
|
||||
seg.rate = output_rate;
|
||||
seg.applied_rate *= segment_applied_rate;
|
||||
|
||||
GST_LOG_OBJECT (pitch->sinkpad, "in segment %" GST_SEGMENT_FORMAT, &seg);
|
||||
|
||||
stream_time_ratio = pitch->tempo * pitch->rate * our_arate;
|
||||
stream_time_ratio = pitch->tempo * pitch->rate * segment_applied_rate;
|
||||
|
||||
if (stream_time_ratio == 0) {
|
||||
GST_LOG_OBJECT (pitch->sinkpad, "stream_time_ratio is zero");
|
||||
|
@ -720,9 +730,9 @@ gst_pitch_process_segment (GstPitch * pitch, GstEvent ** event)
|
|||
|
||||
/* Update the playback rate */
|
||||
GST_OBJECT_LOCK (pitch);
|
||||
pitch->seg_arate = our_arate;
|
||||
pitch->priv->stream_time_ratio = stream_time_ratio;
|
||||
pitch->priv->st->setTempo (pitch->tempo * pitch->seg_arate);
|
||||
pitch->segment_applied_rate = segment_applied_rate;
|
||||
priv->stream_time_ratio = stream_time_ratio;
|
||||
priv->st->setTempo (pitch->tempo * pitch->segment_applied_rate);
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
|
||||
seg.start = (gint64) (seg.start / stream_time_ratio);
|
||||
|
@ -748,20 +758,21 @@ gst_pitch_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|||
GstPitch *pitch;
|
||||
|
||||
pitch = GST_PITCH (parent);
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
GST_LOG_OBJECT (pad, "received %s event", GST_EVENT_TYPE_NAME (event));
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_FLUSH_STOP:
|
||||
gst_pitch_flush_buffer (pitch, FALSE);
|
||||
pitch->priv->st->clear ();
|
||||
priv->st->clear ();
|
||||
pitch->next_buffer_offset = 0;
|
||||
pitch->next_buffer_time = GST_CLOCK_TIME_NONE;
|
||||
pitch->min_latency = pitch->max_latency = 0;
|
||||
break;
|
||||
case GST_EVENT_EOS:
|
||||
gst_pitch_flush_buffer (pitch, TRUE);
|
||||
pitch->priv->st->clear ();
|
||||
priv->st->clear ();
|
||||
pitch->min_latency = pitch->max_latency = 0;
|
||||
break;
|
||||
case GST_EVENT_SEGMENT:
|
||||
|
@ -772,7 +783,7 @@ gst_pitch_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
|||
GST_PITCH_GET_PRIVATE (pitch)->pending_segment = event;
|
||||
event = NULL;
|
||||
}
|
||||
pitch->priv->st->clear ();
|
||||
priv->st->clear ();
|
||||
pitch->min_latency = pitch->max_latency = 0;
|
||||
break;
|
||||
case GST_EVENT_CAPS:
|
||||
|
@ -802,9 +813,10 @@ static void
|
|||
gst_pitch_update_latency (GstPitch * pitch, GstClockTime timestamp)
|
||||
{
|
||||
GstClockTimeDiff current_latency, min_latency, max_latency;
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
current_latency =
|
||||
(GstClockTimeDiff) (timestamp / pitch->priv->stream_time_ratio) -
|
||||
(GstClockTimeDiff) (timestamp / priv->stream_time_ratio) -
|
||||
pitch->next_buffer_time;
|
||||
|
||||
min_latency = MIN (pitch->min_latency, current_latency);
|
||||
|
@ -881,7 +893,8 @@ gst_pitch_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
|||
|
||||
gst_buffer_map (buffer, &info, GST_MAP_READ);
|
||||
GST_OBJECT_LOCK (pitch);
|
||||
priv->st->putSamples ((soundtouch::SAMPLETYPE *) info.data, info.size / pitch->info.bpf);
|
||||
priv->st->putSamples ((soundtouch::SAMPLETYPE *) info.data,
|
||||
info.size / pitch->info.bpf);
|
||||
GST_OBJECT_UNLOCK (pitch);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -906,6 +919,7 @@ gst_pitch_change_state (GstElement * element, GstStateChange transition)
|
|||
{
|
||||
GstStateChangeReturn ret;
|
||||
GstPitch *pitch = GST_PITCH (element);
|
||||
GstPitchPrivate *priv = GST_PITCH_GET_PRIVATE (pitch);
|
||||
|
||||
switch (transition) {
|
||||
case GST_STATE_CHANGE_NULL_TO_READY:
|
||||
|
@ -913,7 +927,7 @@ gst_pitch_change_state (GstElement * element, GstStateChange transition)
|
|||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
pitch->next_buffer_time = GST_CLOCK_TIME_NONE;
|
||||
pitch->next_buffer_offset = 0;
|
||||
pitch->priv->st->clear ();
|
||||
priv->st->clear ();
|
||||
pitch->min_latency = pitch->max_latency = 0;
|
||||
break;
|
||||
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <gst/audio/audio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_PITCH \
|
||||
(gst_pitch_get_type())
|
||||
#define GST_PITCH(obj) \
|
||||
|
@ -35,55 +34,53 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PITCH))
|
||||
#define GST_IS_PITCH_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PITCH))
|
||||
|
||||
typedef struct _GstPitch GstPitch;
|
||||
typedef struct _GstPitchClass GstPitchClass;
|
||||
typedef struct _GstPitchPrivate GstPitchPrivate;
|
||||
typedef struct _GstPitch GstPitch;
|
||||
typedef struct _GstPitchClass GstPitchClass;
|
||||
typedef struct _GstPitchPrivate GstPitchPrivate;
|
||||
|
||||
|
||||
struct _GstPitch
|
||||
{
|
||||
GstElement element;
|
||||
|
||||
GstPad *srcpad;
|
||||
GstPad *sinkpad;
|
||||
GstPad *srcpad;
|
||||
GstPad *sinkpad;
|
||||
|
||||
/* parameter values */
|
||||
gfloat tempo; /* time stretch
|
||||
gfloat tempo; /* time stretch
|
||||
* change the duration, without affecting the pitch
|
||||
* > 1 makes the stream shorter
|
||||
*/
|
||||
|
||||
gfloat rate; /* change playback rate
|
||||
gfloat rate; /* change playback rate
|
||||
* resample
|
||||
* > 1 makes the stream shorter
|
||||
*/
|
||||
|
||||
gfloat out_seg_rate; /* change output segment rate
|
||||
gfloat output_rate; /* change output segment rate
|
||||
* Affects playback when input
|
||||
* segments have rate != out_rate
|
||||
* segments have rate != output_rate
|
||||
*/
|
||||
|
||||
gfloat pitch; /* change pitch
|
||||
gfloat pitch; /* change pitch
|
||||
* change the pitch without affecting the
|
||||
* duration, stream length doesn't change
|
||||
*/
|
||||
|
||||
gfloat seg_arate; /* Rate to apply from input segment */
|
||||
|
||||
/* values extracted from caps */
|
||||
GstAudioInfo info;
|
||||
GstAudioInfo info;
|
||||
|
||||
/* stream tracking */
|
||||
GstClockTime next_buffer_time;
|
||||
gint64 next_buffer_offset;
|
||||
gfloat segment_applied_rate; /* Rate applied from input segment */
|
||||
GstClockTime next_buffer_time;
|
||||
gint64 next_buffer_offset;
|
||||
|
||||
GstClockTimeDiff min_latency, max_latency;
|
||||
GstClockTimeDiff min_latency, max_latency;
|
||||
|
||||
GstPitchPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GstPitchClass
|
||||
struct _GstPitchClass
|
||||
{
|
||||
GstElementClass parent_class;
|
||||
};
|
||||
|
@ -92,5 +89,4 @@ GType gst_pitch_get_type (void);
|
|||
GST_ELEMENT_REGISTER_DECLARE (pitch);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_PITCH_H__ */
|
||||
|
|
Loading…
Reference in a new issue