ladybird/Libraries/LibMedia/Audio/TimeStretcher.h
Zaggy1024 28f670f09f LibMedia: Implement audio time stretching with WSOLA
The algorithm is ported over from Chromium's, which produces very good
results for speech, while being not objectionable for music, especially
in the background.

Other algorithms were tested.

Phase vocoders:
- Bungee
- Signalsmith Stretch
- pvdoneright
All three of these exhibited the usual phase shifting artifacts,
causing speech to sound slightly shifted into the high end. Speech is
the main thing we want to optimize for, so these aren't ideal.

Sonic (TD-PSOLA) performs better than WSOLA for speech, especially at
rates higher than 2x, but makes background sounds/music garbled and
unpleasant. It is still worth considering for speech clarity, and could
be added as an optional feature.
2026-06-06 19:58:17 -05:00

31 lines
722 B
C++

/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/Time.h>
#include <LibMedia/AudioBlock.h>
#include <LibMedia/DecoderError.h>
namespace Audio {
class TimeStretcher {
public:
virtual ~TimeStretcher() = default;
virtual i64 preroll_frame_count() const = 0;
virtual void flush(AK::Duration media_start_timestamp, i64 output_start_frame_index) = 0;
virtual void set_rate(float) = 0;
virtual void push_block(Media::AudioBlock const&) = 0;
virtual Media::DecoderErrorOr<Media::AudioBlock> retrieve_block() = 0;
virtual void signal_end_of_stream() = 0;
};
}