summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorJulian Offenhäuser <metalvoidzz@gmail.com>2020-12-01 20:20:46 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-02 16:31:30 +0100
commitbad8cd3d8f1d9a25e3cd9a9b9b4a68cc5aaa1193 (patch)
tree0d5d7f13386e64bbb73d9b683e8abfb81edc58a1 /Applications
parent1f47b01e3bf4188df83eff416064124649894757 (diff)
downloadserenity-bad8cd3d8f1d9a25e3cd9a9b9b4a68cc5aaa1193.zip
Applications+Userland: Switch to new Audio::Loader API
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Piano/Track.cpp24
-rw-r--r--Applications/SoundPlayer/PlaybackManager.cpp4
-rw-r--r--Applications/SoundPlayer/PlaybackManager.h7
-rw-r--r--Applications/SoundPlayer/SoundPlayerWidget.cpp9
4 files changed, 20 insertions, 24 deletions
diff --git a/Applications/Piano/Track.cpp b/Applications/Piano/Track.cpp
index 754a43407a..8bbdf5474f 100644
--- a/Applications/Piano/Track.cpp
+++ b/Applications/Piano/Track.cpp
@@ -27,7 +27,7 @@
#include "Track.h"
#include <AK/NumericLimits.h>
-#include <LibAudio/WavLoader.h>
+#include <LibAudio/Loader.h>
#include <math.h>
Track::Track(const u32& time)
@@ -138,19 +138,19 @@ void Track::reset()
String Track::set_recorded_sample(const StringView& path)
{
- Audio::WavLoader wav_loader(path);
- if (wav_loader.has_error())
- return String(wav_loader.error_string());
- auto wav_buffer = wav_loader.get_more_samples(60 * sample_rate * sizeof(Sample)); // 1 minute maximum
+ NonnullRefPtr<Audio::Loader> loader = Audio::Loader::create(path);
+ if (loader->has_error())
+ return String(loader->error_string());
+ auto buffer = loader->get_more_samples(60 * sample_rate * sizeof(Sample)); // 1 minute maximum
if (!m_recorded_sample.is_empty())
m_recorded_sample.clear();
- m_recorded_sample.resize(wav_buffer->sample_count());
+ m_recorded_sample.resize(buffer->sample_count());
double peak = 0;
- for (int i = 0; i < wav_buffer->sample_count(); ++i) {
- double left_abs = fabs(wav_buffer->samples()[i].left);
- double right_abs = fabs(wav_buffer->samples()[i].right);
+ for (int i = 0; i < buffer->sample_count(); ++i) {
+ double left_abs = fabs(buffer->samples()[i].left);
+ double right_abs = fabs(buffer->samples()[i].right);
if (left_abs > peak)
peak = left_abs;
if (right_abs > peak)
@@ -158,9 +158,9 @@ String Track::set_recorded_sample(const StringView& path)
}
if (peak) {
- for (int i = 0; i < wav_buffer->sample_count(); ++i) {
- m_recorded_sample[i].left = wav_buffer->samples()[i].left / peak;
- m_recorded_sample[i].right = wav_buffer->samples()[i].right / peak;
+ for (int i = 0; i < buffer->sample_count(); ++i) {
+ m_recorded_sample[i].left = buffer->samples()[i].left / peak;
+ m_recorded_sample[i].right = buffer->samples()[i].right / peak;
}
}
diff --git a/Applications/SoundPlayer/PlaybackManager.cpp b/Applications/SoundPlayer/PlaybackManager.cpp
index ce616ff71c..1421e75215 100644
--- a/Applications/SoundPlayer/PlaybackManager.cpp
+++ b/Applications/SoundPlayer/PlaybackManager.cpp
@@ -41,10 +41,10 @@ PlaybackManager::~PlaybackManager()
{
}
-void PlaybackManager::set_loader(OwnPtr<Audio::WavLoader>&& loader)
+void PlaybackManager::set_loader(NonnullRefPtr<Audio::Loader>&& loader)
{
stop();
- m_loader = move(loader);
+ m_loader = loader;
if (m_loader) {
m_total_length = m_loader->total_samples() / static_cast<float>(m_loader->sample_rate());
m_timer->start();
diff --git a/Applications/SoundPlayer/PlaybackManager.h b/Applications/SoundPlayer/PlaybackManager.h
index da6adf8cd3..35be78fe9d 100644
--- a/Applications/SoundPlayer/PlaybackManager.h
+++ b/Applications/SoundPlayer/PlaybackManager.h
@@ -27,8 +27,9 @@
#pragma once
#include <AK/Vector.h>
+#include <LibAudio/Buffer.h>
#include <LibAudio/ClientConnection.h>
-#include <LibAudio/WavLoader.h>
+#include <LibAudio/Loader.h>
#include <LibCore/Timer.h>
#define PLAYBACK_MANAGER_BUFFER_SIZE 64 * KiB
@@ -45,7 +46,7 @@ public:
void seek(const int position);
void loop(bool);
bool toggle_pause();
- void set_loader(OwnPtr<Audio::WavLoader>&&);
+ void set_loader(NonnullRefPtr<Audio::Loader>&&);
int last_seek() const { return m_last_seek; }
bool is_paused() const { return m_paused; }
@@ -67,7 +68,7 @@ private:
size_t m_next_ptr { 0 };
size_t m_last_seek { 0 };
float m_total_length { 0 };
- OwnPtr<Audio::WavLoader> m_loader { nullptr };
+ RefPtr<Audio::Loader> m_loader { nullptr };
NonnullRefPtr<Audio::ClientConnection> m_connection;
RefPtr<Audio::Buffer> m_next_buffer;
RefPtr<Audio::Buffer> m_current_buffer;
diff --git a/Applications/SoundPlayer/SoundPlayerWidget.cpp b/Applications/SoundPlayer/SoundPlayerWidget.cpp
index 0402e38817..1f44f97d1c 100644
--- a/Applications/SoundPlayer/SoundPlayerWidget.cpp
+++ b/Applications/SoundPlayer/SoundPlayerWidget.cpp
@@ -119,15 +119,10 @@ void SoundPlayerWidget::hide_scope(bool hide)
void SoundPlayerWidget::open_file(String path)
{
- if (!path.ends_with(".wav")) {
- GUI::MessageBox::show(window(), "Selected file is not a \".wav\" file!", "Filetype error", GUI::MessageBox::Type::Error);
- return;
- }
-
- OwnPtr<Audio::WavLoader> loader = make<Audio::WavLoader>(path);
+ NonnullRefPtr<Audio::Loader> loader = Audio::Loader::create(path);
if (loader->has_error()) {
GUI::MessageBox::show(window(),
- String::formatted("Failed to load WAV file: {} ({})", path, loader->error_string()),
+ String::formatted("Failed to load audio file: {} ({})", path, loader->error_string()),
"Filetype error", GUI::MessageBox::Type::Error);
return;
}