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
17d51938
Commit
17d51938
authored
Sep 29, 2011
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swr_test: test planar audio
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
a75b254c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
12 deletions
+49
-12
swresample_test.c
libswresample/swresample_test.c
+49
-12
No files found.
libswresample/swresample_test.c
View file @
17d51938
...
...
@@ -28,7 +28,16 @@
#define ASSERT_LEVEL 2
static
double
get
(
const
void
*
p
,
int
index
,
enum
AVSampleFormat
f
){
static
double
get
(
const
uint8_t
*
a
[],
int
ch
,
int
index
,
int
ch_count
,
enum
AVSampleFormat
f
){
const
uint8_t
*
p
;
if
(
f
>=
0x100
){
f
&=
0xFF
;
p
=
a
[
ch
];
}
else
{
p
=
a
[
0
];
index
=
ch
+
index
*
ch_count
;
}
switch
(
f
){
case
AV_SAMPLE_FMT_U8
:
return
((
const
uint8_t
*
)
p
)[
index
]
/
255
.
0
*
2
-
1
.
0
;
case
AV_SAMPLE_FMT_S16
:
return
((
const
int16_t
*
)
p
)[
index
]
/
32767
.
0
;
...
...
@@ -39,7 +48,15 @@ static double get(const void *p, int index, enum AVSampleFormat f){
}
}
static
void
set
(
void
*
p
,
int
index
,
enum
AVSampleFormat
f
,
double
v
){
static
void
set
(
uint8_t
*
a
[],
int
ch
,
int
index
,
int
ch_count
,
enum
AVSampleFormat
f
,
double
v
){
uint8_t
*
p
;
if
(
f
>=
0x100
){
f
&=
0xFF
;
p
=
a
[
ch
];
}
else
{
p
=
a
[
0
];
index
=
ch
+
index
*
ch_count
;
}
switch
(
f
){
case
AV_SAMPLE_FMT_U8
:
((
uint8_t
*
)
p
)[
index
]
=
(
v
+
1
.
0
)
*
255
.
0
/
2
;
break
;
case
AV_SAMPLE_FMT_S16
:
((
int16_t
*
)
p
)[
index
]
=
v
*
32767
;
break
;
...
...
@@ -68,6 +85,19 @@ AV_CH_LAYOUT_7POINT1_WIDE ,
0
};
static
void
setup_array
(
uint8_t
*
out
[
SWR_CH_MAX
],
uint8_t
*
in
,
enum
AVSampleFormat
format
,
int
samples
){
if
(
format
>=
0x100
){
int
i
;
int
plane_size
=
av_get_bytes_per_sample
(
format
&
0xFF
)
*
samples
;
format
&=
0xFF
;
for
(
i
=
0
;
i
<
SWR_CH_MAX
;
i
++
){
out
[
i
]
=
in
+
i
*
plane_size
;
}
}
else
{
out
[
0
]
=
in
;
}
}
int
main
(
int
argc
,
char
**
argv
){
int
in_sample_rate
,
out_sample_rate
,
ch
,
i
,
in_ch_layout_index
,
out_ch_layout_index
,
osr
;
uint64_t
in_ch_layout
,
out_ch_layout
;
...
...
@@ -76,6 +106,11 @@ int main(int argc, char **argv){
uint8_t
array_in
[
SAMPLES
*
8
*
8
];
uint8_t
array_mid
[
SAMPLES
*
8
*
8
*
3
];
uint8_t
array_out
[
SAMPLES
*
8
*
8
+
100
];
uint8_t
*
ain
[
SWR_CH_MAX
];
uint8_t
*
aout
[
SWR_CH_MAX
];
uint8_t
*
amid
[
SWR_CH_MAX
];
int
planar_in
=
256
,
planar_out
=
256
;
struct
SwrContext
*
forw_ctx
=
NULL
;
struct
SwrContext
*
backw_ctx
=
NULL
;
...
...
@@ -95,10 +130,10 @@ int main(int argc, char **argv){
in_ch_count
,
out_ch_count
,
in_sample_rate
,
out_sample_rate
,
av_get_sample_fmt_name
(
in_sample_fmt
),
av_get_sample_fmt_name
(
out_sample_fmt
));
forw_ctx
=
swr_alloc2
(
forw_ctx
,
out_ch_layout
,
out_sample_fmt
,
out_sample_rate
,
in_ch_layout
,
in_sample_fmt
,
in_sample_rate
,
0
,
0
);
forw_ctx
=
swr_alloc2
(
forw_ctx
,
out_ch_layout
,
out_sample_fmt
+
planar_out
,
out_sample_rate
,
in_ch_layout
,
in_sample_fmt
+
planar_in
,
in_sample_rate
,
0
,
0
);
backw_ctx
=
swr_alloc2
(
backw_ctx
,
in_ch_layout
,
in_sample_fmt
,
in_sample_rate
,
out_ch_layout
,
out_sample_fmt
,
out_sample_rate
,
0
,
0
);
out_ch_layout
,
out_sample_fmt
+
planar_out
,
out_sample_rate
,
0
,
0
);
if
(
swr_init
(
forw_ctx
)
<
0
)
fprintf
(
stderr
,
"swr_init(->) failed
\n
"
);
if
(
swr_init
(
backw_ctx
)
<
0
)
...
...
@@ -108,14 +143,16 @@ int main(int argc, char **argv){
if
(
!
backw_ctx
)
fprintf
(
stderr
,
"Failed to init backw_ctx
\n
"
);
//FIXME test planar
setup_array
(
ain
,
array_in
,
in_sample_fmt
+
planar_in
,
SAMPLES
);
setup_array
(
amid
,
array_mid
,
out_sample_fmt
+
planar_out
,
3
*
SAMPLES
);
setup_array
(
aout
,
array_out
,
in_sample_fmt
,
SAMPLES
);
for
(
ch
=
0
;
ch
<
in_ch_count
;
ch
++
){
for
(
i
=
0
;
i
<
SAMPLES
;
i
++
)
set
(
a
rray_in
,
ch
+
i
*
in_ch_count
,
in_sample_fmt
,
sin
(
i
*
i
*
3
/
SAMPLES
));
set
(
a
in
,
ch
,
i
,
in_ch_count
,
in_sample_fmt
+
planar_in
,
sin
(
i
*
i
*
3
/
SAMPLES
));
}
mid_count
=
swr_convert
(
forw_ctx
,
(
uint8_t
*
[]){
array_mid
},
3
*
SAMPLES
,
(
const
uint8_t
*
[]){
array_in
},
SAMPLES
);
out_count
=
swr_convert
(
backw_ctx
,(
uint8_t
*
[]){
array_out
},
3
*
SAMPLES
,
(
const
uint8_t
*
[]){
array_mid
},
mid_count
);
mid_count
=
swr_convert
(
forw_ctx
,
amid
,
3
*
SAMPLES
,
ain
,
SAMPLES
);
out_count
=
swr_convert
(
backw_ctx
,
aout
,
SAMPLES
,
amid
,
mid_count
);
for
(
ch
=
0
;
ch
<
in_ch_count
;
ch
++
){
double
sse
,
x
,
maxdiff
=
0
;
double
sum_a
=
0
;
...
...
@@ -124,8 +161,8 @@ int main(int argc, char **argv){
double
sum_bb
=
0
;
double
sum_ab
=
0
;
for
(
i
=
0
;
i
<
out_count
;
i
++
){
double
a
=
get
(
a
rray_in
,
ch
+
i
*
in_ch_count
,
in_sample_fmt
);
double
b
=
get
(
a
rray_out
,
ch
+
i
*
in_ch_count
,
in_sample_fmt
);
double
a
=
get
(
a
in
,
ch
,
i
,
in_ch_count
,
in_sample_fmt
+
planar_in
);
double
b
=
get
(
a
out
,
ch
,
i
,
in_ch_count
,
in_sample_fmt
);
sum_a
+=
a
;
sum_b
+=
b
;
sum_aa
+=
a
*
a
;
...
...
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