Commit 8f51f1bc authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Speex resampler (for FL32 and S16N)

This adds a good resampler for integers, while reusing a source package
(speex) that is already dependend on.

Contrary to SRC, the library is BSD and the plugin is LGPL.
parent 9e015a3f
...@@ -134,6 +134,7 @@ Audio Output and Filters: ...@@ -134,6 +134,7 @@ Audio Output and Filters:
* New audio output in memory (amem) * New audio output in memory (amem)
* Important simplification and improvements in the core audio output * Important simplification and improvements in the core audio output
* New audio output based on OpenSL ES API for Android * New audio output based on OpenSL ES API for Android
* New audio resampler using Speex (DSP)
* New audio resampler using the Secret Rabbit Code (a.k.a. libsamplerate) * New audio resampler using the Secret Rabbit Code (a.k.a. libsamplerate)
* New Compressor filter, a dynamic range compressor * New Compressor filter, a dynamic range compressor
* New simplistic Karaoke filter * New simplistic Karaoke filter
......
...@@ -2843,9 +2843,20 @@ then ...@@ -2843,9 +2843,20 @@ then
fi fi
dnl dnl
dnl Speex plugin dnl Speex plugins
dnl dnl
PKG_ENABLE_MODULES_VLC([SPEEX], [], [ogg speex >= 1.0.5], [Speex decoder support], [auto]) PKG_ENABLE_MODULES_VLC([SPEEX], [], [ogg speex >= 1.0.5], [Speex support], [auto])
have_speexdsp="no"
AS_IF([test "${enable_speex}" != "no"], [
PKG_CHECK_MODULES([SPEEXDSP], [speexdsp], [
have_speexdsp="yes"
], [
AS_IF([test "${enable_speex}" = "yes"], [
AC_MSG_ERROR([${SPEEXDSP_PKG_ERRORS}.])
])
])
])
AM_CONDITIONAL([HAVE_SPEEXDSP], [test "$have_speexdsp" = "yes"])
dnl dnl
dnl theora decoder plugin dnl theora decoder plugin
......
...@@ -296,6 +296,7 @@ $Id$ ...@@ -296,6 +296,7 @@ $Id$
* smf: Standard MIDI file demuxer * smf: Standard MIDI file demuxer
* spatializer: A spatializer audio filter * spatializer: A spatializer audio filter
* speex: a speex audio decoder/packetizer using the libspeex library * speex: a speex audio decoder/packetizer using the libspeex library
* speex_resampler: audio resampler using the libspeexdsp library
* spudec: RLE DVD subtitles decoder * spudec: RLE DVD subtitles decoder
* sqlite: manage an SQLite database * sqlite: manage an SQLite database
* stats: Stats encoder function * stats: Stats encoder function
......
...@@ -64,3 +64,11 @@ libvlc_LTLIBRARIES += \ ...@@ -64,3 +64,11 @@ libvlc_LTLIBRARIES += \
libugly_resampler_plugin.la libugly_resampler_plugin.la
EXTRA_LTLIBRARIES += \ EXTRA_LTLIBRARIES += \
libbandlimited_resampler_plugin.la libbandlimited_resampler_plugin.la
libspeex_resampler_plugin_la_SOURCES = resampler/speex.c
libspeex_resampler_plugin_la_CFLAGS = $(AM_CFLAGS) $(SPEEXDSP_CFLAGS)
libspeex_resampler_plugin_la_LIBADD = $(AM_LIBADD) $(SPEEXDSP_LIBS)
libspeex_resampler_plugin_la_DEPENDENCIES =
if HAVE_SPEEXDSP
libvlc_LTLIBRARIES += libspeex_resampler_plugin.la
endif
/*****************************************************************************
* speex.c : libspeex DSP resampler
*****************************************************************************
* Copyright © 2011 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_filter.h>
#include <vlc_plugin.h>
#include <speex/speex_resampler.h>
#define QUALITY_TEXT N_("Resampling quality")
#define QUALITY_LONGTEXT N_( \
"Resampling quality (0 = worst and fastest, 10 = best and slowest).")
static int Open (vlc_object_t *);
static void Close (vlc_object_t *);
vlc_module_begin ()
set_shortname (N_("Speex resampler"))
set_description (N_("Speex resampler") )
set_category (CAT_AUDIO)
set_subcategory (SUBCAT_AUDIO_MISC)
add_integer ("speex-resampler-quality", 3,
QUALITY_TEXT, QUALITY_LONGTEXT, true)
change_integer_range (0, 10)
set_capability ("audio filter", 60)
set_callbacks (Open, Close)
vlc_module_end ()
static block_t *Resample (filter_t *, block_t *);
static int Open (vlc_object_t *obj)
{
filter_t *filter = (filter_t *)obj;
/* Will change rate */
if (filter->fmt_in.audio.i_rate == filter->fmt_out.audio.i_rate
/* Cannot convert format */
|| filter->fmt_in.audio.i_format != filter->fmt_out.audio.i_format
/* Cannot remix */
|| filter->fmt_in.audio.i_physical_channels
!= filter->fmt_out.audio.i_physical_channels
|| filter->fmt_in.audio.i_original_channels
!= filter->fmt_out.audio.i_original_channels)
return VLC_EGENERIC;
switch (filter->fmt_in.audio.i_format)
{
case VLC_CODEC_FL32: break;
case VLC_CODEC_S16N: break;
default: return VLC_EGENERIC;
}
SpeexResamplerState *st;
unsigned channels = aout_FormatNbChannels (&filter->fmt_in.audio);
unsigned q = var_InheritInteger (obj, "speex-resampler-quality");
if (unlikely(q > 10))
q = 3;
int err;
st = speex_resampler_init(channels, filter->fmt_in.audio.i_rate,
filter->fmt_out.audio.i_rate, q, &err);
if (unlikely(st == NULL))
{
msg_Err (obj, "cannot initialize resampler: %s",
speex_resampler_strerror (err));
return VLC_ENOMEM;
}
filter->p_sys = (filter_sys_t *)st;
filter->pf_audio_filter = Resample;
return VLC_SUCCESS;
}
static void Close (vlc_object_t *obj)
{
filter_t *filter = (filter_t *)obj;
SpeexResamplerState *st = (SpeexResamplerState *)filter->p_sys;
speex_resampler_destroy (st);
}
static block_t *Resample (filter_t *filter, block_t *in)
{
SpeexResamplerState *st = (SpeexResamplerState *)filter->p_sys;
const size_t framesize = filter->fmt_out.audio.i_bytes_per_frame;
const unsigned irate = filter->fmt_in.audio.i_rate;
const unsigned orate = filter->fmt_out.audio.i_rate;
spx_uint32_t ilen = in->i_nb_samples;
spx_uint32_t olen = ((ilen + 1) * orate) / irate;
block_t *out = block_Alloc (olen * framesize);
if (unlikely(out == NULL))
goto error;
speex_resampler_set_rate (st, irate, orate);
int err;
if (filter->fmt_in.audio.i_format == VLC_CODEC_FL32)
err = speex_resampler_process_interleaved_float (st,
(float *)in->p_buffer, &ilen, (float *)out->p_buffer, &olen);
else
err = speex_resampler_process_interleaved_int (st,
(int16_t *)in->p_buffer, &ilen, (int16_t *)out->p_buffer, &olen);
if (err != 0)
{
msg_Err (filter, "cannot resample: %s",
speex_resampler_strerror (err));
block_Release (out);
out = NULL;
goto error;
}
out->i_buffer = olen * framesize;
out->i_nb_samples = olen;
out->i_pts = in->i_pts;
out->i_length = olen * CLOCK_FREQ / filter->fmt_out.audio.i_rate;
error:
block_Release (in);
return out;
}
...@@ -306,6 +306,7 @@ modules/audio_filter/normvol.c ...@@ -306,6 +306,7 @@ modules/audio_filter/normvol.c
modules/audio_filter/param_eq.c modules/audio_filter/param_eq.c
modules/audio_filter/resampler/bandlimited.c modules/audio_filter/resampler/bandlimited.c
modules/audio_filter/resampler/bandlimited.h modules/audio_filter/resampler/bandlimited.h
modules/audio_filter/resampler/speex.c
modules/audio_filter/resampler/src.c modules/audio_filter/resampler/src.c
modules/audio_filter/resampler/ugly.c modules/audio_filter/resampler/ugly.c
modules/audio_filter/scaletempo.c modules/audio_filter/scaletempo.c
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment