summaryrefslogtreecommitdiffstats
path: root/audio
Commit message (Collapse)AuthorAgeFilesLines
* ad_spdif: handle deprecated FF_PROFILE_* definitionsDudemanguy2024-03-051-7/+13
| | | | See: https://github.com/FFmpeg/FFmpeg/commit/8238bc0b5e3dba271217b1223a901b3f9713dc6e
* misc/jni: reduce duplication in mapping structsfan52024-02-281-66/+66
| | | | | 'name' was in fact unused when reading fields or methods, so it can be merged with 'method'. Also changed the type of 'mandatory' to bool.
* misc/jni: introduce macros for deleting referencessfan52024-02-281-43/+24
|
* ao_audiotrack: refactor JNI class retrievalsfan52024-02-281-68/+77
| | | | | | - split mapping from field struct - mark field struct static - define list of classes to reduce more repetitive code
* ao_audiotrack: remove two dead variablessfan52024-02-281-9/+0
|
* ao_audiotrack: fix missing check for passthrough supportsfan52024-02-281-0/+4
|
* osdep/mac: make mac naming of files, folders and function consistentder richter2024-02-281-1/+1
| | | | | rename all macOS namings (osx, macosx, macOS, macos, apple) to mac, to make naming consistent.
* ao: don't clip floating point formats at non-unity gainnanahi2024-02-251-1/+1
| | | | | | | | | | | | | | | | | Currently, the softvol gain control attempts to clip floating point ao formats within -1 and +1. However, this is "optimized out" at unity gain, where no clipping is applied. This results in inconsistent behavior when the source audio is already out of -1 and +1 range, where a gain of 0.99 results in clipping, but not at exactly 1. Since a big advantage of floating point audio data is that they do not lose information through out-of-range data because the ao sink can apply suitable negative gain to prevent clipping before converting them to integer formats, clipping should not be performed on these data. Fix this by removing the existing clipping behavior. It now results in a simple multiplication, which faciliates compiler auto-vectorization of this operation over audio data.
* ao_wasapi: scale queried AO volume to (0, 100)sunpenghao2024-02-241-2/+2
| | | | This was done for `AOCONTROL_SET_VOLUME` but not `AOCONTROL_GET_VOLUME`.
* ao_wasapi: address premature buffer fills in exclusive modesunpenghao2024-02-242-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, running AO control wakes up the WASAPI renderer thread in the `WASAPI_THREAD_FEED` state, where `thread_feed` will be called. However, it seems that in recent Windows versions (tested on Windows 10 build 19044.3930 and Windows 11 build 22631.3007) we can't know if it is safe to feed more audio data in event-driven exclusive mode: - `IAudioClient_GetCurrentPadding` always returns `bufferFrameCount`, even if *NO* data has ever been written. This means we don't know how much free space we have that is available for writing. This is not the case in shared mode, where the return value correctly reflects the size of data waiting to be processed. As a sidenote, MS did not document the precise definition of the return value for an event-driven, exclusive stream [1]. - `IAudioRenderClient_GetBuffer` never fails. We can call it for 10 times in a roll, each time requesting an entire buffer (the unit at which data is exchanged in exclusive mode using event-driven buffering; there are 2 such buffers) and get a successful return code everytime. In shared mode, we get `AUDCLNT_E_BUFFER_TOO_LARGE` if we request a buffer larger than that currently available. As a result, `thread_feed` will always write `bufferFrameCount` frames of audio in exclusive mode. There will therefore be glitches each time `thread_control` is called due to the subsequent `thread_feed` overwriting frames yet to be processed. Also, an irreversible error is accumulated to `sample_count` as long as there is no AO reset, leading to eventual, unbounded A/V desync. As a fix to the issue, add a dedicated state for dispatch queue processing so that `thread_feed` is only called when signaled by the OS. The buffer checks in `thread_feed` that use `GetCurrentPadding` in exclusive mode are kept in case there are older versions where the two APIs behave differently. Closes #12615. [1] https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-iaudioclient-getcurrentpadding
* various: make mentions of macOS consistentder richter2024-02-211-2/+2
| | | | | change all mentions and variations of OSX, OS X, MacOSX, MacOS X, etc consistent. use the official naming macOS.
* af_lavcac3enc: don't use deprecated `avcodec_close`llyyr2024-02-191-1/+9
| | | | | | | | Deprecated upstream https://github.com/FFmpeg/FFmpeg/commit/1cc24d749569a42510399a29b034f7a77bdec34e We need to reallocate the context here because `avcodec_free_context` also frees the context, and we want to reuse the context with some reconfig.
* ao_pipewire: add support for SPDIF formatsThomas Weißschuh2024-02-151-15/+46
|
* ao_pipewire: don't interpret unknown formatsThomas Weißschuh2024-02-151-7/+5
| | | | | | Interpreting data in the wrong sample format has unpredictable results and may damage hardware and hurt users. Instead error out.
* ao_sndio: add missing config.h includeKacper Michajłow2024-02-071-0/+2
|
* audio: rename ao_read_data_unlockedThomas Weißschuh2024-02-051-4/+4
| | | | | | | | | As mentioned in [0] the suffix "_locked" would have been the appropriate naming in line with similar uses inside mpv. See `mp_abort_recheck_locked()`, `mp_abort_trigger_locked()`, `retrigger_locked()`, `wakeup_locked()`... [0] https://github.com/mpv-player/mpv/pull/12811#discussion_r1477518525
* ad_spdif: fix DTS 44.1khz passthrough playbackAlex Mitzsch2024-01-241-1/+1
| | | | Fix DTS passthrough playback of 44.1 khz content. Also, take into account that there are some DTS variants with a samplerate of 96khz (e.g. DTS 24/96), somehow they are recognized wrongly as 48khz by the code. Don´t rely on this "bug", do it correctly. Now every samplerate above 44.1Khz is correctly treated as 48khz, and 44.1khz files are treated as 44.1khz for bitstreaming.
* chmap: mp_image_pool: drop stale mentions of Libav in commentsllyyr2024-01-201-4/+4
|
* ao_null: fix reset() implementationsfan52024-01-121-1/+2
| | | | | | | | Stopping output implies that it can't be paused anymore. This is consistent with the documented API in internal.h as well as the behavior of other AOs. resolves #13267
* various: use correct PATH_MAX for win32sfan52023-12-271-2/+3
| | | | | | | | In commit c09245cdf2491211f3e0bfe47f28cc0e0a2e05c8 long-path support was enabled for mpv without actually making sure that there was no code left that used the old limit (260 Unicode chars) for buffer sizes. This commit fixes all but one case.
* ao_wasapi: clean GUID definitionsKacper Michajłow2023-12-031-28/+41
| | | | | Add ifndefs to define only when needed and remove some already defined ones in mingw.
* ao_wasapi: fix MP3 GUIDKacper Michajłow2023-12-031-1/+1
| | | | | | | While CEA-861 defines MP2 as 0x5 and MP3 as 0x4, the GUIDs defined in ksmedia.h are in reverse order. See: https://github.com/MicrosoftDocs/windows-driver-docs/pull/3742
* ao_sndio: remove duplicated conditionKacper Michajłow2023-11-281-1/+1
|
* meson: adjust win32 definesKacper Michajłow2023-11-251-0/+1
| | | | | | | | - Don't define _GNU_SOURCE on Windows, no need - Define WIN32_LEAN_AND_MEAN to strip some unneded headers from windows.h - Define NOMINMAX and _USE_MATH_DEFINES as they are common for Windows headers
* ao_coreaudio_chmap: suppress vla warningKacper Michajłow2023-11-241-2/+2
|
* various: replace some OOM handlingsfan52023-11-241-4/+2
| | | | | | We prefer to fail fast rather than degrade in unpredictable ways. The example in sub/ is particularly egregious because the code just skips the work it's meant to do when an allocation fails.
* ao/coreaudio_exclusive: fix segfault when changing formatsleetoburrito2023-11-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR #12747 missed updating a variable declaration in `ca_change_physical_format_sync`, which ultimately leads to the thread crashing. The problem reproduces consistently on AS Macs (I don't have an Intel Mac to test on anymore), and produces stack traces like the following: ``` Thread 3 Crashed:: mpv 0 libsystem_kernel.dylib 0x18cebd11c __pthread_kill + 8 1 libsystem_pthread.dylib 0x18cef4cc0 pthread_kill + 288 2 libsystem_c.dylib 0x18ce04ad4 __abort + 136 3 libsystem_c.dylib 0x18cdf56c4 __stack_chk_fail + 96 4 mpv 0x1026b66d0 ca_change_physical_format_sync + 420 5 mpv 0x1026b3b70 init + 1052 6 mpv 0x1025c5afc ao_init + 332 7 mpv 0x1025c5bec ao_init + 572 8 mpv 0x1025c5830 ao_init_best + 1228 9 mpv 0x102622fac fill_audio_out_buffers + 1820 10 mpv 0x1026450d0 run_playloop + 132 11 mpv 0x10263f958 play_current_file + 5116 12 mpv 0x10263e4e8 mp_play_files + 452 13 mpv 0x102641308 mpv_main + 128 14 mpv 0x10269f520 playback_thread + 40 15 libsystem_pthread.dylib 0x18cef5034 _pthread_start + 136 16 libsystem_pthread.dylib 0x18ceefe3c thread_start + 8 ``` Note that non-exclusive output seems to be unaffected. To reproduce this problem (and/or test this fix), pass `--audio-exclusive=yes` to mpv.
* ao_wasapi: add missing comma in strings arrayKacper Michajłow2023-11-181-1/+1
|
* audio: fix UB when casting INFINITY to integerKacper Michajłow2023-11-151-3/+3
| | | | | | Fixes busy wait, because in practice inf would be casted to 0. Fixes: 174df99
* audio: avoid unnecessary silence padding in read_buffer()Thomas Weißschuh2023-11-081-11/+14
| | | | | Not all callers of read_buffer() require the buffer to be padded with silence.
* ao_audiotrack: switch to ao_read_data_nonblocking()Thomas Weißschuh2023-11-081-1/+1
|
* ao_coreaudio: switch to ao_read_data_nonblocking()Thomas Weißschuh2023-11-081-1/+1
|
* ao_pipewire: switch to ao_read_data_nonblocking()Thomas Weißschuh2023-11-081-1/+1
| | | | Avoid blocking the process callback as it runs with realtime privileges.
* audio: introduce ao_read_data_nonblocking()Thomas Weißschuh2023-11-082-10/+38
| | | | | This behaves similar to ao_read_data() but does not block and may return partial data.
* ALL: use new mp_thread abstractionKacper Michajłow2023-11-057-92/+87
|
* various: remove trailing whitespaceGuido Cella2023-10-301-1/+1
|
* ao_coreaudio: signal buffer underrunsUmar Getagazov2023-10-291-1/+8
| | | | | Change the resulting buffer sizes to match the actual amount of samples read, and set a flag in case no samples were read at all.
* mp_threads: rename threads for consistent naming across all of themKacper Michajłow2023-10-272-2/+2
| | | | | | | | I'd like some names to be more descriptive, but to work with 15 chars limit we have to make some sacrifice. Also because of the limit, remove the `mpv/` prefix and prioritize actuall thread name.
* semaphore_osx: change mp_sem_timedwait to mp_timeKacper Michajłow2023-10-261-2/+2
|
* semaphore_osx: don't overwrite global symbolsKacper Michajłow2023-10-261-5/+5
|
* Revert "audio: don't block on lock in ao_read_data"sfan52023-10-241-2/+1
| | | | | | | | | | It was found that this causes issues with at least ao_coreaudio, essentially revealing a way bigger issue: Some AOs don't check for 0 and/or have no way to deal with short writes. Someone will have to figure out a fix later but get rid of the direct cause for now. This reverts commit ae908a70cecebb2cac8354a3b4d8967af847bd3e.
* audio: don't block on lock in ao_read_dataThomas Weißschuh2023-10-201-1/+2
| | | | | | | ao_read_data() is used by pull AOs potentially from threads managed by external libraries. These threads can be sensitive to blocking. For example the pipewire ao is using a realtime thread for the callbacks.
* various: sort some standard headersNRK2023-10-204-5/+7
| | | | | | | | | | | | since i was going to fix the include order of stdatomic, might as well sort the surrouding includes in accordance with the project's coding style. some headers can sometime require specific include order. standard library headers usually don't. but mpv might "hack into" the standard headers (e.g pthreads) so that complicates things a bit more. hopefully nothing breaks. if it does, the style guide is to blame.
* osdep: remove atomic.hNRK2023-10-206-5/+9
| | | | | | | replace it with <stdatomic.h> and replace the mp_atomic_* typedefs with explicit _Atomic qualified types. also add missing config.h includes on some files.
* ao: convert all timing code to nanosecondsDudemanguy2023-10-1613-60/+61
| | | | | | | Pull AOs work off of a callback that relies on mpv's internal timer. So like with the related video changes, convert all of these to nanoseconds instead. In many cases, the underlying audio API does actually provide nanosecond resolution as well.
* timer: add convenience time unit conversion macrosDudemanguy2023-10-161-3/+3
| | | | | | | There's a lot of wild 1e6, 1000, etc. lying around in the code. A macro is much easier to read and understand at a glance. Add some helpers for this. We don't need to convert everything now but there's some simple things that can be done so they are included in this commit.
* af_scaletempo2: better defaultsChristoph Heinrich2023-10-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Why a bigger search-interval is required: scaletempo2 doesn't do a good job when the signal contains frequencies less then 1/search_interval. With a search interval of 30ms that means anything below 33.333Hz sounds bad. Depending on the genre it's very for music to contain frequencies down to 30Hz, and sometimes even a little bit below that. Therefore a higher default value is needed to handle such cases. Based on that an argument can be made for a value of 50, as that should work down to 20Hz, or something even higher because movies sometimes have some infrasonic content. However the downside of big search intervals is increased CPU usage and intelligibility at higher speeds, as it effectively leads to parts of the audio being skipped. A value of 40 can handle frequencies down to 25Hz, enough for all music except very rare edge cases, while still providing decent intelligibility. Why a smaller window-size is required: Large values reduce intelligibility at high speeds and therefore small values are preferred. However when values get too small it starts to sound weird (similar to librubberband). In my testing a value of 10 already works well, but adding a small safety margin seems like a good idea, especially since it made no noticeable difference to intelligibility, which is why 12 was chosen.
* timer: change mp_sleep_us to mp_sleep_nsDudemanguy2023-10-101-3/+3
| | | | | | | | | | | Linux and macOS already use nanosecond resolution for their sleep functions. It was just being converted from microseconds before. Since we have mp_time_ns now, go ahead and bump the precision here. The timer for windows uses some timeBeginPeriod thing which I'm not sure what it does really but whatever just convert the units to ms like they were doing before. There's really no reason to keep the mp_sleep_us helper around. A multiplication by 1000 is trivial and underlying OS clocks have nanosecond precision.
* af_scaletempo: overlap is a factor not a percentageChristoph Heinrich2023-10-071-4/+4
|
* timer: teach it about nanosecondsKacper Michajłow2023-09-291-1/+1
| | | | | Those changes will alow to change vsync base to more precise time base. In general there is no reason to truncate values returned by system.
* ao_audiotrack: convert to nanosecondsKacper Michajłow2023-09-291-14/+14
|
* audio/chmap: support up to 64 channelsKacper Michajłow2023-09-291-1/+1
| | | | This fixes AAC 22.2 playback
* wasapi: clamp number of output channels to 8Kacper Michajłow2023-09-291-1/+13
| | | | | | This is the most supported in standard layout, if we request more it tends to fallback to stereo instead. Also channels mask is 32-bit and it can get truncated.
* chmap: add more channel layouts up to 22.2Kacper Michajłow2023-09-294-1/+30
|
* audio/chmap: link string buffer size to MP_NUM_CHANNELSKacper Michajłow2023-09-292-3/+6
|
* af_scaletempo2: raise max playback rate to 8.0llyyr2023-09-271-1/+1
| | | | | | 4.0 was too low and copied from Chromium defaults when the filter was initially written, there's no good reason for it to be so low, so double it.
* options: remove a few options marked with .deprecation_messageDudemanguy2023-09-211-3/+0
| | | | | | | | | | | A bit different from the OPT_REPLACED/OPT_REMOVED ones in that the options still possibly do something but they have a deprecation message. Most of these are old and have no real usage. The only potentially controversial ones are the removal of --oaffset and --ovoffset which were deprecated years ago and seemingly have no real replacement. There's a cryptic message about --audio-delay but who knows. The less encoding mode code we have, the better so just chuck it.
* af_scaletempo2: fix missing variable init, remove redundant initferreum2023-09-201-1/+1
|
* af_scaletempo2: truncate final packet to expected lengthferreum2023-09-201-0/+14
| | | | | | | | | | Avoid generating too much audio after EOF. Note: This often has no effect, because less audio is produced than required. Usually this comes to effect with the userspeed filter at high speed (4x) and going back to 1x speed to remove the filter.
* af_scaletempo2: fix processing of final packetferreum2023-09-203-16/+64
| | | | | | | | | | | | After the final input packet, the filter padded with silence to allow one more iteration. That was not enough to process the final frames. Continue padding the end of `input_buffer` with silence until the final frames have been processed. Implementation: Instead of padding when adding final samples, pad before running WSOLA iteration. Count number of added silent frames and remaining input frames for time keeping.
* af_scaletempo2: calculate latency by center of search blockferreum2023-09-202-6/+6
| | | | | | | | | | | | | | | | | | | | | This changes the emitted pts values from the start of the search block to the center of the search block. Change initial `output_time` accordingly. Initial `search_block_index` is irrelevant, because it's overwritten before the first iteration. Using the `output_time` removes the rounding of `search_block_index`, which also fixes the <20 microsecond gaps in timestamps between output packets. Rationale: The variance in audio position was in the range `0..search-interval`. With this change, the range is (- search-interval / 2)..(search-interval / 2)` which ensures lower maximum offset.
* af_scaletempo2: restore exact audio sync on return to 1x speedferreum2023-09-201-1/+9
| | | | | | | | | Target block can be anywhere in the previous search-block, varying by `search-interval` while the filter is active. This resulted in constant audio offset when returning to 1x playback speed. - Move the search block to the target block to sync up exactly. - Drop old frames to minimize input_buffer usage.
* af_scaletempo2: fix speed change latency and pts spikesferreum2023-09-203-42/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The internal time update function involved multiple problems: - Time was updated after WSOLA iteration. The means speed was updated one iteration later than it could be. - The update functions caused spikes of too many or too few samples advanced, leading to audio glitches on speed changes. - The inconsistent updates made it very difficult to produce gapless audio packets. - The `output_time` update function involved complicated feedback: `search_block_index` influenced how many frames from `input_buffer` are retained, which influenced how much `output_time` is changed, which influenced `search_block_index`. With these changes: - Time is updated before WSOLA iterations. Speed changes are effective instantly. - There are no spikes in playback speed during speed changes. - No significant gaps are introduced in output packets. - The time update function becomes (function calls omitted for brevity) output_time += ola_hop_size * playback_rate Functions received a `playback_rate` parameter to check how many samples are needed before iteration. Internal state is only updated when the iteration is actually run, so the speed is allowed to change until enough data is received.
* af_scaletempo2: fix audio artifact on initial WSOLA iterationferreum2023-09-202-7/