1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:38:12 +00:00
serenity/Libraries/LibAudio/AWavLoader.h
Andreas Kling ae4a9e017a LibAudio+aplay: Make the aplay output look a little funner.
Show some information about the file we're playing, and display how many
samples we've played out of how many total.

This might be a bit buggy as I haven't tested it with many different files,
but it's a start. :^)
2019-07-28 21:52:30 +02:00

40 lines
1,004 B
C++

#pragma once
#include <AK/AKString.h>
#include <AK/RefPtr.h>
#include <AK/StringView.h>
#include <LibCore/CFile.h>
class ABuffer;
namespace AK {
class ByteBuffer;
}
// Parses a WAV file and produces an ABuffer instance from it
class AWavLoader {
public:
explicit AWavLoader(const StringView& path);
RefPtr<ABuffer> load_wav(const StringView& path);
const char* error_string() { return m_error_string.characters(); }
RefPtr<ABuffer> get_more_samples();
int loaded_samples() const { return m_loaded_samples; }
int total_samples() const { return m_total_samples; }
u32 sample_rate() const { return m_sample_rate; }
u16 num_channels() const { return m_num_channels; }
u16 bits_per_sample() const { return m_bits_per_sample; }
private:
bool parse_header();
CFile m_file;
String m_error_string;
u32 m_sample_rate { 0 };
u16 m_num_channels { 0 };
u16 m_bits_per_sample { 0 };
int m_loaded_samples { 0 };
int m_total_samples { 0 };
};