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

WIP: Audio mixer interface #569

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.3.2 Under development
Under development
=======================
- [feature] Audio mixer interface class (alexeevdv)

0.3.1 (2018-01-14)
=======================
Expand Down
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ if(NOT SDL2_FOUND)
endif(NOT SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR})

find_package(SDL2_mixer REQUIRED)
if(NOT SDLMIXER_FOUND)
message(FATAL_ERROR "SDL2_mixer library not found")
endif(NOT SDLMIXER_FOUND)
include_directories(${SDL_MIXER_INCLUDE_DIR})

find_package(SDL2_image REQUIRED)
if(NOT SDLIMAGE_FOUND)
message(FATAL_ERROR "SDL2_image library not found")
Expand Down Expand Up @@ -109,7 +103,7 @@ endif()
if (CONAN_LIBS)
target_link_libraries(falltergeist ${CONAN_LIBS})
else()
target_link_libraries(falltergeist ${ZLIB_LIBRARIES} ${SDL2_LIBRARY} ${SDL_MIXER_LIBRARY} ${SDL_IMAGE_LIBRARY} ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY})
target_link_libraries(falltergeist ${ZLIB_LIBRARIES} ${SDL2_LIBRARY} ${SDL_IMAGE_LIBRARY} ${OPENGL_gl_LIBRARY} ${GLEW_LIBRARY})
endif()

include(cmake/install/windows.cmake)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ https://falltergeist.org/
## Dependencies

- [SDL2](http://www.libsdl.org)
- [SDL2\_mixer](http://www.libsdl.org/projects/SDL_mixer/)
- [SDL2\_image](http://www.libsdl.org/projects/SDL_image/)
- [GLEW](http://glew.sourceforge.net/)
- [GLM](http://glm.g-truc.net/)
Expand Down
96 changes: 0 additions & 96 deletions cmake/modules/FindSDL2_mixer.cmake

This file was deleted.

2 changes: 0 additions & 2 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
zlib/1.2.11@lasote/stable
SDL2/2.0.5@lasote/stable
SDL2_image/2.0.1@lasote/stable
SDL2_mixer/2.0.1@a_teammate/testing
glew/2.0.0@coding3d/stable
glm/0.9.7.6@dlarudgus20/stable

Expand All @@ -13,7 +12,6 @@ cmake
SDL2:directx=False
SDL2:shared=False
SDL2_image:shared=False
SDL2_mixer:shared=False
libjpeg-turbo:shared=True
libpng:shared=True
zlib:shared=True
Expand Down
80 changes: 80 additions & 0 deletions src/Audio/AcmSound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2012-2018 Falltergeist Developers.
*
* This file is part of Falltergeist.
*
* Falltergeist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Falltergeist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Falltergeist. If not, see <http://www.gnu.org/licenses/>.
*/

// Related headers
#include "../Audio/AcmSound.h"

// C++ standard includes
#include <cstring>

// Falltergeist includes
#include "../Base/Buffer.h"
#include "../Format/Acm/File.h"

// Third party includes

namespace Falltergeist {
namespace Audio {
AcmSound::AcmSound(Format::Acm::File *acmFile) : _acmFile(acmFile) {
_acmFile->rewind();
}

uint8_t AcmSound::channels() {
return (uint8_t) _acmFile->channels();
}

uint32_t AcmSound::sampleRate() {
return (uint32_t) _acmFile->bitrate();
}

void AcmSound::rewind() {
_acmFile->rewind();
}

uint32_t AcmSound::samplesAvailable() {
return (uint32_t) _acmFile->samplesLeft();
}

uint32_t AcmSound::readSamples(uint8_t *audioBuffer, uint32_t bytes) {
if (_acmFile->samplesLeft() <= 0) {
memset(audioBuffer, 0, bytes);
return 0;
}

Base::Buffer<uint16_t> tmp(bytes / 2);
uint16_t *sstr = (uint16_t *) audioBuffer;
// TODO check if requested bytes cout is available
_acmFile->readSamples(tmp.data(), bytes / 4);
for (size_t i = 0; i < bytes / 4; i++) {
sstr[i * 2] = tmp[i];
sstr[i * 2 + 1] = tmp[i];
}

return bytes;
}

bool AcmSound::looped() {
return _looped;
}

void AcmSound::setLooped(bool value) {
_looped = value;
}
}
}
52 changes: 52 additions & 0 deletions src/Audio/AcmSound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2012-2018 Falltergeist Developers.
*
* This file is part of Falltergeist.
*
* Falltergeist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Falltergeist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Falltergeist. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

// C++ standard includes

// Falltergeist includes
#include "../Audio/ISound.h"

// Third party includes

namespace Falltergeist {
namespace Format {
namespace Acm {
class File;
}
}
namespace Audio {
class AcmSound : public ISound {
public:
explicit AcmSound(Format::Acm::File *acmFile);
~AcmSound() override = default;
uint8_t channels() override;
uint32_t sampleRate() override;
void rewind() override;
uint32_t samplesAvailable() override;
uint32_t readSamples(uint8_t *audioBuffer, uint32_t bytes) override;
bool looped() override;
void setLooped(bool value) override;
private:
Format::Acm::File* _acmFile = nullptr; // TODO use smart pointer instead
bool _looped = false;
};
}
}
108 changes: 108 additions & 0 deletions src/Audio/IMixer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2012-2018 Falltergeist Developers.
*
* This file is part of Falltergeist.
*
* Falltergeist is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Falltergeist is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Falltergeist. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

// C++ standard includes
#include <memory>
#include <string>

// Falltergeist includes
#include "../Audio/ISound.h"

// Third party includes

namespace Falltergeist {
namespace UI {
class MvePlayer;
}
namespace Audio {
enum class Channel {
Music,
Effects,
Speech
};
class IMixer {
public:
virtual ~IMixer() = default;

/**
* Play file looped in given channel
* @param channel
* @param filename
*/
virtual void playLooped(Channel channel, const std::string& filename) = 0;

/**
* Play file once in given channel
* @param channel
* @param filename
*/
virtual void playOnce(Channel channel, const std::string& filename) = 0;

/**
* Play sound in given channel
* @param channel
* @param sound
*/
virtual void play(Channel channel, std::shared_ptr<ISound> sound) = 0;

/**
* @param channel
*/
virtual void stopChannel(Channel channel) = 0;

/**
* @param channel
*/
virtual void pauseChannel(Channel channel) = 0;

/**
* @param channel
*/
virtual void resumeChannel(Channel channel) = 0;

/**
* Sets master volume
* @param volume from 0.0 to 1.0
*/
virtual void setMasterVolume(double volume) = 0;

/**
* Returns master volume
* @return from 0.0 to 1.0
*/
virtual double masterVolume() = 0;

/**
* Sets channel volume
* @param channel
* @param volume from 0.0 to 1.0
*/
virtual void setChannelVolume(Channel channel, double volume) = 0;

/**
* Returns channel volume
* @param channel
* @return from 0.0 to 1.0
*/
virtual double channelVolume(Channel channel) = 0;
};
}
}
Loading