Rename audio::sample -> audio::track
This commit is contained in:
parent
1ab980f0d2
commit
58a793af9d
3 changed files with 22 additions and 22 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <psemek/audio/effect.hpp>
|
#include <psemek/audio/effect.hpp>
|
||||||
#include <psemek/audio/stream.hpp>
|
#include <psemek/audio/stream.hpp>
|
||||||
#include <psemek/audio/sample.hpp>
|
#include <psemek/audio/track.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
@ -18,10 +18,10 @@ namespace psemek::audio
|
||||||
engine();
|
engine();
|
||||||
~engine();
|
~engine();
|
||||||
|
|
||||||
std::shared_ptr<sample> load_raw(std::int16_t const * data, std::size_t sample_count, bool copy = true);
|
std::shared_ptr<track> load_raw(std::int16_t const * data, std::size_t sample_count, bool copy = true);
|
||||||
std::shared_ptr<sample> load_wav(char const * data, std::size_t size);
|
std::shared_ptr<track> load(char const * data, std::size_t size);
|
||||||
|
|
||||||
std::shared_ptr<stream> play(std::shared_ptr<sample> s, bool start = true, bool loop = false);
|
std::shared_ptr<stream> play(std::shared_ptr<track> s, bool start = true, bool loop = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct impl;
|
struct impl;
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
namespace psemek::audio
|
namespace psemek::audio
|
||||||
{
|
{
|
||||||
|
|
||||||
struct sample
|
struct track
|
||||||
{
|
{
|
||||||
virtual std::int16_t const * data() const = 0;
|
virtual std::int16_t const * data() const = 0;
|
||||||
virtual std::size_t size() const = 0;
|
virtual std::size_t size() const = 0;
|
||||||
|
|
||||||
virtual ~sample(){}
|
virtual ~track(){}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -35,12 +35,12 @@ namespace psemek::audio
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sample_impl
|
struct track_impl
|
||||||
: sample
|
: track
|
||||||
{
|
{
|
||||||
Mix_Chunk * chunk;
|
Mix_Chunk * chunk;
|
||||||
|
|
||||||
sample_impl(Mix_Chunk * chunk)
|
track_impl(Mix_Chunk * chunk)
|
||||||
: chunk(chunk)
|
: chunk(chunk)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ namespace psemek::audio
|
||||||
return chunk->alen;
|
return chunk->alen;
|
||||||
}
|
}
|
||||||
|
|
||||||
~sample_impl()
|
~track_impl()
|
||||||
{
|
{
|
||||||
Mix_FreeChunk(chunk);
|
Mix_FreeChunk(chunk);
|
||||||
}
|
}
|
||||||
|
|
@ -66,14 +66,14 @@ namespace psemek::audio
|
||||||
bool playing = false;
|
bool playing = false;
|
||||||
|
|
||||||
int channel;
|
int channel;
|
||||||
std::shared_ptr<sample_impl> sample;
|
std::shared_ptr<track_impl> track;
|
||||||
bool loop;
|
bool loop;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<effect>> effects;
|
std::vector<std::shared_ptr<effect>> effects;
|
||||||
|
|
||||||
stream_impl(int channel, std::shared_ptr<sample_impl> sample, bool loop)
|
stream_impl(int channel, std::shared_ptr<track_impl> track, bool loop)
|
||||||
: channel(channel)
|
: channel(channel)
|
||||||
, sample(sample)
|
, track(track)
|
||||||
, loop(loop)
|
, loop(loop)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
@ -111,7 +111,7 @@ namespace psemek::audio
|
||||||
void start() override
|
void start() override
|
||||||
{
|
{
|
||||||
playing = true;
|
playing = true;
|
||||||
Mix_PlayChannel(channel, sample->chunk, loop ? -1 : 0);
|
Mix_PlayChannel(channel, track->chunk, loop ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pause() override
|
void pause() override
|
||||||
|
|
@ -158,7 +158,7 @@ namespace psemek::audio
|
||||||
impl();
|
impl();
|
||||||
~impl();
|
~impl();
|
||||||
|
|
||||||
std::shared_ptr<stream> play(std::shared_ptr<sample> s, bool loop);
|
std::shared_ptr<stream> play(std::shared_ptr<track> s, bool loop);
|
||||||
|
|
||||||
static void channel_finished(int ch);
|
static void channel_finished(int ch);
|
||||||
};
|
};
|
||||||
|
|
@ -197,9 +197,9 @@ namespace psemek::audio
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<stream> engine::impl::play(std::shared_ptr<sample> s, bool loop)
|
std::shared_ptr<stream> engine::impl::play(std::shared_ptr<track> s, bool loop)
|
||||||
{
|
{
|
||||||
auto ss = std::dynamic_pointer_cast<sample_impl>(s);
|
auto ss = std::dynamic_pointer_cast<track_impl>(s);
|
||||||
if (!ss)
|
if (!ss)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to play sample: unknown sample type");
|
throw std::runtime_error("Failed to play sample: unknown sample type");
|
||||||
|
|
@ -253,12 +253,12 @@ namespace psemek::audio
|
||||||
engine::~engine()
|
engine::~engine()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::shared_ptr<sample> engine::load_wav(char const * data, std::size_t size)
|
std::shared_ptr<track> engine::load(char const * data, std::size_t size)
|
||||||
{
|
{
|
||||||
return std::make_shared<sample_impl>(Mix_LoadWAV_RW(SDL_RWFromConstMem(data, size), 1));
|
return std::make_shared<track_impl>(Mix_LoadWAV_RW(SDL_RWFromConstMem(data, size), 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<sample> engine::load_raw(std::int16_t const * data, std::size_t sample_count, bool copy)
|
std::shared_ptr<track> engine::load_raw(std::int16_t const * data, std::size_t sample_count, bool copy)
|
||||||
{
|
{
|
||||||
Mix_Chunk * chunk = static_cast<Mix_Chunk *>(malloc(sizeof(Mix_Chunk)));
|
Mix_Chunk * chunk = static_cast<Mix_Chunk *>(malloc(sizeof(Mix_Chunk)));
|
||||||
chunk->allocated = copy ? 1 : 0;
|
chunk->allocated = copy ? 1 : 0;
|
||||||
|
|
@ -273,10 +273,10 @@ namespace psemek::audio
|
||||||
{
|
{
|
||||||
chunk->abuf = const_cast<Uint8 *>(reinterpret_cast<Uint8 const *>(data));
|
chunk->abuf = const_cast<Uint8 *>(reinterpret_cast<Uint8 const *>(data));
|
||||||
}
|
}
|
||||||
return std::make_shared<sample_impl>(chunk);
|
return std::make_shared<track_impl>(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<stream> engine::play(std::shared_ptr<sample> s, bool start, bool loop)
|
std::shared_ptr<stream> engine::play(std::shared_ptr<track> s, bool start, bool loop)
|
||||||
{
|
{
|
||||||
auto str = impl().play(std::move(s), loop);
|
auto str = impl().play(std::move(s), loop);
|
||||||
if (start) str->start();
|
if (start) str->start();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue