Commit graph

120 commits

Author SHA1 Message Date
David Mandelberg
21c3570b12 resampler: Flag for remixing to all sink channels.
Add a flag PA_RESAMPLER_NO_FILL_SINK, which controls whether remixing
should attempt to use all sink channels, versus only the ones needed
to reproduce the source audio.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=62588
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=94563

Suggested-by: Alexander E. Patrakov <patrakov@gmail.com>
2017-01-19 03:00:45 +02:00
Barun Kumar Singh
1d5dfccbb2 resampler: Fix leaking lfe filter on init failure
Fix memory leak in pa_resampler_new() in resampler.c, Deallocating
memory of r->lfe_filter in case of fail.

Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
2016-05-27 09:37:37 +05:30
Arun Raghavan
daf326a9e4 resampler: Don't expose soxr methods if they are not supported
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=92780
2015-11-06 17:40:29 +05:30
Deepak Srivastava
2d5eec2d2c Rename functions with "tostring" in the name to one with "to_string" to conform with the convention.
component: core

<EP-E358F00C1D9A449EAE69225B9D2530F8>
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=88833

Signed-off-by: Deepak Srivastava <srivastava.d@samsung.com>
2015-09-25 17:29:02 +05:30
David Henningsson
2cfc5df87f resampler: Rename "lfe_filter_required" to "lfe_remixed"
Just refactoring to make the variable name better.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-30 15:12:53 +02:00
David Henningsson
c65a606ae7 resampler: Allow disabling the LFE filter by setting crossover to 0
When crossover_freq is set to 0, this restores the old behaviour
of letting the LFE channel be the average of the source channels,
without additional processing. This can be useful e g in case the
user already has a hardware crossover.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-30 11:10:56 +02:00
David Henningsson
7fb531d936 resampler: Make some basic functions for rewinding
The resampler framework just forwards the request to the lfe filter.
There are no resampler impl that can rewind yet, so just reset the
resampler impl instead of properly rewinding yet.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-30 10:52:30 +02:00
David Henningsson
defc2b702b lfe-filter: Add rewind support
Store current filter state at every normal block process.
When a rewind happens, rewind back to the nearest saved state,
then calculate forward to the actual sample position.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-30 10:52:30 +02:00
Hui Wang
c36e191ce5 lfe-filter: change the crossover frequency as a parameter
Add a user defined parameter lfe-crossover-freq for the lfe-filter,
to pass this parameter to the lfe-filter, we need to change the
pa_resampler_new() API as well.

Signed-off-by: Hui Wang <hui.wang@canonical.com>
2015-03-30 10:52:30 +02:00
David Henningsson
979f19a434 lfe-filter: Enable LFE filter in the resampler
When enable-lfe-remixing is set, an LFE channel is present in the
resampler's destination channel map but not in the source channel map,
we insert a low-pass filter instead of just averaging the channels.
Other channels will get a high-pass filter.

In this patch, the crossover frequency is hardcoded to 120Hz (to be fixed
in later patches).

Note that in current state the LFE filter is
 - not very optimised
 - not rewind friendly (rewinding can cause audible artifacts)

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-30 10:52:29 +02:00
Andrey Semashev
e257fd51f6 Enabled libsoxr resampler backend.
Added ID and names for the resampler presets and also updated the working sample rate deduction to take the new resampler into account. The initial libsoxr backend version does not variable rate resampling, so it is disabled in this case.
2015-02-12 20:36:58 +01:00
Ondrej Holecek
5effc83479 update FSF addresses to FSF web page
FSF addresses used in PA sources are no longer valid and rpmlint
generates numerous warnings during packaging because of this.
This patch changes all FSF addresses to FSF web page according to
the GPL how-to: https://www.gnu.org/licenses/gpl-howto.en.html

Done automatically by sed-ing through sources.
2015-01-14 22:20:40 +02:00
Andrey Semashev
807c98a37d resampler: Fix sample_format_more_precise() for the case of comparing against PA_SAMPLE_S32BE
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-11-12 23:17:08 +01:00
Peter Meerwald
70973d58e6 resampler: Drop pointless remix variable
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-11-06 10:12:39 +01:00
Alexander E. Patrakov
ee658fa074 resampler: Moved speex_is_fixed_point() to speex.c
IMHO code that calls into speex belongs in speex.c, not in resampler.c.

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
2014-08-17 13:06:20 +03:00
poljar (Damir Jelić)
72103e1e33 resampler: Split the resampler implementations into separate files
Rebased by Peter Meerwald.

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: poljar (Damir Jelić) <poljarinho@gmail.com>
2014-08-17 11:18:17 +03:00
Tanu Kaskinen
be10147611 resampler: Remove prefix from static functions 2014-05-24 13:15:39 +03:00
Alexander E. Patrakov
ac984f59d3 resampler: Support speex resampler compiled with FIXED_POINT
speex_resample_float() does not work with speex compiled with
--enable-fixed-point, because speex expects its float input
to be normalized to ±32768 instead of the more usual ±1.

It is possible to fix speex_resample_float(), as demonstrated at
http://lists.freedesktop.org/archives/pulseaudio-discuss/2014-May/020617.html
However, a better idea is to avoid using the speex-float resampler and
the associated s16 <-> float conversions that speex will immediately undo
internally if it is known that speex has been compiled with FIXED_POINT.
So, transparently change speex-float-* to speex-fixed-* in that case.

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
Reported-by: Fahad Arslan <fahad_arslan@mentor.com>
Cc: Damir Jelić <poljarinho@gmail.com>
Cc: Peter Meerwald <pmeerw@pmeerw.net>

FIXED_POINT detection is based on code by Peter Meerwald.
2014-05-23 13:23:26 +03:00
Peter Meerwald
e92e8b11f1 remap: Add (optional) state to remap struct
State can be used by remap function implementations to
speed up the remapping, e.g. by precomputing things or
even by generating specialized code for a specific channel
remapping task

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-04-29 00:00:06 +02:00
Peter Meerwald
9362bdc8a1 remap: Make resampler's remap structure more self-contained
Initialization of the remap structure now happens in one place

Rename calc_map_table() to setup_remap(), copy sample format and
channel specs; the remap structure is initialized when we know the
work sample format of the resampler

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-04-29 00:00:06 +02:00
Peter Meerwald
937b4175c2 remap: Refactor channel remap table computation calc_map_table()
Make the resampler argument const, and pass explicit remap
structure argument

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-04-29 00:00:06 +02:00
Peter Meerwald
c7190b5fd4 remap: Rename pa_init_remap() to pa_init_remap_func()
pa_init_remap_func() only sets the appropriate remapping function, it
does not initialize the pa_remap struct

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-04-29 00:00:06 +02:00
Peter Meerwald
537f430c99 resampler: Resample first followed by remapping if have more out channels than in channels
Reintroduces a cleaned-up version of commit 30ce3a14e5 which
was reverted by 1ce71cbd82; for more information see
http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/17479/focus=17487

The patch intends to reduce computational load when resampling AND remapping. The PA
resampler performs the following steps:

sample format conversion -> remapping -> resampling -> sample format conversion

In case the number of output channels is higher than the number of input channels, the
resampler has to be run more often than necessary. E.g. in case of mono to 4-channel remapping,
the resampler runs on 4 channels separately.

To ímprove this, the PA resampler pipeline is made adaptive:

if out-channels <= in-channels:
  sample format conversion -> remapping -> resampling -> sample format conversion
if out-channels > in-channels:
  sample format conversion -> resampling -> remapping -> sample format conversion

Signed-off-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2014-01-28 23:08:54 +02:00
Peter Meerwald
b51d28bbbf resampler: Implement leftover handling in convert_to_work_format()
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-01-28 22:49:15 +02:00
Peter Meerwald
5ad310f4f6 resampler: Extend fit_buf() helper to copy leftover data to new buffer
the patch changes the interface of the (internal) fit_buf() function:
fit_buf() manages the memblock of the buf chunk, it reallocates the memblock
if the requested number of bytes ('len') if larger than the memblock's size ('size')
and optionally preserves 'copy' bytes

the code should be in line with the comment now

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2014-01-28 22:41:16 +02:00
Tanu Kaskinen
a67318f8af Add pa_sample_rate_valid()
I think this makes the code a bit nicer to read and write. This also
reduces the chances of off-by-one errors when checking the bounds of
sample rate values.
2013-12-15 11:21:56 +01:00
Tanu Kaskinen
1cda717252 Add pa_sample_format_valid()
I think this makes the code a bit nicer to read and write. This also
reduces the chances of off-by-one errors when checking the bounds of
the sample format value.
2013-12-15 11:07:17 +01:00
Peter Meerwald
742b93d32c resampler: Clean up ffmpeg resampler buffering
buf in struct ffmpeg_data is reset() initially and freed, but never
actually used

when a new block is allocated ffmpeg_data->buf[c].length is used
(which is always 0) to compute the new block size

so, drop buf

Signed-off-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2013-12-05 10:46:47 +02:00
Peter Meerwald
d0fd59c34c resampler: Cleanup, index of memchunks is not used
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-11-08 16:14:43 +02:00
Peter Meerwald
b14e9c0a6c resampler: Prepare to have leftover data in different output buffers
leftover_buf points to the output buffer of a stage containing leftover
data; similar for leftover_buf_size and have_leftover

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-11-08 16:01:06 +02:00
Peter Meerwald
0109a50a2d resampler: Add fit_buf() helper funtion for buffer allocation
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-11-08 15:50:05 +02:00
Peter Meerwald
da5c215d9b resampler: Cleanup, rename xxxx_buf_samples to xxxx_buf_size
we measure the capacity of a buffer in bytes, not samples

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-11-08 10:34:56 +02:00
Peter Meerwald
53104b36e6 resampler: Handle leftover samples, use new return value
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-11-08 10:33:16 +02:00
Peter Meerwald
79b237ca02 resampler: Change interface, resampler may return the number of leftover frames
some resampler implementations (e.g. libsamplerate and ffmpeg) do not consume
the entire input buffer; the impl_resample() function now has a return value
returning the number of frames in the input buffer not processed

these frames must be saved in appropriate buffer and presented together with
new input data

also change the parameter names from in_samples, out_samples to in_n_frames,
out_n_frames, respectively (n_frames = samples / channels)

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-11-08 10:27:30 +02:00
Peter Meerwald
6d61c7779d resampler: Introduce work_channels
work_channels is the number of channels in the resampler stage

Signed-off-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2013-11-08 10:17:46 +02:00
Peter Meerwald
c60a36ecdd resampler: Introduce work frame size (w_fz)
w_fz represents the number of bytes per frame in the resampler stage

Signed-off-by: Peter Meerwald <p.meerwald@bct-electronic.com>
2013-11-08 10:05:25 +02:00
poljar (Damir Jelić)
6f94c56782 resampler: Revert to auto if the rates are equal and copy is chosen
This patch fixes a small mistake where we actually log that we are
reverting to the auto resampler if we can't use the 'copy' resampler but
never do the revert.

This would lead to a crash if the user chooses the 'copy' resampler and
then tries to play something that needs to be resampled.
2013-09-25 18:15:40 +05:30
Tanu Kaskinen
d448ef04e9 resampler: Never return zero for max block size
With very low input sample rates the memory pool max block size may
not be big enough, in which case we should return the size of one
frame. Returning zero caused crashing.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=68616
2013-09-08 11:10:10 +03:00
poljar (Damir Jelić)
9a590dd3f2 resampler: Add a choose_auto_resampler function
This function returns our preferred resampler if the user choose the
auto (or if he has chosen an unsupported) resampler.
2013-08-27 12:33:10 +02:00
poljar (Damir Jelić)
8ab6c37e10 resampler: Get rid of redundant implementation specific structs
This patch removes implementation specific structs that contain a single
member.
2013-08-27 12:33:10 +02:00
poljar (Damir Jelić)
0d525e9c85 resampler: Add assert to set_input/output_rate
This adds asserts to check if the implementation has an update rate
function defined for the unlikely event that some implementation forgets
to assign a update rate function we can simply bail.

It is expected from the resampling implementations to have such a
function even if the state of the resampler is completely reset.
2013-08-27 12:33:10 +02:00
poljar (Damir Jelić)
4bdfebee5c resampler: Introduce a implementation specific struct
This struct holds all the implementation specific data in one place.
2013-08-27 12:33:10 +02:00
poljar (Damir Jelić)
c5cd65d81e Resampler: Don't use the peaks resampler for upsampling
This patch fixes this assertion:
    Assertion 'r->i_ss.rate >= r->o_ss.rate' failed at ../../src/pulsecore/resampler.c:1744, function peaks_init(). Aborting.
2013-08-27 12:33:10 +02:00
poljar (Damir Jelić)
2bed8cda25 resampler: Add a function for comparing sample format precision 2013-08-27 12:33:10 +02:00
poljar (Damir Jelić)
7665f60cc0 resampler: choose_work_format use switch instead of if/else
This way the function for choosing the work format should
be more readable and easier to expand in the future.
2013-08-27 12:33:09 +02:00
poljar (Damir Jelić)
78c18e71e0 resampler: Move the work format finding logic into a separate function 2013-08-27 12:33:09 +02:00
poljar (Damir Jelić)
83cf44831f resampler: fix_method use switch instead of if/else
This way the fix method function should be more readable and easier to
expand in the future.
2013-08-27 12:33:09 +02:00
poljar (Damir Jelić)
2d9aba0946 resampler: Move the fix method logic into a separate function 2013-08-27 12:33:09 +02:00
poljar (Damir Jelić)
97feeab40c resampler: Make resampler struct implementation agnostic
The pa_resampler struct contains many implementation specific
structures. These create overhead and don't belong there anyways.

This patch moves the implementation specific structures out of the
pa_resampler structure.
2013-08-27 12:33:09 +02:00
Tanu Kaskinen
1470fc325a resampler: Fix peaks resampler's channel handling
In the resampling phase the input and output data have the same number
of channels (o_ss.channels).
2013-07-29 10:49:19 +03:00