From 89a8add7bf2a1b4ce97acc2201cbdaef365bad1d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 8 Oct 2016 12:56:44 +0200 Subject: [PATCH] audio: reorganise files --- src/Makefile.am | 8 +++- src/audio.h | 37 ---------------- src/{ => audio}/audio.cpp | 19 ++++++--- src/{ => audio}/sample.cpp | 24 +++++------ src/audio/sampler.cpp | 84 +++++++++++++++++++++++++++++++++++++ src/eglapp.cpp | 2 +- src/lol-core.vcxproj | 13 +++--- src/lol-core.vcxproj.filter | 37 ++++++++-------- src/lol/audio/all.h | 18 ++++++++ src/lol/audio/audio.h | 41 ++++++++++++++++++ src/lol/audio/sample.h | 52 +++++++++++++++++++++++ src/lol/audio/sampler.h | 41 ++++++++++++++++++ src/lol/extras.h | 17 ++++---- src/lol/public.h | 15 ++++--- src/platform/sdl/sdlapp.cpp | 2 +- src/sample.h | 50 ---------------------- src/sampler.cpp | 82 ------------------------------------ src/sampler.h | 39 ----------------- 18 files changed, 313 insertions(+), 268 deletions(-) delete mode 100644 src/audio.h rename src/{ => audio}/audio.cpp (79%) rename src/{ => audio}/sample.cpp (86%) create mode 100644 src/audio/sampler.cpp create mode 100644 src/lol/audio/all.h create mode 100644 src/lol/audio/audio.h create mode 100644 src/lol/audio/sample.h create mode 100644 src/lol/audio/sampler.h delete mode 100644 src/sample.h delete mode 100644 src/sampler.cpp delete mode 100644 src/sampler.h diff --git a/src/Makefile.am b/src/Makefile.am index c4d8c85a..7d92b444 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,10 +7,9 @@ noinst_LIBRARIES = liblol-core.a liblol_core_a_SOURCES = \ tiler.cpp tiler.h dict.cpp dict.h lolgl.h \ - audio.cpp audio.h scene.cpp scene.h font.cpp font.h \ + scene.cpp scene.h font.cpp font.h \ textureimage.cpp textureimage.h textureimage-private.h \ tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h \ - sample.cpp sample.h sampler.cpp sampler.h \ profiler.cpp profiler.h text.cpp text.h emitter.cpp emitter.h \ numeric.h utils.h messageservice.cpp messageservice.h \ gradient.cpp gradient.h gradient.lolfx \ @@ -46,6 +45,9 @@ liblol_core_headers = \ lol/algorithm/all.h \ lol/algorithm/sort.h lol/algorithm/portal.h lol/algorithm/aabb_tree.h \ \ + lol/audio/all.h \ + lol/audio/audio.h lol/audio/sampler.h lol/audio/sample.h \ + \ lol/sys/all.h \ lol/sys/init.h lol/sys/file.h lol/sys/getopt.h lol/sys/thread.h \ lol/sys/threadtypes.h lol/sys/timer.h \ @@ -92,6 +94,8 @@ liblol_core_sources = \ gpu/framebuffer.cpp gpu/texture.cpp gpu/renderer.cpp \ gpu/rendercontext.cpp \ \ + audio/audio.cpp audio/sampler.cpp audio/sample.cpp \ + \ input/input.cpp input/input.h input/input_internal.h input/keys.h \ input/controller.cpp input/controller.h \ \ diff --git a/src/audio.h b/src/audio.h deleted file mode 100644 index a60f5e81..00000000 --- a/src/audio.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2011 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -#pragma once - -// -// The Audio interface -// ------------------- -// Helper functions to set up the audio device. -// - -#include - -namespace lol -{ - -class Audio -{ -public: - static void Setup(int channels); - static void SetVolume(int channel,int volume); - static void MuteAll(); - static void UnmuteAll(); - -private: - Audio() {} -}; - -} /* namespace lol */ - diff --git a/src/audio.cpp b/src/audio/audio.cpp similarity index 79% rename from src/audio.cpp rename to src/audio/audio.cpp index b206b7ac..884950e9 100644 --- a/src/audio.cpp +++ b/src/audio/audio.cpp @@ -29,19 +29,26 @@ namespace lol { /* - * Public Audio class + * Public audio class */ -void Audio::Setup(int channels) +void audio::init() { #if defined LOL_USE_SDL_MIXER - Mix_OpenAudio(22050, AUDIO_S16, channels, 1024); + Mix_OpenAudio(22050, AUDIO_S16, 8, 1024); +#endif +} + +void audio::set_channels(int channels) +{ +#if defined LOL_USE_SDL_MIXER + Mix_AllocateChannels(channels); #else UNUSED(channels); #endif } -void Audio::SetVolume(int channel, int volume) +void audio::set_volume(int channel, int volume) { #if defined LOL_USE_SDL_MIXER Mix_Volume(channel,volume); @@ -50,7 +57,7 @@ void Audio::SetVolume(int channel, int volume) #endif } -void Audio::MuteAll() +void audio::mute_all() { #if defined LOL_USE_SDL_MIXER Mix_Volume(-1,0); @@ -59,7 +66,7 @@ void Audio::MuteAll() #endif } -void Audio::UnmuteAll() +void audio::unmute_all() { #if defined LOL_USE_SDL_MIXER Mix_Volume(-1,MIX_MAX_VOLUME); diff --git a/src/sample.cpp b/src/audio/sample.cpp similarity index 86% rename from src/sample.cpp rename to src/audio/sample.cpp index 3fba9277..d2fe62d6 100644 --- a/src/sample.cpp +++ b/src/audio/sample.cpp @@ -33,12 +33,12 @@ namespace lol { /* - * Sample implementation class + * sample implementation class */ -class SampleData +class sample_data { - friend class Sample; + friend class sample; private: String m_name; @@ -49,11 +49,11 @@ private: }; /* - * Public Sample class + * Public sample class */ -Sample::Sample(char const *path) - : data(new SampleData()) +sample::sample(char const *path) + : data(new sample_data()) { data->m_name = String(" ") + path; @@ -72,7 +72,7 @@ Sample::Sample(char const *path) #endif } -Sample::~Sample() +sample::~sample() { #if defined LOL_USE_SDL_MIXER if (data->m_chunk) @@ -81,17 +81,17 @@ Sample::~Sample() delete data; } -void Sample::TickGame(float seconds) +void sample::TickGame(float seconds) { Entity::TickGame(seconds); } -char const *Sample::GetName() +char const *sample::GetName() { return data->m_name.C(); } -void Sample::Play() +void sample::play() { #if defined LOL_USE_SDL_MIXER if (data->m_chunk) @@ -99,7 +99,7 @@ void Sample::Play() #endif } -void Sample::Loop() +void sample::loop() { #if defined LOL_USE_SDL_MIXER if (data->m_chunk) @@ -107,7 +107,7 @@ void Sample::Loop() #endif } -void Sample::Stop() +void sample::stop() { #if defined LOL_USE_SDL_MIXER if (data->m_channel >= 0) diff --git a/src/audio/sampler.cpp b/src/audio/sampler.cpp new file mode 100644 index 00000000..55360ad1 --- /dev/null +++ b/src/audio/sampler.cpp @@ -0,0 +1,84 @@ +// +// Lol Engine +// +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#include + +namespace lol +{ + +/* + * sampler implementation class + */ + +static class sampler_data +{ + friend class sampler; + +public: + Dict samples; +} +samplerdata; + +static sampler_data * const data = &samplerdata; + +/* + * Public sampler class + */ + +int sampler::load_sample(char const *path) +{ + int id = data->samples.MakeSlot(path); + + if (!data->samples.GetEntity(id)) + { + sample *s = new sample(path); + data->samples.SetEntity(id, s); + } + + return id + 1; /* ID 0 is for the empty sample */ +} + +void sampler::unload_sample(int id) +{ + if (id > 0) + data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */ +} + +void sampler::play_sample(int id) +{ + if (id > 0) + { + sample *s = (sample *)data->samples.GetEntity(id - 1); + s->play(); + } +} + +void sampler::loop_sample(int id) +{ + if (id > 0) + { + sample *s = (sample *)data->samples.GetEntity(id - 1); + s->loop(); + } +} + +void sampler::stop_sample(int id) +{ + if (id > 0) + { + sample *s = (sample *)data->samples.GetEntity(id - 1); + s->stop(); + } +} + +} /* namespace lol */ + diff --git a/src/eglapp.cpp b/src/eglapp.cpp index c9741dda..569c074f 100644 --- a/src/eglapp.cpp +++ b/src/eglapp.cpp @@ -258,7 +258,7 @@ EglApp::EglApp(char const *title, ivec2 res, float fps) : /* Initialise everything */ Ticker::Setup(fps); Video::Setup((ivec2)data->screen_size); - Audio::Setup(2); + audio::init(); #endif } diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj index 431b5878..2a02b20c 100644 --- a/src/lol-core.vcxproj +++ b/src/lol-core.vcxproj @@ -77,7 +77,9 @@ - + + + @@ -197,8 +199,6 @@ - - @@ -216,7 +216,6 @@ - @@ -251,6 +250,10 @@ + + + + @@ -348,8 +351,6 @@ - - diff --git a/src/lol-core.vcxproj.filter b/src/lol-core.vcxproj.filter index 322a9d4e..5bc06437 100644 --- a/src/lol-core.vcxproj.filter +++ b/src/lol-core.vcxproj.filter @@ -201,8 +201,14 @@ platform\d3d9 - - ... + + audio + + + audio + + + audio ... @@ -234,12 +240,6 @@ ... - - ... - - - ... - ... @@ -535,9 +535,6 @@ platform\d3d9 - - ... - ... @@ -577,12 +574,6 @@ ... - - ... - - - ... - ... @@ -598,6 +589,18 @@ easymesh + + lol\audio + + + lol\audio + + + lol\audio + + + lol\audio + lol\base diff --git a/src/lol/audio/all.h b/src/lol/audio/all.h new file mode 100644 index 00000000..68f2947b --- /dev/null +++ b/src/lol/audio/all.h @@ -0,0 +1,18 @@ +// +// Lol Engine +// +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +#include +#include +#include + diff --git a/src/lol/audio/audio.h b/src/lol/audio/audio.h new file mode 100644 index 00000000..8ad9a40d --- /dev/null +++ b/src/lol/audio/audio.h @@ -0,0 +1,41 @@ +// +// Lol Engine +// +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +// +// The audio interface +// ------------------- +// Helper functions to set up the audio device. +// + +#include + +namespace lol +{ + +class audio +{ +public: + static void init(); + + static void set_channels(int channels); + static void set_volume(int channel,int volume); + static void mute_all(); + static void unmute_all(); + +private: + audio() {} +}; + +} /* namespace lol */ + diff --git a/src/lol/audio/sample.h b/src/lol/audio/sample.h new file mode 100644 index 00000000..e2871a61 --- /dev/null +++ b/src/lol/audio/sample.h @@ -0,0 +1,52 @@ +// +// Lol Engine +// +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +// +// The sample class +// ---------------- +// A sample is a unique sound sample. +// + +#include "engine/entity.h" + +#include + +namespace lol +{ + +class sample_data; + +class sample : public Entity +{ +public: + sample(char const *path); + virtual ~sample(); + +protected: + /* Inherited from Entity */ + virtual char const *GetName(); + virtual void TickGame(float seconds); + +public: + /* New methods */ + void play(); + void loop(); + void stop(); + +private: + sample_data *data; +}; + +} /* namespace lol */ + diff --git a/src/lol/audio/sampler.h b/src/lol/audio/sampler.h new file mode 100644 index 00000000..1a24f359 --- /dev/null +++ b/src/lol/audio/sampler.h @@ -0,0 +1,41 @@ +// +// Lol Engine +// +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +// +// The sampler class +// ----------------- +// The sampler is a static class that manages samples. +// + +#include + +namespace lol +{ + +class sampler +{ +public: + static int load_sample(char const *path); + static void unload_sample(int id); + + static void play_sample(int id); + static void loop_sample(int id); + static void stop_sample(int id); + +private: + sampler() {} +}; + +} /* namespace lol */ + diff --git a/src/lol/extras.h b/src/lol/extras.h index 62e62071..4a678055 100644 --- a/src/lol/extras.h +++ b/src/lol/extras.h @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #pragma once @@ -24,7 +26,6 @@ // Static classes #include #include -#include #include #include #include @@ -45,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -64,5 +64,4 @@ // Managers #include #include -#include diff --git a/src/lol/public.h b/src/lol/public.h index 36db90c2..626ae221 100644 --- a/src/lol/public.h +++ b/src/lol/public.h @@ -1,11 +1,13 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright © 2010—2016 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. // #pragma once @@ -20,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 772556cc..e2f16ca4 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -207,7 +207,7 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : /* Initialise everything */ Ticker::Setup(fps); - Audio::Setup(2); + audio::init(); /* Autoreleased objects */ #if defined LOL_USE_XINPUT diff --git a/src/sample.h b/src/sample.h deleted file mode 100644 index fa3bfa2b..00000000 --- a/src/sample.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2013 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -#pragma once - -// -// The Sample class -// ---------------- -// A Sample is a unique sound sample. -// - -#include "engine/entity.h" - -#include - -namespace lol -{ - -class SampleData; - -class Sample : public Entity -{ -public: - Sample(char const *path); - virtual ~Sample(); - -protected: - /* Inherited from Entity */ - virtual char const *GetName(); - virtual void TickGame(float seconds); - -public: - /* New methods */ - void Play(); - void Loop(); - void Stop(); - -private: - SampleData *data; -}; - -} /* namespace lol */ - diff --git a/src/sampler.cpp b/src/sampler.cpp deleted file mode 100644 index f3380d85..00000000 --- a/src/sampler.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2011 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -#include - -namespace lol -{ - -/* - * Sampler implementation class - */ - -static class SamplerData -{ - friend class Sampler; - -public: - Dict samples; -} -samplerdata; - -static SamplerData * const data = &samplerdata; - -/* - * Public Sampler class - */ - -int Sampler::Register(char const *path) -{ - int id = data->samples.MakeSlot(path); - - if (!data->samples.GetEntity(id)) - { - Sample *sample = new Sample(path); - data->samples.SetEntity(id, sample); - } - - return id + 1; /* ID 0 is for the empty sample */ -} - -void Sampler::Deregister(int id) -{ - if (id > 0) - data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */ -} - -void Sampler::PlaySample(int id) -{ - if (id > 0) - { - Sample *sample = (Sample *)data->samples.GetEntity(id - 1); - sample->Play(); - } -} - -void Sampler::LoopSample(int id) -{ - if (id > 0) - { - Sample *sample = (Sample *)data->samples.GetEntity(id - 1); - sample->Loop(); - } -} - -void Sampler::StopSample(int id) -{ - if (id > 0) - { - Sample *sample = (Sample *)data->samples.GetEntity(id - 1); - sample->Stop(); - } -} - -} /* namespace lol */ - diff --git a/src/sampler.h b/src/sampler.h deleted file mode 100644 index 2e8e4706..00000000 --- a/src/sampler.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2011 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -#pragma once - -// -// The Sampler class -// ----------------- -// The Sampler is a static class that manages samples. -// - -#include - -namespace lol -{ - -class Sampler -{ -public: - static int Register(char const *path); - static void Deregister(int id); - - static void PlaySample(int id); - static void LoopSample(int id); - static void StopSample(int id); - -private: - Sampler() {} -}; - -} /* namespace lol */ -