Unverified Commit 19689366 authored by RobLoach's avatar RobLoach Committed by GitHub
Browse files

Merge pull request #294 from libretro/ogg

Add OGG support
parents 1c87a2d4 b1c9aaad
......@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## 0.25.0 - Unreleased
### Features
- Added Cheat support
- Added .ogg audio support
### Fixes
- Fix loading save states
......
......@@ -46,6 +46,11 @@ SOURCES_C += $(wildcard \
$(CORE_DIR)/vendor/libretro-common/lists/string_list.c \
)
# stb_vorbis
#SOURCES_C += $(CORE_DIR)/vendor/stb/stb_vorbis.c
FLAGS += -DHAVE_STB_VORBIS
FLAGS += -I$(CORE_DIR)/vendor/libretro-deps
# zlib
SOURCES_C += \
$(CORE_DIR)/vendor/libretro-deps/libz/zutil.c \
......
......@@ -12,23 +12,39 @@ namespace Types {
namespace Audio {
SoundData::SoundData(const std::string& filename) {
// Load the file.
// Check the extension.
ChaiLove* app = ChaiLove::getInstance();
std::string extension = app->filesystem.newFileData(filename).getExtension();
if (extension != "wav" && extension != "ogg") {
std::cout << "[ChaiLove] [SoundData] Unknown extension " << extension << " for file " << filename << "." << std::endl;
return;
}
// Load the file.
int size = 0;
void* buffer = app->filesystem.readBuffer(filename, size);
buffer = app->filesystem.readBuffer(filename, size);
if (buffer == NULL) {
std::cout << "[ChaiLove] [SoundData] Failed to load file buffer " << filename << std::endl;
std::cout << "[ChaiLove] [SoundData] Failed to load file " << filename << std::endl;
return;
}
// Load the file into the buffer.
// TODO(RobLoach): Check the audio file extensions of ".wav".
m_sound = audio_mixer_load_wav(buffer, size);
free(buffer);
// Load the audio from the file.
if (extension == "wav") {
m_sound = audio_mixer_load_wav(buffer, size);
// Wav files don't need the buffer anymore.
free(buffer);
buffer = NULL;
} else if (extension == "ogg") {
m_sound = audio_mixer_load_ogg(buffer, size);
}
// Finally, if it failed, report as such.
if (m_sound == NULL) {
std::cout << "[ChaiLove] [SoundData] Failed to load wav from buffer " << filename << std::endl;
std::cout << "[ChaiLove] [SoundData] Failed to load audio for " << filename << std::endl;
if (buffer != NULL) {
free(buffer);
buffer = NULL;
}
}
}
......@@ -61,8 +77,9 @@ SoundData& SoundData::setVolume(float volume) {
void SoundData::unload() {
if (m_voice != NULL) {
audio_mixer_stop(m_voice);
m_voice = NULL;
}
if (isLoaded()) {
if (m_sound != NULL) {
audio_mixer_destroy(m_sound);
m_sound = NULL;
}
......
......@@ -63,16 +63,17 @@ class SoundData {
*/
SoundData& setLooping(bool loop);
// The audio callback for when a sound finishes.
static void audioCallback(audio_mixer_sound_t* sound, unsigned reason);
// Properties
bool m_playing = false;
bool m_loop = false;
float m_volume = 1.0f;
void* buffer = NULL;
audio_mixer_sound* m_sound = NULL;
// TODO(RobLoach): Make voice a vector.
// TODO(RobLoach): Make voice a vector?
audio_mixer_voice_t* m_voice = NULL;
// The audio callback for when a sound finishes.
static void audioCallback(audio_mixer_sound_t* sound, unsigned reason);
};
} // namespace Audio
......
......@@ -29,6 +29,8 @@ class audio {
* @param type ("static") The type of audio source to load ("static", "stream"). Optional.
*
* @return The new SoundData if it loaded correctly, NULL otherwise.
*
* @see love.sound.newSoundData
*/
SoundData* newSource(const std::string& filename, const std::string& type);
SoundData* newSource(const std::string& filename);
......
......@@ -29,10 +29,9 @@ bool sound::isLoaded() {
}
void sound::unload() {
// Unload all sounds.
for (std::vector<SoundData*>::size_type i = 0; i != sounds.size(); i++) {
if (sounds[i] != NULL) {
delete sounds[i];
for(std::vector<SoundData*>::iterator it = sounds.begin(); it != sounds.end(); ++it) {
if (*it != NULL) {
delete *it;
}
}
sounds.clear();
......
......@@ -22,6 +22,10 @@ class sound {
/**
* Creates a new SoundData.
*
* Supported file types include:
* - WAV
* - OGG
*
* @param filename The file name of the file to load.
*
* @return A new SoundData object, NULL if loading failed.
......
......@@ -9,7 +9,14 @@
global beat
def load() {
beat = love.audio.newSource("assets/startup.wav")
beat = love.audio.newSource("unittests/assets/chailove.ogg")
print("LOADED!")
if (beat.is_var_null()) {
print("NULLLL!!!!!")
}
//beat = love.audio.newSource("assets/startup.wav")
}
def draw() {
......
......@@ -34,7 +34,7 @@ assert_not(love.filesystem.isSymlink("keyboard.chai"), "love.filesystem.isSymlin
// getDirectoryItems()
var getDirectoriesItems = love.filesystem.getDirectoryItems("assets").size()
assert_equal(getDirectoriesItems, 3, "love.filesystem.getDirectoryItems()")
assert_equal(getDirectoriesItems, 4, "love.filesystem.getDirectoryItems()")
// lines()
var theLines = love.filesystem.lines("filesystem.chai")
......
......@@ -2,6 +2,10 @@
var theSound = love.sound.newSoundData("assets/jump.wav")
assert_not(theSound.is_var_null(), "love.sound.newSoundData()")
// newSoundData() with OGG
var theOgg = love.sound.newSoundData("assets/chailove.ogg")
assert_not(theOgg.is_var_null(), " - ogg")
// getVolume()
assert_equal(theSound.getVolume(), 1.0f, "SoundData.getVolume()")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment