mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:07:34 +00:00
LibAudio: Support 32 and 64-bit float WAV files
LibAudio's WavLoader plugin for loading WAV files now supports loading audio files with 32-bit float or 64-bit float samples. By supporting these new non-int sample formats, Audio::Buffer now stores the sample format (out of a list of supported formats) instead of the raw bit depth. (The bit depth is easily calculated with pcm_bits_per_sample)
This commit is contained in:
parent
91c210c39a
commit
563cc17a50
5 changed files with 127 additions and 35 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,6 +9,7 @@
|
|||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/AnonymousBuffer.h>
|
||||
|
@ -69,6 +71,19 @@ struct Frame {
|
|||
double right;
|
||||
};
|
||||
|
||||
// Supported PCM sample formats.
|
||||
enum PcmSampleFormat : u8 {
|
||||
Uint8,
|
||||
Int16,
|
||||
Int24,
|
||||
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...
|
||||
|
@ -89,8 +104,8 @@ private:
|
|||
// A buffer of audio samples, normalized to 44100hz.
|
||||
class Buffer : public RefCounted<Buffer> {
|
||||
public:
|
||||
static RefPtr<Buffer> from_pcm_data(ReadonlyBytes data, ResampleHelper& resampler, int num_channels, int bits_per_sample);
|
||||
static RefPtr<Buffer> from_pcm_stream(InputMemoryStream& stream, ResampleHelper& resampler, int num_channels, int bits_per_sample, int num_samples);
|
||||
static RefPtr<Buffer> from_pcm_data(ReadonlyBytes data, ResampleHelper& resampler, int num_channels, PcmSampleFormat sample_format);
|
||||
static RefPtr<Buffer> from_pcm_stream(InputMemoryStream& stream, ResampleHelper& resampler, int num_channels, PcmSampleFormat sample_format, int num_samples);
|
||||
static NonnullRefPtr<Buffer> create_with_samples(Vector<Frame>&& samples)
|
||||
{
|
||||
return adopt_ref(*new Buffer(move(samples)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue