[vlc-devel] [RFC PATCH 6/7] demux: mock: audio: output a sine wave by default
Thomas Guillem
thomas at gllm.fr
Fri Aug 14 15:18:06 CEST 2020
---
modules/demux/Makefile.am | 1 +
modules/demux/mock.c | 50 ++++++++++++++++++++++++++++++++++++---
2 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 0f588606248..1e443ee10ab 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -509,4 +509,5 @@ demux_LTLIBRARIES += libnoseek_plugin.la
libdemux_mock_plugin_la_SOURCES = demux/mock.c
libdemux_mock_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
+libdemux_mock_plugin_la_LIBADD = $(LIBM)
noinst_LTLIBRARIES += libdemux_mock_plugin.la
diff --git a/modules/demux/mock.c b/modules/demux/mock.c
index 1dffe4d75cc..3e40de176d3 100644
--- a/modules/demux/mock.c
+++ b/modules/demux/mock.c
@@ -112,13 +112,22 @@ var_Read_unsigned(const char *psz)
return value >= 0 && value < UINT_MAX ? value : UINT_MAX;
}
+static float
+var_Read_float(const char *psz)
+{
+ return atof(psz);
+}
+
#define OPTIONS_AUDIO(Y) \
Y(audio, packetized, bool, add_bool, Bool, true) \
Y(audio, add_track_at, vlc_tick_t, add_integer, Integer, VLC_TICK_INVALID) \
Y(audio, channels, unsigned, add_integer, Unsigned, 2) \
Y(audio, format, vlc_fourcc_t, add_string, Fourcc, "f32l") \
Y(audio, rate, unsigned, add_integer, Unsigned, 44100) \
- Y(audio, sample_length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(40) )
+ Y(audio, sample_length, vlc_tick_t, add_integer, Integer, VLC_TICK_FROM_MS(40)) \
+ Y(audio, sinewave, bool, add_bool, Bool, true) \
+ Y(audio, sinewave_frequency, unsigned, add_integer, Integer, 500) \
+ Y(audio, sinewave_amplitude, float, add_float, Float, 0.2)
#define OPTIONS_VIDEO(Y) \
Y(video, packetized, bool, add_bool, Bool, true)\
@@ -440,6 +449,27 @@ Control(demux_t *demux, int query, va_list args)
}
}
+static void
+GenerateAudioSineWave(demux_t *demux, struct mock_track *track, block_t *block)
+{
+ struct demux_sys *sys = demux->p_sys;
+ float *out = (float *) block->p_buffer;
+ double delta = 1 / (double) track->fmt.audio.i_rate;
+ double audio_pts_sec = sys->audio_pts / (double) CLOCK_FREQ;
+
+ assert(track->fmt.audio.i_format == VLC_CODEC_FL32);
+
+ for (unsigned si = 0; si < block->i_nb_samples; ++si)
+ {
+ double value = track->audio.sinewave_amplitude
+ * sin(2 * M_PI * track->audio.sinewave_frequency * audio_pts_sec);
+ audio_pts_sec += delta;
+
+ for (unsigned ci = 0; ci < track->fmt.audio.i_channels; ++ci)
+ *out++ = value;
+ }
+}
+
static block_t *
CreateAudioBlock(demux_t *demux, struct mock_track *track, vlc_tick_t length)
{
@@ -450,9 +480,14 @@ CreateAudioBlock(demux_t *demux, struct mock_track *track, vlc_tick_t length)
block_t *b = block_Alloc(bytes);
if (!b)
return NULL;
- memset(b->p_buffer, 0, b->i_buffer);
+ b->i_nb_samples = samples;
+
+ if (track->audio.sinewave)
+ GenerateAudioSineWave(demux, track, b);
+ else
+ memset(b->p_buffer, 0, b->i_buffer);
+
return b;
- (void) demux;
}
struct video_block
@@ -647,6 +682,15 @@ ConfigureAudioTrack(demux_t *demux,
return VLC_EGENERIC;
}
+ if (options->sinewave && options->format != VLC_CODEC_FL32)
+ {
+ /* We could support every formats if we plug an audio converter, but
+ * this may be overkill for a mock module */
+ msg_Err(demux, "audio sinewave works only with fl32 format");
+ return VLC_EGENERIC;
+ }
+
+
uint16_t physical_channels = 0;
switch (options->channels)
{
--
2.28.0
More information about the vlc-devel
mailing list