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
aab5a452
Commit
aab5a452
authored
May 01, 2012
by
Michael Niedermayer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swr: add and use function pointers for rematrix
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
00fea26f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
30 deletions
+29
-30
rematrix.c
libswresample/rematrix.c
+13
-18
rematrix_template.c
libswresample/rematrix_template.c
+8
-9
swresample.c
libswresample/swresample.c
+3
-2
swresample_internal.h
libswresample/swresample_internal.h
+5
-1
No files found.
libswresample/rematrix.c
View file @
aab5a452
...
@@ -268,6 +268,8 @@ int swri_rematrix_init(SwrContext *s){
...
@@ -268,6 +268,8 @@ int swri_rematrix_init(SwrContext *s){
for
(
j
=
0
;
j
<
nb_in
;
j
++
)
for
(
j
=
0
;
j
<
nb_in
;
j
++
)
((
int
*
)
s
->
native_matrix
)[
i
*
nb_in
+
j
]
=
lrintf
(
s
->
matrix
[
i
][
j
]
*
32768
);
((
int
*
)
s
->
native_matrix
)[
i
*
nb_in
+
j
]
=
lrintf
(
s
->
matrix
[
i
][
j
]
*
32768
);
*
((
int
*
)
s
->
native_one
)
=
32768
;
*
((
int
*
)
s
->
native_one
)
=
32768
;
s
->
mix_1_1_f
=
copy_s16
;
s
->
mix_2_1_f
=
sum2_s16
;
}
else
if
(
s
->
midbuf
.
fmt
==
AV_SAMPLE_FMT_FLTP
){
}
else
if
(
s
->
midbuf
.
fmt
==
AV_SAMPLE_FMT_FLTP
){
s
->
native_matrix
=
av_mallocz
(
nb_in
*
nb_out
*
sizeof
(
float
));
s
->
native_matrix
=
av_mallocz
(
nb_in
*
nb_out
*
sizeof
(
float
));
s
->
native_one
=
av_mallocz
(
sizeof
(
float
));
s
->
native_one
=
av_mallocz
(
sizeof
(
float
));
...
@@ -275,6 +277,8 @@ int swri_rematrix_init(SwrContext *s){
...
@@ -275,6 +277,8 @@ int swri_rematrix_init(SwrContext *s){
for
(
j
=
0
;
j
<
nb_in
;
j
++
)
for
(
j
=
0
;
j
<
nb_in
;
j
++
)
((
float
*
)
s
->
native_matrix
)[
i
*
nb_in
+
j
]
=
s
->
matrix
[
i
][
j
];
((
float
*
)
s
->
native_matrix
)[
i
*
nb_in
+
j
]
=
s
->
matrix
[
i
][
j
];
*
((
float
*
)
s
->
native_one
)
=
1
.
0
;
*
((
float
*
)
s
->
native_one
)
=
1
.
0
;
s
->
mix_1_1_f
=
copy_float
;
s
->
mix_2_1_f
=
sum2_float
;
}
else
}
else
av_assert0
(
0
);
av_assert0
(
0
);
//FIXME quantize for integeres
//FIXME quantize for integeres
...
@@ -290,15 +294,6 @@ int swri_rematrix_init(SwrContext *s){
...
@@ -290,15 +294,6 @@ int swri_rematrix_init(SwrContext *s){
return
0
;
return
0
;
}
}
void
swri_sum2
(
enum
AVSampleFormat
format
,
void
*
dst
,
const
void
*
src0
,
const
void
*
src1
,
float
coef0
,
float
coef1
,
int
len
){
if
(
format
==
AV_SAMPLE_FMT_FLTP
){
sum2_float
((
float
*
)
dst
,
(
const
float
*
)
src0
,
(
const
float
*
)
src1
,
coef0
,
coef1
,
len
);
}
else
{
av_assert1
(
format
==
AV_SAMPLE_FMT_S16P
);
sum2_s16
((
int16_t
*
)
dst
,
(
const
int16_t
*
)
src0
,
(
const
int16_t
*
)
src1
,
lrintf
(
coef0
*
32768
),
lrintf
(
coef1
*
32768
),
len
);
}
}
void
swri_rematrix_free
(
SwrContext
*
s
){
void
swri_rematrix_free
(
SwrContext
*
s
){
av_freep
(
&
s
->
native_matrix
);
av_freep
(
&
s
->
native_matrix
);
av_freep
(
&
s
->
native_one
);
av_freep
(
&
s
->
native_one
);
...
@@ -317,19 +312,19 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
...
@@ -317,19 +312,19 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
break
;
break
;
case
1
:
case
1
:
in_i
=
s
->
matrix_ch
[
out_i
][
1
];
in_i
=
s
->
matrix_ch
[
out_i
][
1
];
if
(
mustcopy
||
s
->
matrix
[
out_i
][
in_i
]
!=
1
.
0
){
if
(
s
->
matrix
[
out_i
][
in_i
]
!=
1
.
0
){
if
(
s
->
int_sample_fmt
==
AV_SAMPLE_FMT_FLTP
){
s
->
mix_1_1_f
(
out
->
ch
[
out_i
],
in
->
ch
[
in_i
],
s
->
native_matrix
,
in
->
ch_count
*
out_i
+
in_i
,
len
);
copy_float
((
float
*
)
out
->
ch
[
out_i
],
(
const
float
*
)
in
->
ch
[
in_i
],
s
->
matrix
[
out_i
][
in_i
],
len
);
}
else
if
(
mustcopy
){
}
else
memcpy
(
out
->
ch
[
out_i
],
in
->
ch
[
in_i
],
len
*
out
->
bps
);
copy_s16
((
int16_t
*
)
out
->
ch
[
out_i
],
(
const
int16_t
*
)
in
->
ch
[
in_i
],
s
->
matrix32
[
out_i
][
in_i
],
len
);
}
else
{
}
else
{
out
->
ch
[
out_i
]
=
in
->
ch
[
in_i
];
out
->
ch
[
out_i
]
=
in
->
ch
[
in_i
];
}
}
break
;
break
;
case
2
:
case
2
:
{
swri_sum2
(
s
->
int_sample_fmt
,
out
->
ch
[
out_i
],
in
->
ch
[
s
->
matrix_ch
[
out_i
][
1
]
],
in
->
ch
[
s
->
matrix_ch
[
out_i
][
2
]
],
int
in_i1
=
s
->
matrix_ch
[
out_i
][
1
];
s
->
matrix
[
out_i
][
s
->
matrix_ch
[
out_i
][
1
]
],
s
->
matrix
[
out_i
][
s
->
matrix_ch
[
out_i
][
2
]
],
len
);
int
in_i2
=
s
->
matrix_ch
[
out_i
][
2
];
break
;
s
->
mix_2_1_f
(
out
->
ch
[
out_i
],
in
->
ch
[
in_i1
],
in
->
ch
[
in_i2
],
s
->
native_matrix
,
in
->
ch_count
*
out_i
+
in_i1
,
in
->
ch_count
*
out_i
+
in_i2
,
len
);
break
;}
default
:
default
:
if
(
s
->
int_sample_fmt
==
AV_SAMPLE_FMT_FLTP
){
if
(
s
->
int_sample_fmt
==
AV_SAMPLE_FMT_FLTP
){
for
(
i
=
0
;
i
<
len
;
i
++
){
for
(
i
=
0
;
i
<
len
;
i
++
){
...
...
libswresample/rematrix_template.c
View file @
aab5a452
...
@@ -19,20 +19,19 @@
...
@@ -19,20 +19,19 @@
*/
*/
static
void
RENAME
(
sum2
)(
SAMPLE
*
out
,
const
SAMPLE
*
in1
,
const
SAMPLE
*
in2
,
COEFF
coeff1
,
COEFF
coeff
2
,
int
len
){
static
void
RENAME
(
sum2
)(
SAMPLE
*
out
,
const
SAMPLE
*
in1
,
const
SAMPLE
*
in2
,
COEFF
*
coeffp
,
int
index1
,
int
index
2
,
int
len
){
int
i
;
int
i
;
COEFF
coeff1
=
coeffp
[
index1
];
COEFF
coeff2
=
coeffp
[
index2
];
for
(
i
=
0
;
i
<
len
;
i
++
)
for
(
i
=
0
;
i
<
len
;
i
++
)
out
[
i
]
=
R
(
coeff1
*
in1
[
i
]
+
coeff2
*
in2
[
i
]);
out
[
i
]
=
R
(
coeff1
*
in1
[
i
]
+
coeff2
*
in2
[
i
]);
}
}
static
void
RENAME
(
copy
)(
SAMPLE
*
out
,
const
SAMPLE
*
in
,
COEFF
coeff
,
int
len
){
static
void
RENAME
(
copy
)(
SAMPLE
*
out
,
const
SAMPLE
*
in
,
COEFF
*
coeffp
,
int
index
,
int
len
){
if
(
coeff
==
ONE
){
int
i
;
memcpy
(
out
,
in
,
sizeof
(
SAMPLE
)
*
len
);
COEFF
coeff
=
coeffp
[
index
];
}
else
{
for
(
i
=
0
;
i
<
len
;
i
++
)
int
i
;
out
[
i
]
=
R
(
coeff
*
in
[
i
]);
for
(
i
=
0
;
i
<
len
;
i
++
)
out
[
i
]
=
R
(
coeff
*
in
[
i
]);
}
}
}
libswresample/swresample.c
View file @
aab5a452
...
@@ -314,7 +314,7 @@ av_assert0(s->out.ch_count);
...
@@ -314,7 +314,7 @@ av_assert0(s->out.ch_count);
s
->
dither
=
s
->
preout
;
s
->
dither
=
s
->
preout
;
if
(
s
->
rematrix
)
if
(
s
->
rematrix
||
s
->
dither_method
)
return
swri_rematrix_init
(
s
);
return
swri_rematrix_init
(
s
);
return
0
;
return
0
;
...
@@ -554,8 +554,9 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co
...
@@ -554,8 +554,9 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co
if
(
s
->
dither_pos
+
out_count
>
s
->
dither
.
count
)
if
(
s
->
dither_pos
+
out_count
>
s
->
dither
.
count
)
s
->
dither_pos
=
0
;
s
->
dither_pos
=
0
;
for
(
ch
=
0
;
ch
<
preout
->
ch_count
;
ch
++
)
for
(
ch
=
0
;
ch
<
preout
->
ch_count
;
ch
++
)
s
wri_sum2
(
s
->
int_sample_fmt
,
preout
->
ch
[
ch
],
preout
->
ch
[
ch
],
s
->
dither
.
ch
[
ch
]
+
s
->
dither
.
bps
*
s
->
dither_pos
,
1
,
1
,
out_count
);
s
->
mix_2_1_f
(
preout
->
ch
[
ch
],
preout
->
ch
[
ch
],
s
->
dither
.
ch
[
ch
]
+
s
->
dither
.
bps
*
s
->
dither_pos
,
s
->
native_one
,
0
,
0
,
out_count
);
s
->
dither_pos
+=
out_count
;
s
->
dither_pos
+=
out_count
;
}
}
...
...
libswresample/swresample_internal.h
View file @
aab5a452
...
@@ -23,6 +23,9 @@
...
@@ -23,6 +23,9 @@
#include "swresample.h"
#include "swresample.h"
typedef
void
(
mix_1_1_func_type
)(
void
*
out
,
const
void
*
in
,
void
*
coeffp
,
int
index
,
int
len
);
typedef
void
(
mix_2_1_func_type
)(
void
*
out
,
const
void
*
in1
,
const
void
*
in2
,
void
*
coeffp
,
int
index1
,
int
index2
,
int
len
);
typedef
struct
AudioData
{
typedef
struct
AudioData
{
uint8_t
*
ch
[
SWR_CH_MAX
];
///< samples buffer per channel
uint8_t
*
ch
[
SWR_CH_MAX
];
///< samples buffer per channel
uint8_t
*
data
;
///< samples buffer
uint8_t
*
data
;
///< samples buffer
...
@@ -84,6 +87,8 @@ struct SwrContext {
...
@@ -84,6 +87,8 @@ struct SwrContext {
uint8_t
*
native_one
;
uint8_t
*
native_one
;
int32_t
matrix32
[
SWR_CH_MAX
][
SWR_CH_MAX
];
///< 17.15 fixed point rematrixing coefficients
int32_t
matrix32
[
SWR_CH_MAX
][
SWR_CH_MAX
];
///< 17.15 fixed point rematrixing coefficients
uint8_t
matrix_ch
[
SWR_CH_MAX
][
SWR_CH_MAX
+
1
];
///< Lists of input channels per output channel that have non zero rematrixing coefficients
uint8_t
matrix_ch
[
SWR_CH_MAX
][
SWR_CH_MAX
+
1
];
///< Lists of input channels per output channel that have non zero rematrixing coefficients
mix_1_1_func_type
*
mix_1_1_f
;
mix_2_1_func_type
*
mix_2_1_f
;
/* TODO: callbacks for ASM optimizations */
/* TODO: callbacks for ASM optimizations */
};
};
...
@@ -100,7 +105,6 @@ int swri_resample_double(struct ResampleContext *c,double *dst, const double *
...
@@ -100,7 +105,6 @@ int swri_resample_double(struct ResampleContext *c,double *dst, const double *
int
swri_rematrix_init
(
SwrContext
*
s
);
int
swri_rematrix_init
(
SwrContext
*
s
);
void
swri_rematrix_free
(
SwrContext
*
s
);
void
swri_rematrix_free
(
SwrContext
*
s
);
int
swri_rematrix
(
SwrContext
*
s
,
AudioData
*
out
,
AudioData
*
in
,
int
len
,
int
mustcopy
);
int
swri_rematrix
(
SwrContext
*
s
,
AudioData
*
out
,
AudioData
*
in
,
int
len
,
int
mustcopy
);
void
swri_sum2
(
enum
AVSampleFormat
format
,
void
*
dst
,
const
void
*
src0
,
const
void
*
src1
,
float
coef0
,
float
coef1
,
int
len
);
void
swri_get_dither
(
SwrContext
*
s
,
void
*
dst
,
int
len
,
unsigned
seed
,
enum
AVSampleFormat
out_fmt
,
enum
AVSampleFormat
in_fmt
);
void
swri_get_dither
(
SwrContext
*
s
,
void
*
dst
,
int
len
,
unsigned
seed
,
enum
AVSampleFormat
out_fmt
,
enum
AVSampleFormat
in_fmt
);
...
...
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