Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
a44b510d
Commit
a44b510d
authored
Feb 16, 2012
by
Nicolas George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
af_pan: use libswr for rematrixing.
parent
560b224f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
50 deletions
+24
-50
filters.texi
doc/filters.texi
+0
-3
af_pan.c
libavfilter/af_pan.c
+24
-47
No files found.
doc/filters.texi
View file @
a44b510d
...
...
@@ -384,9 +384,6 @@ The channel remapping will be effective if, and only if:
@itemize
@item gain coefficients are zeroes or ones,
@item only one input per channel output,
@item the number of output channels is supported by libswresample (16 at the
moment)
@c if SWR_CH_MAX changes, fix the line above.
@end itemize
If all these conditions are satisfied, the filter will notify the user ("Pure
...
...
libavfilter/af_pan.c
View file @
a44b510d
...
...
@@ -234,18 +234,29 @@ static int config_props(AVFilterLink *link)
}
}
}
// gains are pure, init the channel mapping
if
(
pan
->
pure_gains
)
{
/* TODO reindent */
// sanity check; can't be done in query_formats since the inlink
// channel layout is unknown at that time
if
(
pan
->
nb_input_channels
>
SWR_CH_MAX
)
{
if
(
pan
->
nb_input_channels
>
SWR_CH_MAX
||
pan
->
nb_output_channels
>
SWR_CH_MAX
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"libswresample support a maximum of %d channels. "
"Feel free to ask for a higher limit.
\n
"
,
SWR_CH_MAX
);
return
AVERROR_PATCHWELCOME
;
}
// init libswresample context
pan
->
swr
=
swr_alloc_set_opts
(
pan
->
swr
,
pan
->
out_channel_layout
,
link
->
format
,
link
->
sample_rate
,
link
->
channel_layout
,
link
->
format
,
link
->
sample_rate
,
0
,
ctx
);
if
(
!
pan
->
swr
)
return
AVERROR
(
ENOMEM
);
// gains are pure, init the channel mapping
if
(
pan
->
pure_gains
)
{
// get channel map from the pure gains
for
(
i
=
0
;
i
<
pan
->
nb_output_channels
;
i
++
)
{
int
ch_id
=
-
1
;
...
...
@@ -258,19 +269,9 @@ static int config_props(AVFilterLink *link)
pan
->
channel_map
[
i
]
=
ch_id
;
}
// init libswresample context
pan
->
swr
=
swr_alloc_set_opts
(
pan
->
swr
,
pan
->
out_channel_layout
,
link
->
format
,
link
->
sample_rate
,
link
->
channel_layout
,
link
->
format
,
link
->
sample_rate
,
0
,
ctx
);
if
(
!
pan
->
swr
)
return
AVERROR
(
ENOMEM
);
av_opt_set_int
(
pan
->
swr
,
"icl"
,
pan
->
out_channel_layout
,
0
);
av_opt_set_int
(
pan
->
swr
,
"uch"
,
pan
->
nb_output_channels
,
0
);
swr_set_channel_mapping
(
pan
->
swr
,
pan
->
channel_map
);
r
=
swr_init
(
pan
->
swr
);
if
(
r
<
0
)
return
r
;
}
else
{
// renormalize
for
(
i
=
0
;
i
<
pan
->
nb_output_channels
;
i
++
)
{
...
...
@@ -289,7 +290,16 @@ static int config_props(AVFilterLink *link)
for
(
j
=
0
;
j
<
pan
->
nb_input_channels
;
j
++
)
pan
->
gain
.
d
[
i
][
j
]
/=
t
;
}
av_opt_set_int
(
pan
->
swr
,
"icl"
,
link
->
channel_layout
,
0
);
av_opt_set_int
(
pan
->
swr
,
"ocl"
,
pan
->
out_channel_layout
,
0
);
swr_set_matrix
(
pan
->
swr
,
pan
->
gain
.
d
[
0
],
pan
->
gain
.
d
[
1
]
-
pan
->
gain
.
d
[
0
]);
}
r
=
swr_init
(
pan
->
swr
);
if
(
r
<
0
)
return
r
;
// summary
for
(
i
=
0
;
i
<
pan
->
nb_output_channels
;
i
++
)
{
cur
=
buf
;
...
...
@@ -331,30 +341,6 @@ static void filter_samples_channel_mapping(PanContext *pan,
swr_convert
(
pan
->
swr
,
outsamples
->
data
,
n
,
(
void
*
)
insamples
->
data
,
n
);
}
static
void
filter_samples_panning
(
PanContext
*
pan
,
AVFilterBufferRef
*
outsamples
,
AVFilterBufferRef
*
insamples
,
int
n
)
{
int
i
,
o
;
/* input */
const
int16_t
*
in
=
(
int16_t
*
)
insamples
->
data
[
0
];
const
int16_t
*
in_end
=
in
+
n
*
pan
->
nb_input_channels
;
/* output */
int16_t
*
out
=
(
int16_t
*
)
outsamples
->
data
[
0
];
for
(;
in
<
in_end
;
in
+=
pan
->
nb_input_channels
)
{
for
(
o
=
0
;
o
<
pan
->
nb_output_channels
;
o
++
)
{
int
v
=
0
;
for
(
i
=
0
;
i
<
pan
->
nb_input_channels
;
i
++
)
v
+=
pan
->
gain
.
i
[
o
][
i
]
*
in
[
i
];
*
(
out
++
)
=
v
>>
8
;
}
}
}
static
void
filter_samples
(
AVFilterLink
*
inlink
,
AVFilterBufferRef
*
insamples
)
{
int
n
=
insamples
->
audio
->
nb_samples
;
...
...
@@ -379,21 +365,12 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFilterFormats
*
formats
;
if
(
pan
->
nb_output_channels
<=
SWR_CH_MAX
)
/* TODO reindent */
pan
->
pure_gains
=
are_gains_pure
(
pan
);
if
(
pan
->
pure_gains
)
{
/* libswr supports any sample and packing formats */
avfilter_set_common_sample_formats
(
ctx
,
avfilter_make_all_formats
(
AVMEDIA_TYPE_AUDIO
));
avfilter_set_common_packing_formats
(
ctx
,
avfilter_make_all_packing_formats
());
pan
->
filter_samples
=
filter_samples_channel_mapping
;
}
else
{
const
enum
AVSampleFormat
sample_fmts
[]
=
{
AV_SAMPLE_FMT_S16
,
-
1
};
const
int
packing_fmts
[]
=
{
AVFILTER_PACKED
,
-
1
};
avfilter_set_common_sample_formats
(
ctx
,
avfilter_make_format_list
(
sample_fmts
));
avfilter_set_common_packing_formats
(
ctx
,
avfilter_make_format_list
(
packing_fmts
));
pan
->
filter_samples
=
filter_samples_panning
;
}
// inlink supports any channel layout
formats
=
avfilter_make_all_channel_layouts
();
...
...
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