summaryrefslogtreecommitdiffstats
path: root/audio/filter
<
Commit message (Collapse)AuthorAgeFilesLines
* audio: remove S8, U16, U24, U32 formatswm42015-06-164-116/+1
| | | | | | | | | | | | | They are useless. Not only are they actually rarely in use; but libavcodec doesn't even output them, as libavcodec has no such sample formats for decoded audio. Even if it should happen that we actually still need them (e.g. if doing direct hardware output), there are better solutions. Swapping the sign is a fast and lossless operation and can be done inplace, so AO actually needing it could do this directly. If you wonder why we keep U8 instead of S8: because libavcodec does it.
* af_lavcac3enc: fix A/V syncwm42015-06-151-3/+17
| | | | | | The filter can buffer singificant amounts of audio. (The proper fix is making the filter chain PTS-aware.)
* af: fix an aspect of filter chain flushingwm42015-06-151-0/+11
| | | | | Even if we flush the current filter, we have to read the remaining output from the frame we previously fed to the filter.
* audio: fill NA channels with silencewm42015-06-121-11/+29
| | | | | | | | | | | | | | | Until now, we didn't do this, because it required some effort, and didn't seem to be necessary. It probably still isn't, but it sounds like a good idea not to output arbitrary data on these channels. The situation is complicated by the fact that just adding new channels to a planar frame would require messing with buffers. So we would have to allocate new buffers and add them to the frame. We could have to maintain an extra buffer pool for this. Avoid this by being "clever", and just allocate a frame with enough channels in the first place. libav/swresample won't know about these channels and won't write to them, but we can grab them in reorder_planes() and use them for the NA channels.
* af_lavrresample: slightly better computation of total delaywm42015-06-041-6/+9
| | | | | | | On libavresample, don't ignore the buffered output data. On libswresample, don't round the total buffer size to the input samplerate.
* af_lavrresample: use a new libswresample function if availablewm42015-06-041-0/+4
| | | | | It was recently added to libswresample, and it does exactly what we need.
* af_lavrresample: change output samples calculationwm42015-06-041-2/+2
| | | | | | This is better, because now we call swr_get_delay() with the output samplerate, instead of with the input samplerate and then multiplying it with the ratio and rounding it up.
* af_lavrresample: use native libavresample function for output sizewm42015-06-021-7/+6
| | | | This also drops the unused get_drain_samples() function.
* af_lavrresample: fix and simplify flushing on playback speed changewm42015-06-021-23/+1
| | | | | | | | | | | This manually retrieved the remaining audio from the resampler. It subtly missed a conversion which could leave to an unsubtle crash. This could happen if reorder_planes() was supposed to insert NA channels, and the resampler/actual output format were different. Simplify it by reusing the normal drain path. One oddness is that the filter will add an output frame outside of normal filtering, but that should be fine.
* audio: make softvol scale cubicwm42015-05-221-2/+5
| | | | | | | | This brings the volume control closer to what is percepted as linear volume change. Adjust the --softvol-max default to roughly the old maximum (roughly doubles the gain).
* af: don't attempt to remove last filter for spdif filter removalwm42015-05-051-1/+1
| | | | | | | | | | | | | | | Some time ago, a mechanism was added for automatically removing PCM-only filters if the input format is spdif. This could cause an infinite loop if the AO did not support spdif, but was falling back to some PCM format. Then this code tried to remove the last filter, which is a dummy filter for receiving and queuing filter output. af_remove() simply fails gracefully in this case, so this happens over and over again. Fix by explicitly checking whether the filter to remove is a dummy filter. (af_remove() also fails only if the dummy filters are attempted to be removed - checking this directly is simpler.)
* af_lavrresample: remove dead undefswm42015-05-051-3/+0
|
* audio: introduce support for padding channelswm42015-05-051-37/+82
| | | | | | | | | | | | | | | | | | | Some audio APIs explicitly require you to add dummy channels. These are not rendered, and only exist for the sake of the audio API or hardware strangeness. At least ALSA, Sndio, and CoreAudio seem to have them. This commit is preparation for using them with ao_coreaudio. The result is a bit messy. libavresample/libswresample don't have good API for this; avresample_set_channel_mapping() is pretty useless. Although in theory you can use it to add and remove channels, you can't set the channel counts. So we do the ordering ourselves by making sure the audio data is planar, and by swapping the plane pointers. This requires lots of messiness to get the conversions in place. Also, the input reordering is still done with the "old" method, and doesn't support padded channels - hopefully this will never be needed. (I tried to come up with cleaner solutions, but compared to my other attempts, the final commit is not that bad.)
* af_lavrresample: fix drainingwm42015-04-181-8/+8
| | | | | configure_lavrr() clears s->pending, so we have to assign it after that call.
* Update license headersMarcin Kurczewski2015-04-1331-156/+126
| | | | Signed-off-by: wm4 <wm4@nowhere>
* af_lavrresample: minor simplificationwm42015-04-121-4/+4
| | | | | The in/out pointers usually have not much meaning outside of AF_CONTROL_REINIT. Also remove the redundant casts.
* af_lavrresample: allow resetting output sample formatwm42015-04-121-2/+3
| | | | It must be allowed to set format==0.
* audio/filter: fully renegotiate audio formats on every reconfigwm42015-04-121-0/+10
| | | | | | | | | | | | | | | | | | | It could happen that a lavrresample filter would keep its old output format when the decoder changed its output format. This simply happened because the output format was never reset. Normally, this was not an issue, because lavrresample filters only inserted for format conversion were removed on format changes. But if --no-audio-pitch-correction is set and playback speed is changed, then there is a "permanent" lavrresample filter in the filter chain, which shows this behavior. Fix by explicitly resetting output formats for all filters which support it. Note: this can crash with libswresample in some cases. I'm not sure if this is mpv's fault or libswresample's, but since it works with libavresample, I'm going to assume it's not our's.
* audio: automatically deatch filters if spdif prevents their usewm42015-04-072-5/+17
| | | | Fixes #1743 and partially #1780.
* audio: change a detail about filter insertionwm42015-04-072-8/+12
| | | | | | | | | | The af_add() function has a problem: if the inserted filter returns AF_DETACH during init, the function will have a dangling pointer. Until now this was avoided by making sure none of the used filters actually return AF_DETACH, but it's getting infeasible. Solve this by requiring passing an unique label to af_add(), which is then used instead of the pointer.
* audio: make all format query shortcuts macrosKevin Mitchell2015-04-032-2/+2
| | | | | af_fmt_is_float and af_fmt_is_planar were previously inconsistent with AF_FORAMT_IS_SPECIAL/AF_FORMAT_IS_IEC61937
* af_lavrresample: always normalize (libswresample is stupid)wm42015-04-021-0/+4
| | | | | | | | | | libswresample doesn't normalize when remixing to a float format. This will cause clipping due to float samples being out of the allowed range. Fortunately this extremely bad default can be changed. This does not happen with libavresample: it normalizes by default. Fixes #1752.
* af: remove unused functionswm42015-04-012-34/+0
|
* af_bs2b: fix option default valuewm42015-03-221-1/+2
| | | | | | | | | --af=bs2b:help abort()ed because the default value of the "profile" option is not represented by any choice. Fix it by adding an "unset" choice. (It's a bit odd because there's already a "default" choice, which is not default, but I don't care enough about this filter.) Fixes #1712.
* af_lavfi: handle seekingwm42015-03-171-1/+27
| | | | | | | | To handle seeking correctly, we need to flush the filter. libavfilter does not support flushing, so we destroy and recreate it. We also need to handle resume-after-EOF, because the mpv audio code sends an EOF before and after seeking (the latter happens because the player drains the filter chain in a generic way, which "causes" EOF).
* audio: refuse to change playback speed with spdifwm42015-03-071-1/+1
| | | | | | | | | | | | Handle the failure gracefully, instead of exploding and disabling audio. Just set the speed back to 1.0. Also remove the AF_DETACH from af_scaletempo. This actually created a dangling pointer in af_add(), a tricky consequence of af_add() reconfiguring the filter chain and the newly added filter using AF_DETACH. Fortunately the AF_DETACH is not needed (and probably never worked - it comes from MPlayer times, and MPlayer also disables audio when trying to change speed with spdif).
* af_scaletempo: minor simplificationwm42015-03-061-15/+6
|
* af_scaletempo: restore confusing mplayer behaviorwm42015-03-061-3/+9
| | | | | | | | | This matters only when setting obscure scaletempo suboptions. See #1653. (But what we really should do is figuring out how to do this in a sane way.)
* audio: change playback speed directly in resamplerwm42015-03-023-90/+73
| | | | | | | | | | | | | Although the libraries we use for resampling (libavresample and libswresample) do not support changing sampelrate on the fly, this makes it easier to make sure no audio buffers are implicitly dropped. In fact, this commit adds additional code to drain the resampler explicitly. Changing speed twice without feeding audio in-between made it crash with libavresample inc ertain cases (libswresample is fine). This is probably a libavresample bug. Hopefully this will be fixed, and also I attempted to workaround the situation that crashes it. (It seems to point in direction of random memory corruption, though.)
* af_rubberband: actually fix deadlockMartin Herkt2015-02-121-1/+1
| | | | 371e5d0 missed this one
* af_rubberband: fix filter error deadlockwm42015-02-121-2/+2
| | | | | | | | | | | | rubberband_available() can return a negative value, which we assigned to a size_t variable, leading to the frame allocation to fail. This could spam "Error filtering frame.". (That it spams this instead of exiting should probably also be considered a bug.) At least in the realtime mode and in our case, a negative return value should not have any different meaning from a 0 return value, in particular because we call rubberband_get_samples_required() or set the "final" parameter for rubberband_process() to continue/stop processing.
* af_rubberband: change defaultsMartin Herkt2015-02-121-9/+6
| | | | | | | | | After some testing, I am fairly convinced that these defaults sound better than the previous settings. This also eliminates some issue with random crackling and noise. Also remove the `stretch` option since it has no effect in realtime mode.
* af_rubberband: fix breakagewm42015-02-111-1/+3
| | | | | | | | | The previous commit on this filter accidentally removed the RubberBandOptionProcessRealTime option. Without it, the lib prints a warning and passes the audio through. Also add the RubberBandOptionSmoothingOn option back. Though for some reason the output sounds still very wrong.
* af_rubberband: make all librubberband options configurablewm42015-02-111-4/+43
| | | | | | | librubberband exports a big load of options. Normally, the default settings (whether they're librubberband defaults or our defaults) should be sufficient, but since I'm not so sure about this, making it configurable allows others to figure it out for me.
* af_rubberband: attempt to fix audio position calculationwm42015-02-111-4/+17
| | | | | | | | | | | The problem here is that librubberband can buffer an arbitrary amount of data, but at the same time doesn't provide a way to query how much data is buffered. So we keep track of this manually, assuming that librubberband tries to reach the requested time ratio for input and output (which is probably true). The disadvantage is that rounding errors could accumulate over time. (Maybe it should try to round towards keeping the time ratio.)
* af_rubberband: always calculate and set delaywm42015-02-111-12/+11
| | | | Basically, add an if and reindent the block instead of exiting early.
* af: account for queued frames in audio position calculationwm42015-02-111-0/+2
| | | | af_rubberband exposed this issue.
* af_rubberband: improve EOF handlingwm42015-02-111-5/+11
| | | | | | In theory it could happen that draining on EOF happens incrementally, and then the unconditional reset could have dropped the remaining buffered audio.
* af_rubberband: pitch correction with librubberbandwm42015-02-112-0/+173
| | | | | | | | | If "--af=rubberband" is used, librubberband will be used to speed up or slow down audio with pitch correction. This still has some problems: the audio delay is not calculated correctly, so the audio position jitters around by a few milliseconds. This will probably ruin video timing.
* af_scaletempo: allow changing speed at runtime without reinitwm42015-02-101-18/+21
| | | | | | | | | | | | | | | | Staring at the code a bit, it turns out that changing speed without losing state is quite easy. The initialization code is big and complicated, but most of it is specific only to the configured audio format, not the speed. Refactor the code so that changing speed at runtime could work. (It's not actually used yet - the player code still does a complete reinit. This will be fixed in the next commit.) The "if (s->speed_tempo == s->speed_pitch)" looks a bit strange, but does the same thing as the code did before: speed can be changed only if exactly one flag is set. If both are set or none, speed can't be changed.
* af_scaletempo: drop detaching or skipping init on speed=1wm42015-02-101-7/+5
| | | | | | | | | | | | | | | | | | This code skipped initialization if no speed/pitch change was to be applied. It also didn't force conversion of the audio to a supported format, which is probably the most important case in context of compatibility. With this change applied, af_scaletempo will always force format conversion. To make the change less disruptive, make the filter detach if unconvertable formats are used. Some users use spdif and also have "af=scaletempo" in their config, so better not completely break this. In the case the filter was added with the "speed=both" suboption, the filter also detached itself in this case; but it's an obscure case, so I don't care about that.
* af: remove old filter compatibility hackwm42015-01-152-42/+1
|
* audio/filter: switch remaining filters to refcountingwm42015-01-154-44/+58
| | | | | All of these filters are very similar in frame management, and copy data to a new frame during filtering.
* audio/filter: switch remaining in-place filters to refcountingwm42015-01-159-127/+134
| | | | | | | | | | | | | | | | | | Adds about 7 lines of boilerplate per filter. This could be avoided by providing a different entrypoint (something like af->filter_inplace), which would basically mirror the old interface exactly for this kind of filter. But I feel like it would just be a hack to support all those old, useless filters better. (The ideal solution would be using a language that can do closures to provide a compat. wrapper, but whatever.) af_bs2b has terribly repetitious code for setting up filter functions for each format (most of them useless, in addition to bs2b being useless), so I did something terrible with macros. af_sinesuppress had commented code for float filtering (maybe it was broken; it has been commented every since it was added in 2006). Remove this code.
* af: verify filter input formatswm42015-01-151-1/+4
| | | | | | | | | | | Just to make sure all filters get the correct format. Together wih the check in af_add_output_frame(), this asserts that af->prev->fmt_out == af->fmt_in This also requires setting the "in" pseudo-filter (s->first) formats correctly. Before this commit, the fmt_in/fmt_out fields weren't used for this filter.
* af_lavcac3enc: use refcounted frameswm42015-01-141-89/+95
|
* af_lavfi: use refcounted frameswm42015-01-141-44/+57
|
* audio/filter: actually set fmt_in/fmt_out fieldswm42015-01-141-0/+2
|
* af_scaletempo: use refcounted frameswm42015-01-141-11/+23
|
* af_lavrresample: use refcounted frameswm42015-01-141-23/+46
|
* af_convert24: use refcounted frameswm42015-01-131-8/+13
| | | | | This requires allocating a fully new frame. 32->24 could be in-place, but this is not possible for 24->32.
* audio/filters: use refcounted frames for some in-place filterswm42015-01-133-7/+31
| | | | | These are also quite simple, but require requesting write access to the frames. The error handling (for OOM) is a bit annoying.
* audio/filters: use refcounted frames for some simple filterswm42015-01-134-10/+18
| | | | These are read-only, and very trivial to convert.
* af_volume: use refcounted frameswm42015-01-131-8/+15
|
* audio: use refcounted frames in the filter chainwm42015-01-132-53/+190
| | | | | | | | | | | | | | | | | | | The goal is switching the whole audio chain to using refcounted frames. This brings the architecture closer to FFmpeg, enables better integration with libavfilter, will reduce useless copying somewhat, and will probably allow better timestamp tracking. For now, every filter goes through a semi-awful wrapper in af_do_filter(), though. This will be fixed step by step, and the wrapper should eventually be removed. Another thing that will have to be done is improving the timestamp handling and avoiding extra copies for the AO. Some of the new code is rather similar to the video filter code (the core filter code basically just has types replaced). Such code duplication is normally very unwanted, but in this case there's probably no other choice. On the other hand, this code is pretty simple (even if somewhat tricky). Maybe there will be unified filter code in the future, but this is still far away.
* audio/filter: remove unused af_calc_filter_multiplier()wm42015-01-136-31/+2
| | | | | | | | | | | | The purpose of this function was to filter only as much audio input as needed to produce a certain amount of audio output. This could (in theory) avoid excessive buffering when e.g. changing playback speed with resampling. Use of this was already removed in commit 5fd8a1e0. No problems were experienced, so let's assume this feature is practically worthless. (Though it's possible that it was quite useful over a decade ago, or in some cornercases with evil files.)
* af_volume: dump applied replaygain in verbose modewm42015-01-041-1/+5
|
* win32: add mmap() emulationwm42014-12-262-3/+0
| | | | | | | | Makes all of overlay_add work on windows/mingw. Since we now don't explicitly check for mmap() anymore (it's always present), this also requires us to make af_export.c compile, but I haven't tested it.
* af_hrtf: Fix out-of-range read.reimar2014-12-061-2/+7
| | | | | | | Based on patch by Yuriy Kaminskiy [yumkam gmail]. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@37330 b3059339-0415-0410-9bf9-f77b7e298cf2 Signed-off-by: wm4 <wm4@nowhere>
* audio: make mp_audio_config_to_str return a stack-allocated stringwm42014-11-251-8/+3
| | | | Simpler overall.
* af_scaletempo: use float division for ratewm42014-11-211-1/+1
| | | | | | | | From what I understand the division is to align the dimension of the value from seconds to milliseconds. Hard to tell whether the "rounding" was intentional or not; I'm tipping on "not". Found by Coverity.
* Remove some unneeded NULL checkswm42014-11-211-5/+6
| | | | Found by Coverity; also see commit 85fb2af3.
* af: remove redundant functionwm42014-11-121-9/+2
|
* af: check audio params for validitywm42014-11-121