mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
Piano+LibDSP: Move Track to LibDSP
This is a tangly commit and it fixes all the bugs that a plain move would have caused (i.e. we need to touch other logic which had wrong assumptions).
This commit is contained in:
parent
125122a9ab
commit
4941cffdd0
29 changed files with 322 additions and 413 deletions
|
@ -15,17 +15,9 @@
|
|||
#include <LibAudio/Sample.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
|
||||
static FixedArray<Audio::Sample> music_samples_to_buffer(Vector<Music::Sample>& music_samples)
|
||||
{
|
||||
FixedArray<Audio::Sample> samples = MUST(FixedArray<Audio::Sample>::try_create(music_samples.size()));
|
||||
for (size_t i = 0; i < music_samples.size(); ++i)
|
||||
samples[i] = { static_cast<float>(music_samples[i].left) / AK::NumericLimits<i16>::max(), static_cast<float>(music_samples[i].right) / AK::NumericLimits<i16>::max() };
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
AudioPlayerLoop::AudioPlayerLoop(TrackManager& track_manager, bool& need_to_write_wav, Audio::WavWriter& wav_writer)
|
||||
: m_track_manager(track_manager)
|
||||
, m_buffer(FixedArray<DSP::Sample>::must_create_but_fixme_should_propagate_errors(sample_count))
|
||||
, m_need_to_write_wav(need_to_write_wav)
|
||||
, m_wav_writer(wav_writer)
|
||||
{
|
||||
|
@ -34,7 +26,7 @@ AudioPlayerLoop::AudioPlayerLoop(TrackManager& track_manager, bool& need_to_writ
|
|||
auto target_sample_rate = m_audio_client->get_sample_rate();
|
||||
if (target_sample_rate == 0)
|
||||
target_sample_rate = Music::sample_rate;
|
||||
m_resampler = Audio::ResampleHelper<Sample>(Music::sample_rate, target_sample_rate);
|
||||
m_resampler = Audio::ResampleHelper<DSP::Sample>(Music::sample_rate, target_sample_rate);
|
||||
|
||||
// FIXME: I said I would never write such a hack again, but here we are.
|
||||
// This code should die as soon as possible anyways, so it doesn't matter.
|
||||
|
@ -44,7 +36,7 @@ AudioPlayerLoop::AudioPlayerLoop(TrackManager& track_manager, bool& need_to_writ
|
|||
|
||||
void AudioPlayerLoop::timer_event(Core::TimerEvent&)
|
||||
{
|
||||
if (m_audio_client->remaining_samples() < buffer_size)
|
||||
if (m_audio_client->remaining_samples() < sample_count)
|
||||
enqueue_audio();
|
||||
}
|
||||
|
||||
|
@ -53,8 +45,7 @@ void AudioPlayerLoop::enqueue_audio()
|
|||
m_track_manager.fill_buffer(m_buffer);
|
||||
// FIXME: Handle OOM better.
|
||||
auto audio_buffer = m_resampler->resample(m_buffer);
|
||||
auto real_buffer = music_samples_to_buffer(audio_buffer);
|
||||
(void)m_audio_client->async_enqueue(real_buffer);
|
||||
(void)m_audio_client->async_enqueue(audio_buffer);
|
||||
|
||||
// FIXME: This should be done somewhere else.
|
||||
if (m_need_to_write_wav) {
|
||||
|
@ -63,7 +54,7 @@ void AudioPlayerLoop::enqueue_audio()
|
|||
m_track_manager.set_should_loop(false);
|
||||
do {
|
||||
m_track_manager.fill_buffer(m_buffer);
|
||||
m_wav_writer.write_samples(reinterpret_cast<u8*>(m_buffer.data()), buffer_size);
|
||||
m_wav_writer.write_samples(m_buffer.span());
|
||||
} while (m_track_manager.transport()->time());
|
||||
m_track_manager.reset();
|
||||
m_track_manager.set_should_loop(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue