Browse Source

audio: reorganise files

legacy
Sam Hocevar 8 years ago
parent
commit
89a8add7bf
18 changed files with 313 additions and 268 deletions
  1. +6
    -2
      src/Makefile.am
  2. +0
    -37
      src/audio.h
  3. +13
    -6
      src/audio/audio.cpp
  4. +12
    -12
      src/audio/sample.cpp
  5. +84
    -0
      src/audio/sampler.cpp
  6. +1
    -1
      src/eglapp.cpp
  7. +7
    -6
      src/lol-core.vcxproj
  8. +20
    -17
      src/lol-core.vcxproj.filter
  9. +18
    -0
      src/lol/audio/all.h
  10. +41
    -0
      src/lol/audio/audio.h
  11. +52
    -0
      src/lol/audio/sample.h
  12. +41
    -0
      src/lol/audio/sampler.h
  13. +8
    -9
      src/lol/extras.h
  14. +9
    -6
      src/lol/public.h
  15. +1
    -1
      src/platform/sdl/sdlapp.cpp
  16. +0
    -50
      src/sample.h
  17. +0
    -82
      src/sampler.cpp
  18. +0
    -39
      src/sampler.h

+ 6
- 2
src/Makefile.am View File

@@ -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 \
\


+ 0
- 37
src/audio.h View File

@@ -1,37 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 <stdint.h>

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 */


src/audio.cpp → src/audio/audio.cpp View File

@@ -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);

src/sample.cpp → src/audio/sample.cpp View File

@@ -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("<sample> ") + 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)

+ 84
- 0
src/audio/sampler.cpp View File

@@ -0,0 +1,84 @@
//
// Lol Engine
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
//
// 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 <lol/engine-internal.h>

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 */


+ 1
- 1
src/eglapp.cpp View File

@@ -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
}



+ 7
- 6
src/lol-core.vcxproj View File

@@ -77,7 +77,9 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="application\application.cpp" />
<ClCompile Include="audio.cpp" />
<ClCompile Include="audio\audio.cpp" />
<ClCompile Include="audio\sample.cpp" />
<ClCompile Include="audio\sampler.cpp" />
<ClCompile Include="camera.cpp" />
<ClCompile Include="base\assert.cpp" />
<ClCompile Include="base\enum.cpp" />
@@ -197,8 +199,6 @@
<ClCompile Include="platform\sdl\sdlapp.cpp" />
<ClCompile Include="platform\sdl\sdlinput.cpp" />
<ClCompile Include="profiler.cpp" />
<ClCompile Include="sample.cpp" />
<ClCompile Include="sampler.cpp" />
<ClCompile Include="scene.cpp" />
<ClCompile Include="sprite.cpp" />
<ClCompile Include="sys\file.cpp" />
@@ -216,7 +216,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="application\application.h" />
<ClInclude Include="audio.h" />
<ClInclude Include="camera.h" />
<ClInclude Include="commandstack.h" />
<ClInclude Include="debug\fps.h" />
@@ -251,6 +250,10 @@
<ClInclude Include="lol\algorithm\all.h" />
<ClInclude Include="lol\algorithm\portal.h" />
<ClInclude Include="lol\algorithm\sort.h" />
<ClInclude Include="lol\audio\all.h" />
<ClInclude Include="lol\audio\audio.h" />
<ClInclude Include="lol\audio\sample.h" />
<ClInclude Include="lol\audio\sampler.h" />
<ClInclude Include="lol\base\all.h" />
<ClInclude Include="lol\base\array.h" />
<ClInclude Include="lol\base\assert.h" />
@@ -348,8 +351,6 @@
<ClInclude Include="platform\sdl\sdlapp.h" />
<ClInclude Include="platform\sdl\sdlinput.h" />
<ClInclude Include="profiler.h" />
<ClInclude Include="sample.h" />
<ClInclude Include="sampler.h" />
<ClInclude Include="scene.h" />
<ClInclude Include="sprite.h" />
<ClInclude Include="text.h" />


+ 20
- 17
src/lol-core.vcxproj.filter View File

@@ -201,8 +201,14 @@
<ClCompile Include="platform\d3d9\d3d9input.cpp">
<Filter>platform\d3d9</Filter>
</ClCompile>
<ClCompile Include="audio.cpp">
<Filter>...</Filter>
<ClCompile Include="audio\audio.cpp">
<Filter>audio</Filter>
</ClCompile>
<ClCompile Include="audio\sample.cpp">
<Filter>audio</Filter>
</ClCompile>
<ClCompile Include="audio\sampler.cpp">
<Filter>audio</Filter>
</ClCompile>
<ClCompile Include="camera.cpp">
<Filter>...</Filter>
@@ -234,12 +240,6 @@
<ClCompile Include="profiler.cpp">
<Filter>...</Filter>
</ClCompile>
<ClCompile Include="sample.cpp">
<Filter>...</Filter>
</ClCompile>
<ClCompile Include="sampler.cpp">
<Filter>...</Filter>
</ClCompile>
<ClCompile Include="sprite.cpp">
<Filter>...</Filter>
</ClCompile>
@@ -535,9 +535,6 @@
<ClInclude Include="platform\d3d9\d3d9input.h">
<Filter>platform\d3d9</Filter>
</ClInclude>
<ClInclude Include="audio.h">
<Filter>...</Filter>
</ClInclude>
<ClInclude Include="camera.h">
<Filter>...</Filter>
</ClInclude>
@@ -577,12 +574,6 @@
<ClInclude Include="profiler.h">
<Filter>...</Filter>
</ClInclude>
<ClInclude Include="sample.h">
<Filter>...</Filter>
</ClInclude>
<ClInclude Include="sampler.h">
<Filter>...</Filter>
</ClInclude>
<ClInclude Include="simd.h">
<Filter>...</Filter>
</ClInclude>
@@ -598,6 +589,18 @@
<ClInclude Include="easymesh\easymesh.h">
<Filter>easymesh</Filter>
</ClInclude>
<ClInclude Include="lol\audio\all.h">
<Filter>lol\audio</Filter>
</ClInclude>
<ClInclude Include="lol\audio\audio.h">
<Filter>lol\audio</Filter>
</ClInclude>
<ClInclude Include="lol\audio\sample.h">
<Filter>lol\audio</Filter>
</ClInclude>
<ClInclude Include="lol\audio\sampler.h">
<Filter>lol\audio</Filter>
</ClInclude>
<ClInclude Include="lol\base\array.h">
<Filter>lol\base</Filter>
</ClInclude>


+ 18
- 0
src/lol/audio/all.h View File

@@ -0,0 +1,18 @@
//
// Lol Engine
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
//
// 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 <lol/audio/audio.h>
#include <lol/audio/sampler.h>
#include <lol/audio/sample.h>


+ 41
- 0
src/lol/audio/audio.h View File

@@ -0,0 +1,41 @@
//
// Lol Engine
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
//
// 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 <stdint.h>

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 */


+ 52
- 0
src/lol/audio/sample.h View File

@@ -0,0 +1,52 @@
//
// Lol Engine
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
//
// 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 <stdint.h>

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 */


+ 41
- 0
src/lol/audio/sampler.h View File

@@ -0,0 +1,41 @@
//
// Lol Engine
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
//
// 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 <stdint.h>

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 */


+ 8
- 9
src/lol/extras.h View File

@@ -1,11 +1,13 @@
//
// Lol Engine
// Lol Engine
//
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// 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 <sam@hocevar.net>
//
// 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 <lol/../platform.h>
#include <lol/../video.h>
#include <lol/../audio.h>
#include <lol/../scene.h>
#include <lol/../profiler.h>
#include <lol/../messageservice.h>
@@ -45,7 +46,6 @@
#include <lol/../emitter.h>
#include <lol/../font.h>
#include <lol/../gradient.h>
#include <lol/../sample.h>
#include <lol/../sprite.h>
#include <lol/../text.h>
#include <lol/../textureimage.h>
@@ -64,5 +64,4 @@
// Managers
#include <lol/../forge.h>
#include <lol/../tiler.h>
#include <lol/../sampler.h>


+ 9
- 6
src/lol/public.h View File

@@ -1,11 +1,13 @@
//
// Lol Engine
// Lol Engine
//
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// 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 <sam@hocevar.net>
//
// 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 <lol/algorithm/all.h>
#include <lol/image/all.h>
#include <lol/sys/all.h>
#include <lol/audio/all.h>
#include <lol/gpu/all.h>
#include <lol/debug/all.h>


+ 1
- 1
src/platform/sdl/sdlapp.cpp View File

@@ -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


+ 0
- 50
src/sample.h View File

@@ -1,50 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// 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 <stdint.h>

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 */


+ 0
- 82
src/sampler.cpp View File

@@ -1,82 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 <lol/engine-internal.h>

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 */


+ 0
- 39
src/sampler.h View File

@@ -1,39 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 <stdint.h>

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 */


Loading…
Cancel
Save