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

LibAudio: Split Buffer.{h, cpp} into three files

The Buffer files had contained both the ResampleHelper and the
sample format utilities. Because the Buffer class (and its file) is
going to be deleted soon, this commit separates those two things into
their own files.
This commit is contained in:
kleines Filmröllchen 2022-01-23 15:21:56 +01:00 committed by Andreas Kling
parent 262488ea33
commit 5d01db3493
7 changed files with 169 additions and 149 deletions

View file

@ -17,58 +17,15 @@
#include <AK/Types.h>
#include <AK/Vector.h>
#include <AK/kmalloc.h>
#include <LibAudio/Resampler.h>
#include <LibAudio/Sample.h>
#include <LibAudio/SampleFormats.h>
#include <LibCore/AnonymousBuffer.h>
#include <string.h>
namespace Audio {
using namespace AK::Exponentials;
// Supported PCM sample formats.
enum PcmSampleFormat : u8 {
Uint8,
Int16,
Int24,
Int32,
Float32,
Float64,
};
// Most of the read code only cares about how many bits to read or write
u16 pcm_bits_per_sample(PcmSampleFormat format);
String sample_format_name(PcmSampleFormat format);
// Small helper to resample from one playback rate to another
// This isn't really "smart", in that we just insert (or drop) samples.
// Should do better...
template<typename SampleType>
class ResampleHelper {
public:
ResampleHelper(u32 source, u32 target);
// To be used as follows:
// while the resampler doesn't need a new sample, read_sample(current) and store the resulting samples.
// as long as the resampler needs a new sample, process_sample(current)
// Stores a new sample
void process_sample(SampleType sample_l, SampleType sample_r);
// Assigns the given sample to its correct value and returns false if there is a new sample required
bool read_sample(SampleType& next_l, SampleType& next_r);
Vector<SampleType> resample(Vector<SampleType> to_resample);
void reset();
u32 source() const { return m_source; }
u32 target() const { return m_target; }
private:
const u32 m_source;
const u32 m_target;
u32 m_current_ratio { 0 };
SampleType m_last_sample_l;
SampleType m_last_sample_r;
};
// A buffer of audio samples.
class Buffer : public RefCounted<Buffer> {
public: