Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
37d21af0
Commit
37d21af0
authored
Jul 23, 2011
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PulseAudio: more stable resampling scheme
parent
f5b7eea1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
24 deletions
+33
-24
modules/audio_output/pulse.c
modules/audio_output/pulse.c
+33
-24
No files found.
modules/audio_output/pulse.c
View file @
37d21af0
...
...
@@ -173,34 +173,41 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
//msg_Dbg(aout, "desync: %+"PRId64" us (variation: %+"PRId64" us)",
// delta, change);
/* Compute playback sample rate */
const
unsigned
inrate
=
aout
->
output
.
output
.
i_rate
;
/* NOTE: AOUT_MAX_RESAMPLING (10%) is way too high... */
const
int
limit
=
inrate
>>
6
;
if
(
delta
<
-
AOUT_MAX_PTS_DELAY
)
{
if
(
delta
<
-
AOUT_MAX_PTS_DELAY
)
msg_Warn
(
aout
,
"too late by %"
PRId64
" us"
,
-
delta
);
if
(
change
<
0
)
delta
+=
change
;
/* be more severe if really out of sync */
}
else
if
(
delta
>
+
AOUT_MAX_PTS_ADVANCE
)
{
else
if
(
delta
>
+
AOUT_MAX_PTS_ADVANCE
)
msg_Warn
(
aout
,
"too early by %"
PRId64
" us"
,
delta
);
if
(
change
>
0
)
delta
+=
change
;
}
/* Compute playback sample rate */
const
unsigned
inrate
=
aout
->
output
.
output
.
i_rate
;
#define ADJUST_FACTOR 4
#define ADJUST_MAX 1000
/* Hz (max rate variation per call) */
/* This is empirical. Feel free to define something smarter. */
int
outrate
=
inrate
*
delta
/
-
(
CLOCK_FREQ
*
10
);
if
(
16
*
abs
(
outrate
)
<
limit
)
outrate
=
inrate
;
/* favor native rate to avoid resampling */
else
if
(
outrate
>
limit
)
int
adj
=
sys
->
rate
*
(
delta
+
change
)
/
(
CLOCK_FREQ
*
ADJUST_FACTOR
);
/* This avoids too fast rate variation. They sound ugly as hell and they
* make the algorithm unstable (e.g. oscillation around inrate). */
if
(
adj
>
+
ADJUST_MAX
)
adj
=
+
ADJUST_MAX
;
if
(
adj
<
-
ADJUST_MAX
)
adj
=
-
ADJUST_MAX
;
if
(
abs
(
adj
)
<
(
inrate
>>
10
))
adj
=
0
;
/* favor native rate to avoid resampling */
/* This keeps the effective rate within specified range
* (+/-AOUT_MAX_RESAMPLING% - see <vlc_aout.h>) of the nominal rate. */
unsigned
outrate
=
inrate
-
adj
;
const
int
limit
=
inrate
*
AOUT_MAX_RESAMPLING
/
100
;
if
(
outrate
>
inrate
+
limit
)
outrate
=
inrate
+
limit
;
else
if
(
outrate
<
-
limit
)
if
(
outrate
<
inrate
-
limit
)
outrate
=
inrate
-
limit
;
else
outrate
+=
inrate
;
/* Apply adjusted sample rate */
if
(
outrate
==
(
int
)
sys
->
rate
)
if
(
outrate
==
sys
->
rate
)
return
;
pa_operation
*
op
=
pa_stream_update_sample_rate
(
s
,
outrate
,
NULL
,
NULL
);
if
(
unlikely
(
op
==
NULL
))
{
...
...
@@ -208,7 +215,7 @@ static void stream_latency_cb(pa_stream *s, void *userdata)
return
;
}
pa_operation_unref
(
op
);
msg_Dbg
(
aout
,
"changed sample rate to %
d Hz"
,
outrate
);
msg_Dbg
(
aout
,
"changed sample rate to %
u Hz"
,
outrate
);
sys
->
rate
=
outrate
;
}
...
...
@@ -365,11 +372,13 @@ static void Play(aout_instance_t *aout)
float
*
zeroes
=
calloc
(
nb
,
size
);
msg_Dbg
(
aout
,
"prepending %zu zeroes"
,
nb
);
#if 0 /* Fault injector: add delay */
pa_stream_write(s, zeroes, nb * size, NULL, 0, PA_SEEK_RELATIVE);
pa_stream_write(s, zeroes, nb * size, NULL, 0, PA_SEEK_RELATIVE);
#endif
if
(
likely
(
zeroes
!=
NULL
))
#if 1
/* Fault injection: remove this to be too early */
if
(
pa_stream_write
(
s
,
zeroes
,
nb
*
size
,
free
,
0
,
PA_SEEK_RELATIVE
)
<
0
)
#endif
free
(
zeroes
);
}
...
...
@@ -382,7 +391,7 @@ static void Play(aout_instance_t *aout)
msg_Dbg
(
aout
,
"uncorking"
);
}
#if 0 /* Fault injector to
be too late /
test underrun recovery */
#if 0 /* Fault injector to test underrun recovery */
static unsigned u = 0;
if ((++u % 500) == 0) {
msg_Err(aout, "fault injection");
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment