mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 23:04:59 +00:00

This commit un-deprecates DeprecatedString, and repurposes it as a byte string. As the null state has already been removed, there are no other particularly hairy blockers in repurposing this type as a byte string (what it _really_ is). This commit is auto-generated: $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \ Meta Ports Ladybird Tests Kernel) $ perl -pie 's/\bDeprecatedString\b/ByteString/g; s/deprecated_string/byte_string/g' $xs $ clang-format --style=file -i \ $(git diff --name-only | grep \.cpp\|\.h) $ gn format $(git ls-files '*.gn' '*.gni')
53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2020, William McPherson <willmcpherson2@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteString.h>
|
|
#include <AK/Noncopyable.h>
|
|
#include <AK/RefPtr.h>
|
|
#include <AK/StringView.h>
|
|
#include <LibAudio/Encoder.h>
|
|
#include <LibAudio/Sample.h>
|
|
#include <LibAudio/SampleFormats.h>
|
|
#include <LibCore/File.h>
|
|
#include <LibCore/Forward.h>
|
|
|
|
namespace Audio {
|
|
|
|
class WavWriter : public Encoder {
|
|
AK_MAKE_NONCOPYABLE(WavWriter);
|
|
AK_MAKE_NONMOVABLE(WavWriter);
|
|
|
|
public:
|
|
static ErrorOr<NonnullOwnPtr<WavWriter>> create_from_file(StringView path, int sample_rate = 44100, u16 num_channels = 2, PcmSampleFormat sample_format = PcmSampleFormat::Int16);
|
|
WavWriter(int sample_rate = 44100, u16 num_channels = 2, PcmSampleFormat sample_format = PcmSampleFormat::Int16);
|
|
~WavWriter();
|
|
|
|
virtual ErrorOr<void> write_samples(ReadonlySpan<Sample> samples) override;
|
|
virtual ErrorOr<void> finalize() override;
|
|
|
|
u32 sample_rate() const { return m_sample_rate; }
|
|
u16 num_channels() const { return m_num_channels; }
|
|
PcmSampleFormat sample_format() const { return m_sample_format; }
|
|
|
|
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_sample_format(PcmSampleFormat sample_format) { m_sample_format = sample_format; }
|
|
|
|
private:
|
|
ErrorOr<void> write_header();
|
|
OwnPtr<Core::OutputBufferedFile> m_file;
|
|
bool m_finalized { false };
|
|
|
|
u32 m_sample_rate;
|
|
u16 m_num_channels;
|
|
PcmSampleFormat m_sample_format;
|
|
u32 m_data_sz { 0 };
|
|
};
|
|
|
|
}
|