summaryrefslogtreecommitdiffstats
path: root/audio/filter/af_scaletempo2_internals.c
Commit message (Collapse)AuthorAgeFilesLines
* af_scaletempo2: fix false reporting of frame availabilitynanahi2024-03-281-1/+2
| | | | | | | | | | | | | | | With certain speed settings, the following can happen at the start of the playback: - can_perform_wsola returns false, so no frames are written - mp_scaletempo2_frames_available returns true when p->input_buffer_final_frames is 0 and target_block_index < 0 This results in infinite loop and completely stalls audio filter processing and playback. Fix this by only checking this condition after the final frame is set. Fixes: 8080d00d7f31a0e1ba25418e0f08474f1a2f1f61
* af_scaletempo2: fix missing variable init, remove redundant initferreum2023-09-201-1/+1
|
* af_scaletempo2: fix processing of final packetferreum2023-09-201-9/+49
| | | | | | | | | | | | 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-201-5/+4
| | | | | | | | | | | | | | | | | | | | | 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-201-27/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-201-7/+17
| | | | | | | | | The first WSOLA iteration overlapped audio with whatever was in the `wsola_output` buffer. This was either silence (if not run before), or old frames (if switching to 1x and back to a different speed). Track the state of the output buffer and memcpy the whole window for the first iteration instead.
* af_scaletempo2: fix audio offset when playing back at 1x speedferreum2023-09-201-9/+13
| | | | | `read_input_buffer` needs to respect the `target_block_index`, otherwise the audio resumes at the wrong position.
* af_scaletempo2: fix inconsistent search block position after initferreum2023-09-201-2/+3
| | | | | | | | | `output_time` is used to set the center of the search block. Init of both `search_block_index` and `output_time` with 0 caused inconsistent search block movement for the first iterations. Initialize with `search_block_center_offset` for consistency with initial `search_block_index`.
* af_scaletempo2: move latency calculation to internal functionferreum2023-09-201-0/+6
|
* af_scaletempo2: fix missing dereference when processing final packetferreum2023-09-201-1/+1
| | | | | Missing dereference was not noticed because assigning 0 to pointer is allowed.
* af_scaletempo2: fix crash when the number of channels increasesPeter DeLong2022-09-231-5/+4
| | | | | | | | | | | | | | | | When af_scaletempo2.c:process() detects a format change, it goes back through mp_scaletempo2_init() to reinitialize everything. However, mp_scaletempo2.input_buffer is not necessarily reallocated due to a check in af_scaletempo2_internals.c:resize_input_buffer(). This is a problem if the number of audio channels increases, since without reallocating, the buffer for the new channel(s) will at best point to NULL, and at worst uninitialized memory. Since resize_input_buffer() is only called from two places, pull size check out into mp_scaletempo2_fill_input_buffer(). This allows each caller to decide whether they want to resize or not. We could be smarter about when to reallocate, but that would add a lot of machinery for a case I don't expect to be hit often in practice.
* various: remove trailing whitespaceGuido Cella2022-05-141-2/+2
|
* af_scaletempo2: use gcc vectors to speed up inner loopNiklas Haas2021-05-261-3/+72
| | | | | | | | | | This brings my scaletempo2 benchmark down from ~22s to ~7s on my machine (-march=native), and down to ~11s with a generic compile. Guarded behind an appropriate #ifdef to avoid being ableist against people who have the clinical need to run obscure platforms. Closes #8848
* af_scaletempo2: fix crash for speed >= 16Dorian Rudolph2021-02-151-9/+13
| | | | | | | The input buffer size was fixed, but the required size depends on the speed. Now the buffer will be resized dynamically. Fixes #8081
* af_scaletempo2: M_PI is always definedwm42020-07-271-4/+0
| | | | I forgot why/how (C99?), but other code also uses it.
* audio: add scaletempo2 filter based on chromiumDorian Rudolph2020-07-271-0/+728
scaletempo2 is a new audio filter for playing back audio at modified speed and is based on chromium commit 51ed77e3f37a9a9b80d6d0a8259e84a8ca635259. It sounds subjectively better than the existing implementions scaletempo and rubberband.