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

Merge pull request #163 from RobLoach/setVolume

Add setVolume() and getVolume()
parents ff40e613 65ea9dba
......@@ -4,6 +4,11 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 0.12.0 - Unreleased
### Added
- `SoundData.getVolume()`
- `SoundData.setVolume()`
## 0.11.1 - 2017-12-10
### Fixed
- Version number
......
......@@ -67,8 +67,8 @@ void audio::mixer_render(int16_t *buffer) {
left = rawsamples16[j * 2 + 0];
right = rawsamples16[j * 2 + 1];
}
buffer[j * 2 + 0] += left * currentSound->volume * m_volume;
buffer[j * 2 + 1] += right * currentSound->volume * m_volume;
buffer[j * 2 + 0] += left * currentSound->getVolume() * m_volume;
buffer[j * 2 + 1] += right * currentSound->getVolume() * m_volume;
}
if (end) {
......
......@@ -127,6 +127,8 @@ script::script(const std::string& file) {
chai.add(fun(&SoundData::play), "play");
chai.add(fun(&SoundData::resume), "resume");
chai.add(fun(&SoundData::pause), "pause");
chai.add(fun(&SoundData::setVolume), "setVolume");
chai.add(fun(&SoundData::getVolume), "getVolume");
// Font.
chai.add(user_type<Font>(), "Font");
......
......@@ -29,6 +29,19 @@ SoundData::~SoundData() {
unload();
}
float SoundData::getVolume() {
return m_volume;
}
void SoundData::setVolume(float volume) {
if (volume > 1.0f) {
volume = 1.0f;
} else if (volume < 0.0f) {
volume = 0.0f;
}
m_volume = volume;
}
void SoundData::unload() {
if (isLoaded()) {
PHYSFS_close(sndta.fp);
......
......@@ -51,11 +51,21 @@ class SoundData {
snd_SoundData sndta;
unsigned bps = 0;
bool loop = false;
float volume = 1.0f;
float m_volume = 1.0f;
float pitch = 1.0f;
AudioState state = Stopped;
bool isLoaded();
/**
* @brief Gets the current volume of the Source.
*/
float getVolume();
/**
* @brief Sets the current volume of the Source.
*/
void setVolume(float volume);
/**
* @brief Returns whether the Source is playing.
*/
......
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