Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
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
Commits
17e7ea9a
Commit
17e7ea9a
authored
Sep 27, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
linear resampler: audio filter2
parent
ff981aa0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
142 deletions
+34
-142
modules/audio_filter/resampler/linear.c
modules/audio_filter/resampler/linear.c
+34
-142
No files found.
modules/audio_filter/resampler/linear.c
View file @
17e7ea9a
...
...
@@ -39,11 +39,6 @@
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static
int
Create
(
vlc_object_t
*
);
static
void
Close
(
vlc_object_t
*
);
static
void
DoWork
(
aout_instance_t
*
,
aout_filter_t
*
,
aout_buffer_t
*
,
aout_buffer_t
*
);
static
int
OpenFilter
(
vlc_object_t
*
);
static
void
CloseFilter
(
vlc_object_t
*
);
static
block_t
*
Resample
(
filter_t
*
,
block_t
*
);
...
...
@@ -67,105 +62,56 @@ vlc_module_begin ()
set_description
(
N_
(
"Audio filter for linear interpolation resampling"
)
)
set_category
(
CAT_AUDIO
)
set_subcategory
(
SUBCAT_AUDIO_MISC
)
set_capability
(
"audio filter"
,
5
)
set_callbacks
(
Create
,
Close
)
add_submodule
()
set_description
(
N_
(
"Audio filter for linear interpolation resampling"
)
)
set_capability
(
"audio filter2"
,
5
)
set_callbacks
(
OpenFilter
,
CloseFilter
)
vlc_module_end
()
/*****************************************************************************
*
Create: allocate linear resampl
er
*
Resample: convert a buff
er
*****************************************************************************/
static
int
Create
(
vlc_object_t
*
p_this
)
static
block_t
*
Resample
(
filter_t
*
p_filter
,
block_t
*
p_in_buf
)
{
aout_filter_t
*
p_filter
=
(
aout_filter_t
*
)
p_this
;
struct
filter_sys_t
*
p_sys
;
if
(
p_filter
->
fmt_in
.
audio
.
i_rate
==
p_filter
->
fmt_out
.
audio
.
i_rate
||
p_filter
->
fmt_in
.
audio
.
i_format
!=
p_filter
->
fmt_out
.
audio
.
i_format
||
p_filter
->
fmt_in
.
audio
.
i_physical_channels
!=
p_filter
->
fmt_out
.
audio
.
i_physical_channels
||
p_filter
->
fmt_in
.
audio
.
i_original_channels
!=
p_filter
->
fmt_out
.
audio
.
i_original_channels
||
p_filter
->
fmt_in
.
audio
.
i_format
!=
VLC_CODEC_FL32
)
if
(
!
p_in_buf
||
!
p_in_buf
->
i_nb_samples
)
{
return
VLC_EGENERIC
;
}
/* Allocate the memory needed to store the module's structure */
p_sys
=
malloc
(
sizeof
(
filter_sys_t
)
);
p_filter
->
p_sys
=
(
struct
aout_filter_sys_t
*
)
p_sys
;
if
(
p_sys
==
NULL
)
return
VLC_ENOMEM
;
p_sys
->
p_prev_sample
=
malloc
(
p_filter
->
fmt_in
.
audio
.
i_channels
*
sizeof
(
int32_t
)
);
if
(
p_sys
->
p_prev_sample
==
NULL
)
{
free
(
p_sys
);
return
VLC_ENOMEM
;
if
(
p_in_buf
)
block_Release
(
p_in_buf
);
return
NULL
;
}
date_Init
(
&
p_sys
->
end_date
,
p_filter
->
fmt_out
.
audio
.
i_rate
,
1
);
p_filter
->
pf_do_work
=
DoWork
;
/* We don't want a new buffer to be created because we're not sure we'll
* actually need to resample anything. */
p_filter
->
b_in_place
=
true
;
return
VLC_SUCCESS
;
}
/*****************************************************************************
* Close: free our resources
*****************************************************************************/
static
void
Close
(
vlc_object_t
*
p_this
)
{
aout_filter_t
*
p_filter
=
(
aout_filter_t
*
)
p_this
;
filter_sys_t
*
p_sys
=
(
filter_sys_t
*
)
p_filter
->
p_sys
;
free
(
p_sys
->
p_prev_sample
);
free
(
p_sys
);
}
/*****************************************************************************
* DoWork: convert a buffer
*****************************************************************************/
static
void
DoWork
(
aout_instance_t
*
p_aout
,
aout_filter_t
*
p_filter
,
aout_buffer_t
*
p_in_buf
,
aout_buffer_t
*
p_out_buf
)
{
filter_sys_t
*
p_sys
=
(
filter_sys_t
*
)
p_filter
->
p_sys
;
float
*
p_out
=
(
float
*
)
p_out_buf
->
p_buffer
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
unsigned
i_nb_channels
=
p_filter
->
fmt_in
.
audio
.
i_channels
;
float
*
p_prev_sample
=
(
float
*
)
p_sys
->
p_prev_sample
;
int
i_nb_channels
=
p_filter
->
fmt_in
.
audio
.
i_channels
;
int
i_in_nb
=
p_in_buf
->
i_nb_samples
;
int
i_chan
,
i_in
,
i_out
=
0
;
/* Check if we really need to run the resampler */
if
(
p_
aout
->
mixer_format
.
i_rate
==
p_filter
->
fmt_in
.
audio
.
i_rate
)
if
(
p_
filter
->
fmt_out
.
audio
.
i_rate
==
p_filter
->
fmt_in
.
audio
.
i_rate
)
{
#if 0 /* FIXME: needs audio filter2 for block_Realloc */
if
(
!
(
p_in_buf
->
i_flags
&
BLOCK_FLAG_DISCONTINUITY
)
)
{
p_in_buf
=
block_Realloc
(
p_in_buf
,
sizeof
(
float
)
*
i_nb_channels
,
p_in_buf
->
i_buffer
);
if
(
!
p_in_buf
)
abort()
;
return
NULL
;
memcpy
(
p_in_buf
->
p_buffer
,
p_prev_sample
,
i_nb_channels
*
sizeof
(
float
)
);
}
#endif
p_out_buf
->
i_flags
|=
BLOCK_FLAG_DISCONTINUITY
;
return
;
return
p_in_buf
;
}
float
p_in_orig
[
p_in_buf
->
i_buffer
/
4
],
*
p_in
=
p_in_orig
;
unsigned
i_bytes_per_frame
=
p_filter
->
fmt_out
.
audio
.
i_channels
*
p_filter
->
fmt_out
.
audio
.
i_bitspersample
/
8
;
vlc_memcpy
(
p_in
,
p_in_buf
->
p_buffer
,
p_in_buf
->
i_buffer
);
size_t
i_out_size
=
i_bytes_per_frame
*
(
1
+
(
p_in_buf
->
i_nb_samples
*
p_filter
->
fmt_out
.
audio
.
i_rate
/
p_filter
->
fmt_in
.
audio
.
i_rate
));
block_t
*
p_out_buf
=
filter_NewAudioBuffer
(
p_filter
,
i_out_size
);
if
(
!
p_out_buf
)
goto
out
;
float
*
p_out
=
(
float
*
)
p_out_buf
->
p_buffer
;
unsigned
i_in_nb
=
p_in_buf
->
i_nb_samples
;
unsigned
i_out
=
0
;
const
float
*
p_in
=
(
float
*
)
p_in_buf
->
p_buffer
;
/* Take care of the previous input sample (if any) */
if
(
p_in_buf
->
i_flags
&
BLOCK_FLAG_DISCONTINUITY
)
...
...
@@ -178,7 +124,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
{
while
(
p_sys
->
i_remainder
<
p_filter
->
fmt_out
.
audio
.
i_rate
)
{
for
(
i_chan
=
i_nb_channels
;
i_chan
;
)
for
(
unsigned
i_chan
=
i_nb_channels
;
i_chan
;
)
{
i_chan
--
;
p_out
[
i_chan
]
=
p_prev_sample
[
i_chan
];
...
...
@@ -187,7 +133,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
/
p_filter
->
fmt_out
.
audio
.
i_rate
);
}
p_out
+=
i_nb_channels
;
i_out
++
;
i_out
++
;
p_sys
->
i_remainder
+=
p_filter
->
fmt_in
.
audio
.
i_rate
;
}
...
...
@@ -195,11 +141,11 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
}
/* Take care of the current input samples (minus last one) */
for
(
i_in
=
0
;
i_in
<
i_in_nb
-
1
;
i_in
++
)
for
(
unsigned
i_in
=
0
;
i_in
<
i_in_nb
-
1
;
i_in
++
)
{
while
(
p_sys
->
i_remainder
<
p_filter
->
fmt_out
.
audio
.
i_rate
)
{
for
(
i_chan
=
i_nb_channels
;
i_chan
;
)
for
(
unsigned
i_chan
=
i_nb_channels
;
i_chan
;
)
{
i_chan
--
;
p_out
[
i_chan
]
=
p_in
[
i_chan
];
...
...
@@ -208,7 +154,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
*
p_sys
->
i_remainder
/
p_filter
->
fmt_out
.
audio
.
i_rate
);
}
p_out
+=
i_nb_channels
;
i_out
++
;
i_out
++
;
p_sys
->
i_remainder
+=
p_filter
->
fmt_in
.
audio
.
i_rate
;
}
...
...
@@ -218,7 +164,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
}
/* Backup the last input sample for next time */
for
(
i_chan
=
i_nb_channels
;
i_chan
;
)
for
(
unsigned
i_chan
=
i_nb_channels
;
i_chan
;
)
{
i_chan
--
;
p_prev_sample
[
i_chan
]
=
p_in
[
i_chan
];
...
...
@@ -238,6 +184,9 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
p_out_buf
->
i_buffer
=
p_out_buf
->
i_nb_samples
*
i_nb_channels
*
sizeof
(
int32_t
);
out:
block_Release
(
p_in_buf
);
return
p_out_buf
;
}
/*****************************************************************************
...
...
@@ -268,6 +217,7 @@ static int OpenFilter( vlc_object_t *p_this )
return
VLC_ENOMEM
;
}
date_Init
(
&
p_sys
->
end_date
,
p_filter
->
fmt_in
.
audio
.
i_rate
,
1
);
p_sys
->
i_remainder
=
0
;
p_filter
->
pf_audio_filter
=
Resample
;
...
...
@@ -294,61 +244,3 @@ static void CloseFilter( vlc_object_t *p_this )
free
(
p_filter
->
p_sys
->
p_prev_sample
);
free
(
p_filter
->
p_sys
);
}
/*****************************************************************************
* Resample
*****************************************************************************/
static
block_t
*
Resample
(
filter_t
*
p_filter
,
block_t
*
p_block
)
{
aout_filter_t
aout_filter
;
aout_buffer_t
in_buf
,
out_buf
;
block_t
*
p_out
;
int
i_out_size
;
int
i_bytes_per_frame
;
if
(
!
p_block
||
!
p_block
->
i_nb_samples
)
{
if
(
p_block
)
block_Release
(
p_block
);
return
NULL
;
}
i_bytes_per_frame
=
p_filter
->
fmt_out
.
audio
.
i_channels
*
p_filter
->
fmt_out
.
audio
.
i_bitspersample
/
8
;
i_out_size
=
i_bytes_per_frame
*
(
1
+
(
p_block
->
i_nb_samples
*
p_filter
->
fmt_out
.
audio
.
i_rate
/
p_filter
->
fmt_in
.
audio
.
i_rate
));
p_out
=
p_filter
->
pf_audio_buffer_new
(
p_filter
,
i_out_size
);
if
(
!
p_out
)
{
msg_Warn
(
p_filter
,
"can't get output buffer"
);
block_Release
(
p_block
);
return
NULL
;
}
p_out
->
i_nb_samples
=
i_out_size
/
i_bytes_per_frame
;
p_out
->
i_dts
=
p_block
->
i_dts
;
p_out
->
i_pts
=
p_block
->
i_pts
;
p_out
->
i_length
=
p_block
->
i_length
;
aout_filter
.
p_sys
=
(
struct
aout_filter_sys_t
*
)
p_filter
->
p_sys
;
aout_filter
.
fmt_in
.
audio
=
p_filter
->
fmt_in
.
audio
;
aout_filter
.
fmt_out
.
audio
=
p_filter
->
fmt_out
.
audio
;
in_buf
.
p_buffer
=
p_block
->
p_buffer
;
in_buf
.
i_buffer
=
p_block
->
i_buffer
;
in_buf
.
i_nb_samples
=
p_block
->
i_nb_samples
;
out_buf
.
p_buffer
=
p_out
->
p_buffer
;
out_buf
.
i_buffer
=
p_out
->
i_buffer
;
out_buf
.
i_nb_samples
=
p_out
->
i_nb_samples
;
DoWork
(
(
aout_instance_t
*
)
p_filter
,
&
aout_filter
,
&
in_buf
,
&
out_buf
);
block_Release
(
p_block
);
p_out
->
i_buffer
=
out_buf
.
i_buffer
;
p_out
->
i_nb_samples
=
out_buf
.
i_nb_samples
;
return
p_out
;
}
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