LibAudio: Rename AudioLoader -> AudioStream
This commit is contained in:
@@ -25,7 +25,7 @@ namespace LibAudio
|
||||
|
||||
BAN::ErrorOr<Audio> Audio::load(BAN::StringView path)
|
||||
{
|
||||
Audio result(TRY(AudioLoader::load(path)));
|
||||
Audio result(TRY(AudioStream::load(path)));
|
||||
TRY(result.initialize(256 * 1024));
|
||||
return result;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace LibAudio
|
||||
close(m_server_fd);
|
||||
m_server_fd = -1;
|
||||
|
||||
m_audio_loader.clear();
|
||||
m_audio_stream.clear();
|
||||
}
|
||||
|
||||
Audio& Audio::operator=(Audio&& other)
|
||||
@@ -67,7 +67,7 @@ namespace LibAudio
|
||||
m_server_fd = other.m_server_fd;
|
||||
m_shmid = other.m_shmid;
|
||||
m_audio_buffer = other.m_audio_buffer;
|
||||
m_audio_loader = BAN::move(other.m_audio_loader);
|
||||
m_audio_stream = BAN::move(other.m_audio_stream);
|
||||
|
||||
other.m_server_fd = -1;
|
||||
other.m_shmid = -1;
|
||||
@@ -93,10 +93,10 @@ namespace LibAudio
|
||||
memset(m_audio_buffer->samples, 0, total_samples * sizeof(AudioBuffer::sample_t));
|
||||
|
||||
m_audio_buffer->capacity = total_samples;
|
||||
if (m_audio_loader)
|
||||
if (m_audio_stream)
|
||||
{
|
||||
m_audio_buffer->channels = m_audio_loader->channels();
|
||||
m_audio_buffer->sample_rate = m_audio_loader->sample_rate();
|
||||
m_audio_buffer->channels = m_audio_stream->channels();
|
||||
m_audio_buffer->sample_rate = m_audio_stream->sample_rate();
|
||||
}
|
||||
|
||||
update();
|
||||
@@ -170,15 +170,15 @@ namespace LibAudio
|
||||
|
||||
void Audio::update()
|
||||
{
|
||||
if (!m_audio_loader)
|
||||
if (!m_audio_stream)
|
||||
return;
|
||||
|
||||
if (!m_audio_loader->samples_remaining() && !is_playing())
|
||||
if (!m_audio_stream->samples_remaining() && !is_playing())
|
||||
return set_paused(true);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const uint32_t sample_count = BAN::Math::min<uint32_t>(queueable_samples(), m_audio_loader->samples_remaining());
|
||||
const uint32_t sample_count = BAN::Math::min<uint32_t>(queueable_samples(), m_audio_stream->samples_remaining());
|
||||
if (sample_count == 0)
|
||||
break;
|
||||
|
||||
@@ -186,7 +186,7 @@ namespace LibAudio
|
||||
const uint32_t capacity = m_audio_buffer->capacity;
|
||||
|
||||
for (size_t i = 0; i < sample_count; i++)
|
||||
m_audio_buffer->samples[(head + i) % capacity] = m_audio_loader->get_sample();
|
||||
m_audio_buffer->samples[(head + i) % capacity] = m_audio_stream->get_sample();
|
||||
m_audio_buffer->head = (head + sample_count) % capacity;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
#include <LibAudio/AudioLoader.h>
|
||||
#include <LibAudio/AudioLoaders/WAVLoader.h>
|
||||
#include <LibAudio/AudioStream.h>
|
||||
#include <LibAudio/AudioStreams/WAVAudioStream.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace LibAudio
|
||||
{
|
||||
|
||||
BAN::ErrorOr<BAN::UniqPtr<AudioLoader>> AudioLoader::load(BAN::StringView path)
|
||||
BAN::ErrorOr<BAN::UniqPtr<AudioStream>> AudioStream::load(BAN::StringView path)
|
||||
{
|
||||
if (path.empty())
|
||||
return BAN::Error::from_errno(ENOENT);
|
||||
@@ -37,11 +37,11 @@ namespace LibAudio
|
||||
if (mmap_addr == MAP_FAILED)
|
||||
return BAN::Error::from_errno(errno);
|
||||
|
||||
BAN::ErrorOr<BAN::UniqPtr<AudioLoader>> result_or_error { BAN::Error::from_errno(ENOTSUP) };
|
||||
BAN::ErrorOr<BAN::UniqPtr<AudioStream>> result_or_error { BAN::Error::from_errno(ENOTSUP) };
|
||||
|
||||
auto file_span = BAN::ConstByteSpan(mmap_addr, st.st_size);
|
||||
if (WAVAudioLoader::can_load_from(file_span))
|
||||
result_or_error = WAVAudioLoader::create(file_span);
|
||||
if (WAVAudioStream::can_load_from(file_span))
|
||||
result_or_error = WAVAudioStream::create(file_span);
|
||||
|
||||
if (result_or_error.is_error())
|
||||
{
|
||||
@@ -55,7 +55,7 @@ namespace LibAudio
|
||||
return result;
|
||||
}
|
||||
|
||||
AudioLoader::~AudioLoader()
|
||||
AudioStream::~AudioStream()
|
||||
{
|
||||
if (m_mmap_addr)
|
||||
munmap(m_mmap_addr, m_mmap_size);
|
||||
+13
-13
@@ -1,4 +1,4 @@
|
||||
#include <LibAudio/AudioLoaders/WAVLoader.h>
|
||||
#include <LibAudio/AudioStreams/WAVAudioStream.h>
|
||||
|
||||
namespace LibAudio
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace LibAudio
|
||||
uint16_t wBitsPerSample;
|
||||
};
|
||||
|
||||
bool WAVAudioLoader::can_load_from(BAN::ConstByteSpan data)
|
||||
bool WAVAudioStream::can_load_from(BAN::ConstByteSpan data)
|
||||
{
|
||||
if (data.size() < sizeof(RIFFChunk))
|
||||
return false;
|
||||
@@ -37,7 +37,7 @@ namespace LibAudio
|
||||
return true;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::UniqPtr<AudioLoader>> WAVAudioLoader::create(BAN::ConstByteSpan data)
|
||||
BAN::ErrorOr<BAN::UniqPtr<AudioStream>> WAVAudioStream::create(BAN::ConstByteSpan data)
|
||||
{
|
||||
ASSERT(can_load_from(data));
|
||||
|
||||
@@ -93,15 +93,15 @@ namespace LibAudio
|
||||
if (bps / 8 * channels != format_chunk->nBlockAlign)
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
|
||||
auto loader = TRY(BAN::UniqPtr<WAVAudioLoader>::create());
|
||||
loader->m_bits_per_sample = bps;
|
||||
loader->m_sample_format = format;
|
||||
loader->m_channels = channels;
|
||||
loader->m_sample_rate = format_chunk->nSamplePerSec;
|
||||
loader->m_sample_data = sample_data;
|
||||
loader->m_total_samples = sample_data.size() / (bps / 8);
|
||||
loader->m_current_sample = 0;
|
||||
return BAN::UniqPtr<AudioLoader>(BAN::move(loader));
|
||||
auto stream = TRY(BAN::UniqPtr<WAVAudioStream>::create());
|
||||
stream->m_bits_per_sample = bps;
|
||||
stream->m_sample_format = format;
|
||||
stream->m_channels = channels;
|
||||
stream->m_sample_rate = format_chunk->nSamplePerSec;
|
||||
stream->m_sample_data = sample_data;
|
||||
stream->m_total_samples = sample_data.size() / (bps / 8);
|
||||
stream->m_current_sample = 0;
|
||||
return BAN::UniqPtr<AudioStream>(BAN::move(stream));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -115,7 +115,7 @@ namespace LibAudio
|
||||
return data.as<const T>() / (BAN::numeric_limits<T>::max() / 2.0f) - 1.0f;
|
||||
}
|
||||
|
||||
float WAVAudioLoader::get_sample()
|
||||
float WAVAudioStream::get_sample()
|
||||
{
|
||||
ASSERT(samples_remaining() > 0);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(LIBAUDIO_SOURCES
|
||||
Audio.cpp
|
||||
AudioLoader.cpp
|
||||
AudioLoaders/WAVLoader.cpp
|
||||
AudioStream.cpp
|
||||
AudioStreams/WAVAudioStream.cpp
|
||||
)
|
||||
|
||||
add_library(libaudio ${LIBAUDIO_SOURCES})
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <BAN/StringView.h>
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <LibAudio/AudioLoader.h>
|
||||
#include <LibAudio/AudioStream.h>
|
||||
|
||||
namespace LibAudio
|
||||
{
|
||||
@@ -49,8 +49,8 @@ namespace LibAudio
|
||||
|
||||
private:
|
||||
Audio() = default;
|
||||
Audio(BAN::UniqPtr<AudioLoader>&& audio_loader)
|
||||
: m_audio_loader(BAN::move(audio_loader))
|
||||
Audio(BAN::UniqPtr<AudioStream>&& audio_stream)
|
||||
: m_audio_stream(BAN::move(audio_stream))
|
||||
{ }
|
||||
|
||||
void clear();
|
||||
@@ -60,7 +60,7 @@ namespace LibAudio
|
||||
private:
|
||||
int m_server_fd { -1 };
|
||||
|
||||
BAN::UniqPtr<AudioLoader> m_audio_loader;
|
||||
BAN::UniqPtr<AudioStream> m_audio_stream;
|
||||
|
||||
int m_shmid { -1 };
|
||||
AudioBuffer* m_audio_buffer { nullptr };
|
||||
|
||||
+6
-6
@@ -6,14 +6,14 @@
|
||||
namespace LibAudio
|
||||
{
|
||||
|
||||
class AudioLoader
|
||||
class AudioStream
|
||||
{
|
||||
BAN_NON_COPYABLE(AudioLoader);
|
||||
BAN_NON_MOVABLE(AudioLoader);
|
||||
BAN_NON_COPYABLE(AudioStream);
|
||||
BAN_NON_MOVABLE(AudioStream);
|
||||
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::UniqPtr<AudioLoader>> load(BAN::StringView path);
|
||||
virtual ~AudioLoader();
|
||||
static BAN::ErrorOr<BAN::UniqPtr<AudioStream>> load(BAN::StringView path);
|
||||
virtual ~AudioStream();
|
||||
|
||||
virtual uint32_t channels() const = 0;
|
||||
virtual uint32_t sample_rate() const = 0;
|
||||
@@ -22,7 +22,7 @@ namespace LibAudio
|
||||
virtual float get_sample() = 0;
|
||||
|
||||
protected:
|
||||
AudioLoader() = default;
|
||||
AudioStream() = default;
|
||||
|
||||
private:
|
||||
void* m_mmap_addr { nullptr };
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <LibAudio/AudioLoader.h>
|
||||
#include <LibAudio/AudioStream.h>
|
||||
|
||||
#include <BAN/ByteSpan.h>
|
||||
|
||||
namespace LibAudio
|
||||
{
|
||||
|
||||
class WAVAudioLoader : public AudioLoader
|
||||
class WAVAudioStream : public AudioStream
|
||||
{
|
||||
public:
|
||||
enum FormatCode : uint16_t
|
||||
@@ -18,7 +18,7 @@ namespace LibAudio
|
||||
|
||||
public:
|
||||
static bool can_load_from(BAN::ConstByteSpan data);
|
||||
static BAN::ErrorOr<BAN::UniqPtr<AudioLoader>> create(BAN::ConstByteSpan data);
|
||||
static BAN::ErrorOr<BAN::UniqPtr<AudioStream>> create(BAN::ConstByteSpan data);
|
||||
|
||||
uint32_t channels() const override { return m_channels; }
|
||||
uint32_t sample_rate() const override { return m_sample_rate; }
|
||||
Reference in New Issue
Block a user