1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:17:45 +00:00

Piano+LibAudio: Port to Core::File

This commit is contained in:
Cameron Youell 2023-03-27 00:37:17 +00:00 committed by Andrew Kaster
parent fb8d4b7032
commit 7734eba03f
5 changed files with 61 additions and 59 deletions

View file

@ -11,7 +11,7 @@
#include <AK/RefPtr.h>
#include <AK/StringView.h>
#include <LibAudio/Sample.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/File.h>
#include <LibCore/Forward.h>
namespace Audio {
@ -21,32 +21,26 @@ class WavWriter {
AK_MAKE_NONMOVABLE(WavWriter);
public:
WavWriter(StringView path, int sample_rate = 44100, u16 num_channels = 2, u16 bits_per_sample = 16);
static ErrorOr<NonnullOwnPtr<WavWriter>> create_from_file(StringView path, int sample_rate = 44100, u16 num_channels = 2, u16 bits_per_sample = 16);
WavWriter(int sample_rate = 44100, u16 num_channels = 2, u16 bits_per_sample = 16);
~WavWriter();
bool has_error() const { return !m_error_string.is_null(); }
char const* error_string() const { return m_error_string.characters(); }
void write_samples(Span<Sample> samples);
ErrorOr<void> write_samples(Span<Sample> samples);
void finalize(); // You can finalize manually or let the destructor do it.
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; }
RefPtr<Core::DeprecatedFile> file() const { return m_file; }
Core::File& file() const { return *m_file; }
void set_file(StringView path);
ErrorOr<void> set_file(StringView path);
void set_num_channels(int num_channels) { m_num_channels = num_channels; }
void set_sample_rate(int sample_rate) { m_sample_rate = sample_rate; }
void set_bits_per_sample(int bits_per_sample) { m_bits_per_sample = bits_per_sample; }
void clear_error() { m_error_string = DeprecatedString(); }
private:
void write_header();
RefPtr<Core::DeprecatedFile> m_file;
DeprecatedString m_error_string;
ErrorOr<void> write_header();
OwnPtr<Core::File> m_file;
bool m_finalized { false };
u32 m_sample_rate;