mirror of
https://github.com/mpv-player/mpv
synced 2025-04-25 04:39:47 +00:00
ao_null: add option for simulated device speed
Helps with testing and debugging.
This commit is contained in:
parent
76eca81455
commit
3cd1cfb51c
@ -178,6 +178,11 @@ Available audio output drivers are:
|
|||||||
``outburst``
|
``outburst``
|
||||||
Simulated chunk size in samples.
|
Simulated chunk size in samples.
|
||||||
|
|
||||||
|
``speed``
|
||||||
|
Simulated audio playback speed as a multiplier. Usually, a real audio
|
||||||
|
device will not go exactly as fast as the system clock. It will deviate
|
||||||
|
just a little, and this option helps simulating this.
|
||||||
|
|
||||||
``pcm``
|
``pcm``
|
||||||
Raw PCM/WAVE file writer audio output
|
Raw PCM/WAVE file writer audio output
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ struct priv {
|
|||||||
|
|
||||||
int untimed;
|
int untimed;
|
||||||
float bufferlen; // seconds
|
float bufferlen; // seconds
|
||||||
|
float speed; // multiplier
|
||||||
|
|
||||||
// Minimal unit of audio samples that can be written at once. If play() is
|
// Minimal unit of audio samples that can be written at once. If play() is
|
||||||
// called with sizes not aligned to this, a rounded size will be returned.
|
// called with sizes not aligned to this, a rounded size will be returned.
|
||||||
@ -66,7 +67,7 @@ static void drain(struct ao *ao)
|
|||||||
|
|
||||||
double now = mp_time_sec();
|
double now = mp_time_sec();
|
||||||
if (priv->buffered > 0) {
|
if (priv->buffered > 0) {
|
||||||
priv->buffered -= (now - priv->last_time) * ao->samplerate;
|
priv->buffered -= (now - priv->last_time) * ao->samplerate * priv->speed;
|
||||||
if (priv->buffered < 0) {
|
if (priv->buffered < 0) {
|
||||||
if (!priv->playing_final)
|
if (!priv->playing_final)
|
||||||
MP_ERR(ao, "buffer underrun\n");
|
MP_ERR(ao, "buffer underrun\n");
|
||||||
@ -101,7 +102,7 @@ static void uninit(struct ao *ao, bool cut_audio)
|
|||||||
{
|
{
|
||||||
struct priv *priv = ao->priv;
|
struct priv *priv = ao->priv;
|
||||||
if (!cut_audio && !priv->paused)
|
if (!cut_audio && !priv->paused)
|
||||||
mp_sleep_us(1000.0 * 1000.0 * priv->buffered / ao->samplerate);
|
mp_sleep_us(1000000.0 * priv->buffered / ao->samplerate / priv->speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop playing and empty buffers (for seeking/pause)
|
// stop playing and empty buffers (for seeking/pause)
|
||||||
@ -165,6 +166,9 @@ static float get_delay(struct ao *ao)
|
|||||||
struct priv *priv = ao->priv;
|
struct priv *priv = ao->priv;
|
||||||
|
|
||||||
drain(ao);
|
drain(ao);
|
||||||
|
|
||||||
|
// Note how get_delay returns the delay in audio device time (instead of
|
||||||
|
// adjusting for speed), since most AOs seem to also do that.
|
||||||
return priv->buffered / (double)ao->samplerate;
|
return priv->buffered / (double)ao->samplerate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,11 +189,13 @@ const struct ao_driver audio_out_null = {
|
|||||||
.priv_defaults = &(const struct priv) {
|
.priv_defaults = &(const struct priv) {
|
||||||
.bufferlen = 0.2,
|
.bufferlen = 0.2,
|
||||||
.outburst = 256,
|
.outburst = 256,
|
||||||
|
.speed = 1,
|
||||||
},
|
},
|
||||||
.options = (const struct m_option[]) {
|
.options = (const struct m_option[]) {
|
||||||
OPT_FLAG("untimed", untimed, 0),
|
OPT_FLAG("untimed", untimed, 0),
|
||||||
OPT_FLOATRANGE("buffer", bufferlen, 0, 0, 100),
|
OPT_FLOATRANGE("buffer", bufferlen, 0, 0, 100),
|
||||||
OPT_INTRANGE("outburst", outburst, 0, 1, 100000),
|
OPT_INTRANGE("outburst", outburst, 0, 1, 100000),
|
||||||
|
OPT_FLOATRANGE("speed", speed, 0, 0, 10000),
|
||||||
{0}
|
{0}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user