summaryrefslogtreecommitdiffstats
path: root/audio/filter
Commit message (Collapse)AuthorAgeFilesLines
* af_lavrresample: fudge some channel layout conversionwm42016-01-181-0/+33
| | | | | | | | | | | | Prevents channels from being dropped, e.g. when going 7.1 -> 7.1(wide) and similar cases. The reasoning here is that channel layouts over HDMI don't work anyway, and not dropping a channel and playing it on a slightly "wrong" (but expected) speaker is preferable to playing silence on these speakers. Do this to remove issues with ao_coreaudio. Frankly I'm not sure whether our mapping (between CA and mpv/FFmpeg speakers) is correct, but on the other hand due to the reasons stated above it's not all that meaningful.
* af_lavrresample: fix build on Libavwm42015-11-261-1/+1
| | | | | | | Of course, only FFmpeg has av_clipd(), while Libav does not. (Nevermind that it doesn't do much more than the mpv MPCLAMP() macro. Supposedly, libavutil can provide optimized platform-specific versions for av_clip*, but of course nothing actually does for av_clipf() or av_clipd().)
* af_lavrresample: clamp float output to rangewm42015-11-251-0/+12
| | | | | | | libswresample doesn't do it - although it should, but the patch is stuck in limbo. Probably reduces problems with artifacts on downmixing in some cases.
* af_lavrresample: simplify set_compensation usagewm42015-11-111-13/+12
| | | | | | | | | | | | | Just set the ratio directly by working around the intended semantics of the API function. The silly rounding stuff we had isn't needed anymore (and not entirely correct anyway). Note that since the compensation is virtually active forever, we need to reset if it's not needed. So always run this code to be sure to reset it. Also note that libswresample itself had a precision issue, until it was fixed in FFmpeg commit 351e625d.
* audio: do not require full audio chain reinit for speed changeswm42015-11-041-3/+0
| | | | | | | | | | | | | | | Actually, it didn't really require that before (most work was avoided), but some bits had to be run anyway. Separate the speed change into a light-weight function, which merely updates already created filters, and a heavy-weight one which messes with filter insertion. This also happens to fix the case where the filters would "forget" the current speed (force resampling, change speed, hit a volume control to force af_volume insertion - it will reset speed and desync). Since we now always run the light-weight function, remove the af_scaletempo verbose message that is printed on speed setting. Other than that, all setters are cheap.
* af_lavcac3enc: simplify/fix AVPacket handlingwm42015-11-041-16/+21
| | | | | | For some reason, the encoder didn't like that the AVPacket already had fields set. I'm not quite sure, but this might just be invalid API usage. Do it as it's recommended.
* Revert "af_lavrresample: don't drop sl/sr channels for 7.1 on ALSA"wm42015-11-041-28/+5
| | | | | | | | | | | This reverts commit 4e358a963604af8746a059d7388cb202be0f919d. Testing shows the channel pairs must indeed be swapped (details see commit message of the reverted commit). Making the downmix code move sl/sr to sdl/sdr is not an appropriate solution anymore, and it's better to fix the unusual channel layout in ao_alsa.c directly. (Not reverting the change in chmap.c; this is still correct.)
* af_lavrresample: don't drop sl/sr channels for 7.1 on ALSAwm42015-11-031-5/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ao_alsa: attempt to fix 7.1 over HDMI The last 2 channels of 7.1 (RLC/RRC in ALSA) were exported as sdl/sdr instead of sl/sr (I don't even know why I chose sdl/sdr, but SL/SR and RLC/RRC are different in the ALSA API). libsw/avresample do not move the sl/sr channels to sdl/sdr when rematrixing, so silence was sent for 2 channels. If my selection of sdl/sdr is essentially API abuse, there's no reason why they should do this differently. The mess here is really that ALSa doesn't map the HDMI layouts cleanly. Most ALSA drivers export 7.1 in a way compatible to our expectations, but Intel HDA/HDMI does not: mpv/ffmpeg: fl-fr-fc-lfe-bl-br-sl-sr ALSA/generic: FL FR FC LFE RL RR SL SR [1] ALSA/HDMI: FL FR LFE FC RL RR RLC RRC [2] The HDMI layout is layout 0x13 (going by CEA-861-B). The comment in the kernel code has to be correct too. The early standard defines only 1 other layout, which replaces RLC/RRC with FRC/FLC - this probably corresponds to what we call "7.1(wide)". So it appears when ALSA requests RLC/RRC, we should feed it sl/sr. To make it more complicated, Kodi/xbmc apparently also have to deal with ALSA being special, but instead of sending sl/sr to RLC/RRC, they swap the last two pairs of the layout, and send sl/sr to RL/RR and bl/br to RLC/RRC. Or I might have misunderstood their code. I don't have a 7.1-capable A/V receiver, so I can't test this. For now, go with the simpler solution, and wait until someone tests it. If the speakers end up swapped, a completely different solution will be needed. [1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/sound/core/pcm_lib.c?id=refs/tags/v4.3#n2434 [2] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/sound/pci/hda/patch_hdmi.c?id=refs/tags/v4.3#n307
* Replace deprecated av_free_packet() callswm42015-10-281-1/+1
| | | | | | av_free_packet() got finally deprecated. Use av_packet_unref() instead, which has almost the same semantics, has existed for a while, and is available in all FFmpeg and Libav versions we support.
* audio: use AVFrames with more than 8 channels correctlywm42015-10-261-3/+5
| | | | | | | Requires messy dealing with the extended_ fields. Don't bother with af_lavfi and ao_lavc for now. There are probably no valid use-cases for these.
* af_lavrresample: make planarization pass work with >8 channelswm42015-10-261-4/+5
| | | | | | | | | | av_get_default_channel_layout() fails with channel counts larger than 8. The channel layout doesn't need to make sense, so pick an arbitrary fallback. libswresample also has options for setting the channel counts directly, but better not introduce new concepts in the code. Also, libavresample doesn't have these options.
* af: prevent endless loop when removing filters due to spdifwm42015-10-261-1/+2
| | | | | | | | | | | | | | | | | | | | | This code removes filters which can not take spdif inout. This was made so that PCM filters are transparently dropped in spdif mode. This entered an endless loop with: --af=lavcac3enc:::2 --audio-channels=5.1 The forced number of output channels is incompatible with spdif. It's trying to insert af_lavrresample as conversion filter to compensate for it. Of course this doesn't work, which triggers the PCM filter removal. Then it goes on normally - since the new state is exactly as before, it will try the same thing again, forever. Fix by reusing the retry counter, which is a very dumb but very effective measure against these cases of filter negotiation failure. We could try to be more clever (for example, if the removed filter is a conversion filter, we can be sure this won't work, and error out immediately). But better keep it simple and robust.
* af_lavrresample: fix unintended audio drift when setting playback speedwm42015-10-141-3/+9
| | | | | | | | | | | | | | Small adjustments to the playback speed use swr_set_compensation() to stretch the audio as it is required. But since large adjustments are now handled by actually reinitializing libswresample, the small adjustments get rounded off completely with typical frame sizes. Compensate for this by accounting for the rounding error and keeping track of fractional samples that should have been output to achieve the correct ratio. This fixes display sync mode behavior, which requires these adjustments to be relatively accurate.
* af_lavrresample: reinit resampler on large speed changeswm42015-10-121-15/+19
| | | | | | swr/avresample_set_compensation() was made for small speed adjustments. Non-documentation says it should be used for changes not larger than 1%, so reinitialize the sampler if the change is larger than that.
* af_lavrresample: use libswsresample dynamic rate adjustment featurewm42015-10-071-9/+26
| | | | | | | | | | swr_set_compensation() changes the apparent sample rate on the fly (who would have guessed). It is thus very well-suited for adjusting audio speed on the fly during playback (like needed by the display-sync mode). It skips the relatively slow resampler reinitialization. If this doesn't work (libswresample soxr backend), then fall back to the old method.
* audio/filter: remove reentrancy flagwm42015-09-205-22/+1
| | | | | | | | | | This flag was used by some filters and made sure none of these filters were inserted twice. This triggers only if the user explicitly tries to add multiple filters (and not e.g. due to auto-insertion), so at best this warned the user from doing something potentially pointless. At worst, it blocked some (mildly) legitimate use-cases. Get rid of it. Also see #2322.
* af_lavfi: implement af-metadata propertywm42015-09-113-0/+37
| | | | | | | Works like vf-metadata. Unfortunately requires some code duplication (even though it's not much). Fixes #2311.
* af: use generic statuc codeswm42015-09-111-7/+7
| | | | | | | The reason MPlayer traditionally duplicated them all over the place is that it wanted every component to be a self-contained library (e.g. audio filters were in "libaf"). But this is not necessarily helpful, and this change makes the following commit a bit simpler.
* af_lavrresample: remove unnecessary indirectionswm42015-09-081-35/+30
| | | | | | | Not sure why struct af_resample_opts even exists. It seems useful to group the fields set by user options. But storing the current format conversion parameters doesn't seem very elegant, and having a separate instance in the "ctx" field isn't helpful either.
* af_lavrresample: add normalize suboptionwm42015-09-081-1/+6
|
* af_lavrresample: add missing include statementwm42015-09-041-0/+1
| | | | | | Apparently, this broke compilation with Libav under some circumstances. Looking at it again, it shouldn't have, but this change doesn't hurt anyway.
* audio/filter: remove af_bs2b toowm42015-09-042-171/+0
| | | | | | | Some users still use this filter, so the filter was going to be kept. But I overlooked that libavfilter provides this filter. Remove the redundant wrapper from mpv. Something like --af=lavfi=bs2b should work and give exactly the same results.
* audio/filter: remove some useless filterswm42015-09-0317-3934/+0
| | | | | | | | | | | | | | | | | | | | | | | | All of these filters are considered not useful anymore by us. Some have replacements in libavfilter (useable through af_lavfi). af_center, af_extrastereo, af_karaoke, af_sinesuppress, af_sub, af_surround, af_sweep: pretty simple and useless filters which probably nobody ever wants. af_ladspa: has a replacement in libavfilter. af_hrtf: the algorithm doesn't work properly on most sources, and the implementation was buggy and complicated. (The filter was inherited from MPlayer; but even in mpv times we had to apply fixes that fixed major issues with added noise.) There is a ladspa filter if you still want to use it. af_export: I'm not even sure what this is supposed to do. Possibly it was meant for GUIs rendering audio visualizations, but it couldn't really work well. For example, the size of the audio depended on the samplerate (fixed number of samples only), and it couldn't retrieve the complete audio, only fragments. If this is really needed for GUIs, mpv should add native visualization, or a proper API for it.
* audio: remove unused legacy libavutil headerwm42015-08-072-2/+0
| | | | It was never used, but is a leftover from old times.
* audio: remove af_dummywm42015-08-012-63/+0
| | | | Was used internally once; has no function anymore.
* af_lavrresample: always reinit resampler on filter reinitwm42015-07-191-18/+1
| | | | | | | | This was a minor optimization to potentially avoid resampler reconfiguration when the filter is reinitialized. But filter reinitialization is a rare event, and the case when no reconfiguration is needed is even rarer. As such, this is an unnecessary micro- optimization and only adds potential for bugs.
* af_lavrresample: don't unnecessarily print remix messagewm42015-07-191-8/+8
| | | | | | | | | This message bloats verbose log output if e.g. audio speed is frequently readjusted, such as when syncing audio to video. So don't print the message if only speed is changed. (This case requires reconfiguration, but can't change the input/output channel maps.) Also do not print the message if no remixing is done at all.
* af: fix behavior with pathologic filter chainswm42015-07-071-0/+2
| | | | | | | | Some filter chains require a huge number of auto-inserted conversion filters. There is an overly stupid safeguard against infinite filter insertions, which counts the number of conversion filters inserted. This triggered accidentally in this case. Fix by resetting this counter after a non-conversion filter was successfully configured.
* af_lavrresample: log actual channel layout conversionswm42015-06-301-3/+6
| | | | | With all the reordering etc. that can go on in this filter, it's useful to see what upmix/downmix it's actually performing.
* audio: fix format function consistency issueswm42015-06-264-5/+5
| | | | | | | | | | | Replace all the check macros with function calls. Give them all the same case and naming schema. Drop af_fmt2bits(). Only af_fmt2bps() survives as af_fmt_to_bytes(). Introduce af_fmt_is_pcm(), and use it in situations that used !AF_FORMAT_IS_SPECIAL. Nobody really knew what a "special" format was. It simply meant "not PCM".
* af: move af_from_dB() function to af_volume.cwm42015-06-233-22/+11
| | | | | And also simplify it (it certainly had the most awkward API you could think of for such a simple function).
* af_volume: add a replaygain fallback optionwm42015-06-231-0/+5
|
* af_lavrresample: free and reallocate resample context on reconfigwm42015-06-221-30/+35
| | | | | | | | This avoids keeping "bad" state from previous reconfig calls, such as the internal_sample_format option (which is set only on the first reconfig call). There's no advantage to keeping the resample contexts around anyway.
* af_lavrresample: fix commentwm42015-06-221-4/+4
| | | | | mp_format is not a libavresample input format here, and the comment was more confusing than it helped.
* af: restore detaching of PCM filters when using spdifwm42015-06-223-1/+14
| | | | | | Basically, af_fix_format_conversion() behaves stupid you insert a conversion filter that won't work, and adding back the conversion test function is the simplest fix to it.
* af_lavrresample: don't flush in uninitialized statewm42015-06-221-1/+2
| | | | libswresample verbosely complains.
* Various spelling fixesMarcin Kurczewski2015-06-185-8/+8
| | | | Signed-off-by: wm4 <wm4@nowhere>
* af_lavrresample: include osdep/endian.hwm42015-06-171-0/+1
| | | | The 24 bit conversion code needs the relevant preprocessor symbols.
* af: remove conversion filter searchwm42015-06-163-94/+4
| | | | | | This attempted to find a minimal filter graph for a format conversion involving multiple conversion filters. With the last 2 commits it becomes dead code - remove it.
* af_convert24: remove this filterwm42015-06-162-123/+0
|
* af_lavrresample: integrate 24 bit (3 bytes per sample) outputwm42015-06-161-9/+48
| | | | | | | | | | | | Now af_lavrresample can output 24 bit samples directly, by doing the conversion "inline". Luckily, S32->S24 can be done in-place, so this isn't too much work. But the output conversion logic (which seems to be adding up) gets slightly more complicated again. Normally this is done by af_convert24. But having multiple conversion filters complicates some aspects of the filter chain. S24 output is the only thing the code for multiple conversion filters is still needed for, and getting rid of that is preferable.
* af_lavrresample: always fill reorderwm42015-06-161-1/+1
| | | | | | If the code path for additional output conversion is active, reorder_planes() is always called, even if the reorder_out array wasn't filled. This is obviously wrong - always fill this array.
* 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