Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libsoundio + libsndfile audio backend #33

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fb1c086
Started work on changing to libsoundio for audio
IceDragon200 Sep 8, 2015
dc44e7d
Added libsoundio paths to build, moved to libsoundio as the default a…
IceDragon200 Jun 29, 2016
a776a20
modules/audio-gorilla: Moved headers to mimic libsoundio module
IceDragon200 Jun 29, 2016
933bb5f
modules/audio-libsoundio: Stubbed audio structs
IceDragon200 Jun 29, 2016
05a2b1d
Make libsoundio a dependency of moon-player
IceDragon200 Jun 29, 2016
4b83dc6
modules/audio-libsoundio: Added SoundBuffer#sampleRate
IceDragon200 Jun 29, 2016
6541a72
modules/audio-libsoundio: Changed SoundBuffer structure a bit
IceDragon200 Jun 29, 2016
b92cd67
Do not build examples or tests for libsoundio
IceDragon200 Jun 29, 2016
6c95457
modules/audio-libsoundio: Force linkage static libsoundio.a
IceDragon200 Jun 29, 2016
05dcdcb
modules/system: Added M_PI
IceDragon200 Jun 29, 2016
21941e0
modules/audio-libsoundio: Beware the sine wave
IceDragon200 Jun 29, 2016
828067c
modules/audio-libsoundio: Made suggested changes
IceDragon200 Jun 30, 2016
6e62a5a
Updated libsoundio submodule
IceDragon200 Jun 30, 2016
f8f7ff9
Get it to build on OS X.
Jun 30, 2016
bf37f9e
Get libsndfile to compile and link.
Jun 30, 2016
d51ec68
Remove the sndfile submodule because cmake already fetches it.
Jun 30, 2016
18dbfeb
Add Source (untested)
Jun 30, 2016
820c6c7
Update README
Jun 30, 2016
70b15bd
modules/audio-libsoundio: Fixed source.cxx compilation
IceDragon200 Jul 1, 2016
e57857b
Set the sample rate to 44.1khz.
Jul 2, 2016
972afed
Use a tarball for libsndfile. Removes autotools dep + cached builds.
Jul 4, 2016
137044f
Disable soundio dynamic libs
IceDragon200 Jul 2, 2016
c2d0d94
Simple mixer extraction (get the code to goddamn compile)
Jul 4, 2016
779ac8b
Try getting audio streaming to work.
Jul 4, 2016
1266564
Do proper logic for sndfile buffer reads.
Jul 4, 2016
1092c99
Add missing file
Jul 4, 2016
5fe7ad8
use submodule fork for now
Jul 4, 2016
6fea83e
Should be plureal
Jul 4, 2016
80e9449
GET IT TO WORK!!
Jul 4, 2016
35ff5fd
Don't disable external libs...
Jul 4, 2016
80c7c6f
Get mixing to work.
Jul 5, 2016
1b00ab4
Link ogg/vorbis/flac.
Jul 5, 2016
78aae43
Extract the clipping code.
Jul 5, 2016
cf32445
Clear the buffer in case we read less than what was expected.
Jul 5, 2016
4ddb5fd
Update README a tiny bit.
Jul 5, 2016
e40d991
Oopsie, fix mixing.
Jul 5, 2016
9aeb88d
Fix some things, implement Sound.
Jul 5, 2016
3b0a843
Implement audio handles.
Jul 6, 2016
c886970
meme-set is evil
Jul 6, 2016
d62cb85
FLAC vs flac!
IceDragon200 Jul 6, 2016
2c98661
modules/system,modules/audio-libsoundio: Added moon_memzerof and code…
IceDragon200 Jul 6, 2016
a01ab3f
Fix Sound, sort of.
Jul 6, 2016
46ce621
hmm
Jul 6, 2016
87d48f7
Works at proper playback speed!
Jul 6, 2016
0204445
Add support for pan/pitch/gain and map mono to stereo.
Jul 9, 2016
d9edf98
modules/audio-libsoundio: Cleaned up audio.cxx
IceDragon200 Jul 9, 2016
0b77791
modules/audio-libsoundio: clamp was not available on my system for so…
IceDragon200 Jul 9, 2016
2f001af
modules/audio-libsoundio: Stubbed Music
IceDragon200 Jul 9, 2016
46f000a
modules/audio-libsoundio: Stubbed Sound mruby wrapper
IceDragon200 Jul 9, 2016
ed5cea0
modules/audio-libsoundio: Code gardening
IceDragon200 Jul 9, 2016
1453bc2
travis: When running gcc, use gcc 4.8.
Jul 10, 2016
e2d2b95
Updated libsoundio
IceDragon200 Jul 10, 2016
f41df49
modules/system: Split helpers header into smaller bits
IceDragon200 Jul 15, 2016
4053f5b
modules/{audio-libsound,system}: Butchered audio
IceDragon200 Jul 15, 2016
6976975
travis: Added missing audio packages
IceDragon200 Jul 15, 2016
0c3645f
Revert "modules/{audio-libsound,system}: Butchered audio"
Jul 17, 2016
475afe6
Add seek and tell to the Source interface.
Jul 17, 2016
592c876
Add a Loop source.
Jul 17, 2016
30c5039
Use a newer xcode7.3 and osx 10.11
Jul 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
[submodule "vendor/gorilla-audio"]
path = vendor/gorilla-audio
url = https://github.com/IceDragon200/gorilla-audio.git
[submodule "vendor/libsoundio"]
path = vendor/libsoundio
url = https://github.com/andrewrk/libsoundio
40 changes: 36 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ language: cpp
sudo: false
addons:
apt:
sources:
sources: &sources
- george-edison55-precise-backports
packages:
- ubuntu-toolchain-r-test
packages: &deps
- cmake
- cmake-data
- freeglut3-dev
- freetype
- libasound2-dev
- libdevil-dev
- libflac-dev
- libgles2-mesa-dev
- libglew-dev
- libglu1-mesa-dev
- libogg-dev
- libopenal-dev
- libpulse-dev
- libvorbis-dev
- libvorbisenc2
- libx11-dev
- libxi-dev
- libxmu-dev
Expand All @@ -23,15 +30,40 @@ matrix:
include:
- os: linux
compiler: gcc
env: MOON_MRUBY_TOOLCHAIN=gcc

env:
- MOON_MRUBY_TOOLCHAIN=gcc
- COMPILER=g++-4.9
before_install:
- export CC="gcc-4.9"
- export CXX="g++-4.9"
addons:
apt:
sources:
- *sources
packages:
- *deps
- gcc-4.9
- g++-4.9
- os: linux
compiler: clang
env:
- MOON_MRUBY_TOOLCHAIN=clang
- COMPILER=clang++-3.7
- LD_LIBRARY_PATH: "${TRAVIS_BUILD_DIR}/build/vendor/glfw/src"
before_install:
- export CC="clang-3.7"
- export CXX="clang++-3.7"
addons:
apt:
sources:
- *sources
- llvm-toolchain-precise-3.7
packages:
- *deps
- clang-3.7

- os: osx
osx_image: xcode7.3
compiler: clang
env:
- MOON_MRUBY_TOOLCHAIN=clang
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ project(moon)

find_library(YAML yaml)

include(cmake/BuildSndfile.cmake)

add_subdirectory("vendor/sil")
# cmake doesn't like relative paths for include dirs, so we'll need the absolute
# path instead
get_filename_component(SIL_INCLUDE_DIR "vendor/sil/include" ABSOLUTE)
add_subdirectory("vendor/soil")
add_subdirectory("vendor/gorilla-audio/build")
set(ENABLE_JACK OFF)
set(BUILD_EXAMPLE_PROGRAMS OFF)
set(BUILD_TESTS OFF)
set(BUILD_DYNAMIC_LIBS OFF)
add_subdirectory("vendor/libsoundio")
#add_subdirectory("vendor/glm")

option(freetype-gl_BUILD_DEMOS OFF)
Expand All @@ -30,7 +37,7 @@ if(RAKE_VERBOSE)
endif(RAKE_VERBOSE)

add_custom_target(moon-mruby ALL
DEPENDS SIL SOIL glfw freetype-gl gorilla
DEPENDS SIL SOIL glfw freetype-gl gorilla libsoundio_static libsndfile
COMMAND rake ${RAKE_VERBOSE_FLAG} MRUBY_CONFIG="${CMAKE_SOURCE_DIR}/mrb_config.rb"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/mruby"
)
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[![Coverity Scan Build Status](https://img.shields.io/coverity/scan/5666.svg)](https://scan.coverity.com/projects/5666)

## Introduction
Moon is a experimental prototyping 2D Game Engine written in C++ and scripted using [mruby](https://github.com/mruby/mruby).
Moon is a experimental 2D game engine prototype written in C++ and scripted using [mruby](https://github.com/mruby/mruby).


## Supported
Currently testing is done linux, moon may not run or even compile on other systems. If you managed to get Moon running on your system, please open a PR and share your changes to get it built.
Currently we have builds fo Linux and OS X. Moon may not run or even compile on other systems. If you managed to get Moon running on your system, please open a PR and share your changes to get it built.


## Requirements
Expand All @@ -24,14 +24,19 @@ ruby >= 1.9.2
yard (for docs)

# runtime
OpenAL
OpenAL # for gorilla audio
OpenGL

# For dependency docs
doxygen

# for mruby-yaml
yaml

# for libsndfile
flac
libogg
libvorbis
```

## Support
Expand Down
12 changes: 12 additions & 0 deletions cmake/BuildSndfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include(ExternalProject)

set(SNDFILE_TARBALL "libsndfile-1.0.27")

ExternalProject_Add(libsndfile
URL http://www.mega-nerd.com/libsndfile/files/${SNDFILE_TARBALL}.tar.gz
BUILD_IN_SOURCE 1
INSTALL_DIR vendor/libsndfile
CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/vendor/libsndfile --disable-shared
BUILD_COMMAND $(MAKE) V=1
INSTALL_COMMAND $(MAKE) install
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef MOON_AUDIO_H
#define MOON_AUDIO_H
#ifndef MOON_AUDIO_GORILLA_H
#define MOON_AUDIO_GORILLA_H

/* Gorilla Audio */
#include <gorilla/ga.h>
#include <gorilla/gau.h>
#define MOON_AUDIO_BACKEND "gorilla"

namespace Moon {
class Audio {
Expand All @@ -14,6 +15,7 @@ namespace Moon {
static ga_Mixer* GetMixer();
static ga_StreamManager* GetStreamMgr();
protected:
static bool m_initialized;
static gau_Manager* m_mgr;
static ga_Mixer* m_mixer;
static ga_StreamManager* m_streamMgr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MOON_MUSIC_H
#define MOON_MUSIC_H

#include "moon/gorilla/audio.hxx"
#include "moon/audio/gorilla/audio.hxx"

namespace Moon {
struct Music {
Expand Down
6 changes: 3 additions & 3 deletions modules/audio-gorilla/mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ MRuby::Gem::Specification.new('mruby-moon-audio-gorilla') do |spec|
cc.flags << '-Wextra'
end

#spec.cxx do |cxx|
# cxx.flags << '-std=c++11'
#end
spec.linker do |l|
l.libraries << 'gorilla'
end

spec.add_dependency 'mruby-moon-system'
end
3 changes: 1 addition & 2 deletions modules/audio-gorilla/src/audio.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "moon/gorilla/audio.hxx"
#include "moon/audio/gorilla/audio.hxx"

namespace Moon {
gau_Manager* Audio::m_mgr = NULL;
Expand Down Expand Up @@ -41,4 +41,3 @@ namespace Moon {
return m_streamMgr;
};
}

6 changes: 3 additions & 3 deletions modules/audio-gorilla/src/mrb_moon_audio.cxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <mruby.h>
#include <mruby/class.h>
#include "moon/gorilla/audio.hxx"
#include "moon/gorilla/mrb/music.hxx"
#include "moon/gorilla/mrb/sound.hxx"
#include "moon/audio/gorilla/audio.hxx"
#include "moon/audio/gorilla/mrb/music.hxx"
#include "moon/audio/gorilla/mrb/sound.hxx"

/* Call once per step/frame to update the internal Audio module.
*/
Expand Down
4 changes: 2 additions & 2 deletions modules/audio-gorilla/src/mrb_music.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <mruby/class.h>
#include <mruby/data.h>
#include <mruby/numeric.h>
#include "moon/gorilla/mrb/music.hxx"
#include "moon/gorilla/music.hxx"
#include "moon/audio/gorilla/mrb/music.hxx"
#include "moon/audio/gorilla/music.hxx"
#include "moon/api.h"
#include "moon/intern.h"

Expand Down
6 changes: 3 additions & 3 deletions modules/audio-gorilla/src/mrb_sound.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <mruby/class.h>
#include <mruby/data.h>
#include <mruby/numeric.h>
#include "moon/gorilla/mrb/sound.hxx"
#include "moon/gorilla/audio.hxx"
#include "moon/audio/gorilla/mrb/sound.hxx"
#include "moon/audio/gorilla/audio.hxx"
#include "moon/api.h"
#include "moon/intern.h"

Expand All @@ -16,7 +16,7 @@ sound_free(mrb_state *mrb, void *p)
}
}

MOON_C_API const struct mrb_data_type sound_data_type = { "Sound", sound_free };
MOON_C_API const struct mrb_data_type sound_data_type = { "Moon::Sound", sound_free };

static inline ga_Sound*
get_sound(mrb_state *mrb, mrb_value self)
Expand Down
45 changes: 45 additions & 0 deletions modules/audio-libsoundio/include/moon/audio/libsoundio/audio.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef MOON_AUDIO_H
#define MOON_AUDIO_H

#include "moon/intern.h"
#include <vector>
#include <soundio/soundio.h>
#define MOON_AUDIO_BACKEND "libsoundio"
#include "moon/audio/libsoundio/mixer.hxx"
#include "moon/audio/libsoundio/music.hxx"
#include "moon/audio/libsoundio/sound.hxx"

namespace Moon {
class Audio {
public:
enum ErrorCode {
MOON_AUDIO_OK,
// SoundIO failed to create
MOON_AUDIO_CREATE_ERROR,
// could not establish a connection to the audio server/device
MOON_AUDIO_CONNECTION_ERROR,
// There is no default device present
MOON_AUDIO_NO_DEVICE,
// The device specified by the index, has gone away or does not exist
MOON_AUDIO_DEVICE_MISSING,
// Could not open a stream for audio output
MOON_AUDIO_COULD_NOT_OPEN_STREAM,
// The specified channel layout is not supported
MOON_AUDIO_STREAM_CHANNEL_LAYOUT_ERROR,
// Stream could not be started
MOON_AUDIO_STREAM_START_ERROR
};

static ErrorCode Initialize();
static void Update();
static void Terminate();
static Mixer* m_mixer;
protected:
static bool m_initialized;
static struct SoundIo* m_soundIO;
static struct SoundIoDevice* m_device;
static struct SoundIoOutStream* m_outStream;
};
};

#endif
28 changes: 28 additions & 0 deletions modules/audio-libsoundio/include/moon/audio/libsoundio/handle.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef MOON_AUDIO_LIBSOUNDIO_HANDLE_H
#define MOON_AUDIO_LIBSOUNDIO_HANDLE_H

#include "moon/intern.h"
#include <vector>
#include <soundio/soundio.h>
#include "moon/audio/libsoundio/source.hxx"
#include "moon/audio/libsoundio/music.hxx"
#include "moon/audio/libsoundio/sound.hxx"
#include "moon/audio/libsoundio/loop.hxx"

namespace Moon {
class Handle {
public:
Handle(Moon::Source* source);
~Handle();

void mix(struct SoundIoChannelArea *areas, const struct SoundIoChannelLayout &layout, const float sampleRate, unsigned int frames);

float pan;
float pitch;
float gain;
private:
Moon::Source* source; // TODO:mrb_sound/music sources will need to be wrapped... if a source deallocates, the handle will be broken (shared_ptr)
};
};

#endif
29 changes: 29 additions & 0 deletions modules/audio-libsoundio/include/moon/audio/libsoundio/loop.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef MOON_AUDIO_LIBSOUNDIO_LOOP_H
#define MOON_AUDIO_LIBSOUNDIO_LOOP_H

#include "moon/intern.h"
#include <string>
#include <sndfile.hh>
#include "moon/audio/libsoundio/source.hxx"
#include "moon/audio/libsoundio/mixer.hxx"

namespace Moon
{
class Loop : public Source {
public:
Loop(Moon::Source* source, std::uint32_t trigger, std::uint32_t target);
virtual ~Loop();

int read(float* dst, int frames);
std::uint32_t seek(std::uint32_t pos);

int channels();
int sampleRate();
private:
std::uint32_t trigger;
std::uint32_t target;
Moon::Source* source; // TODO:mrb_sound/music sources will need to be wrapped... if a source deallocates, the handle will be broken (shared_ptr)
};
};

#endif
21 changes: 21 additions & 0 deletions modules/audio-libsoundio/include/moon/audio/libsoundio/mixer.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef MOON_AUDIO_LIBSOUNDIO_MIXER_H
#define MOON_AUDIO_LIBSOUNDIO_MIXER_H

#include "moon/intern.h"
#include <soundio/soundio.h>
#include <vector>
#include "moon/audio/libsoundio/handle.hxx"

namespace Moon
{
class Mixer {
public:
Mixer();

void mix(struct SoundIoChannelArea *areas, const struct SoundIoChannelLayout &layout, const float sampleRate, unsigned int frames);
std::vector<Handle*> handles;
private:
};
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef MMRB_MUSIC_H
#define MMRB_MUSIC_H

#include <mruby.h>
#include <mruby/class.h>
#include <mruby/data.h>
#include "moon/api.h"

MOON_C_API const struct mrb_data_type music_data_type;
MOON_C_API void mmrb_music_init(mrb_state *mrb, struct RClass *mod);

#endif
Loading