mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-01 15:43:36 +03:00
d049626f40
All audio applications (aplay, Piano, Sound Player) respect the ability of the system to have theoretically any sample rate. Therefore, they resample their own audio into the system sample rate. LibAudio previously had its loaders resample their own audio, even though they expose their sample rate. This is now changed. The loaders output audio data in their file's sample rate, which the user has to query and resample appropriately. Resampling code from Buffer, WavLoader and FlacLoader is removed. Note that these applications only check the sample rate at startup, which is reasonable (the user has to restart applications when changing the sample rate). Fully dynamic adaptation could both lead to errors and will require another IPC interface. This seems to be enough for now.
41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
|
|
* Copyright (c) 2021, JJ Roberts-White <computerfido@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "Music.h"
|
|
#include <LibAudio/Buffer.h>
|
|
#include <LibAudio/ClientConnection.h>
|
|
#include <LibAudio/WavWriter.h>
|
|
#include <LibCore/Object.h>
|
|
|
|
class TrackManager;
|
|
|
|
// Wrapper class accepting custom events to advance the track playing and forward audio data to the system.
|
|
// This does not run on a separate thread, preventing IPC multithreading madness.
|
|
class AudioPlayerLoop : public Core::Object {
|
|
C_OBJECT(AudioPlayerLoop)
|
|
public:
|
|
AudioPlayerLoop(TrackManager& track_manager, bool& need_to_write_wav, Audio::WavWriter& wav_writer);
|
|
|
|
void enqueue_audio();
|
|
|
|
void toggle_paused();
|
|
bool is_playing() { return m_should_play_audio; }
|
|
|
|
private:
|
|
TrackManager& m_track_manager;
|
|
Array<Sample, sample_count> m_buffer;
|
|
Optional<Audio::ResampleHelper<double>> m_resampler;
|
|
RefPtr<Audio::ClientConnection> m_audio_client;
|
|
|
|
bool m_should_play_audio = true;
|
|
|
|
bool& m_need_to_write_wav;
|
|
Audio::WavWriter& m_wav_writer;
|
|
};
|