Skip to content
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
15 changes: 8 additions & 7 deletions data/music/forest/forest-cave.music
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(supertux-music
(file "forest-cave.ogg")
(authors "Jason Lavallée")
(license "CC-BY-SA / GPL 2+")
(loop-begin 0)
(loop-at 149)
)
(supertux-music
(file "forest-cave.ogg")
(authors "Jason Lavallée")
(license "CC-BY-SA / GPL 2+")
(volume 0.4)
(loop-begin 0)
(loop-at 149)
)
1 change: 1 addition & 0 deletions src/audio/sound_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ std::unique_ptr<SoundFile> load_music_file(const std::string& filename_original)
sound_file = std::make_unique<OggSoundFile>(file, loop_begin, loop_at);
}

music.get("volume", sound_file->m_volume, 1.0f);
music.get("authors", sound_file->m_authors);
music.get("license", sound_file->m_license);
music.get("title", sound_file->m_title);
Expand Down
3 changes: 3 additions & 0 deletions src/audio/sound_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SoundFile
m_rate(),
m_bits_per_sample(),
m_size(),
m_volume(1.0f),
m_authors(),
m_license(),
m_title()
Expand All @@ -55,6 +56,8 @@ class SoundFile
int m_bits_per_sample;
/// size in bytes
size_t m_size;
/// innate volume adjustment, 0.0 to 1.0
float m_volume;
std::vector<std::string> m_authors;
std::string m_license;
std::string m_title;
Expand Down
20 changes: 20 additions & 0 deletions src/audio/stream_sound_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ StreamSoundSource::set_sound_file(std::unique_ptr<SoundFile> newfile)
{
m_file = std::move(newfile);

alSourcef(m_source, AL_GAIN, m_gain * m_volume * m_file->m_volume);

ALint queued;
alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queued);
for (size_t i = 0; i < STREAMFRAGMENTS - queued; ++i) {
Expand Down Expand Up @@ -131,6 +133,24 @@ StreamSoundSource::update()
}
}

void
StreamSoundSource::set_gain(float gain)
{
m_gain = gain;
if (m_file) {
alSourcef(m_source, AL_GAIN, m_gain * m_volume * m_file->m_volume);
}
}

void
StreamSoundSource::set_volume(float volume)
{
m_volume = volume;
if (m_file) {
alSourcef(m_source, AL_GAIN, m_gain * m_volume * m_file->m_volume);
}
}

void
StreamSoundSource::set_fading(FadeState state, float fade_time_)
{
Expand Down
4 changes: 4 additions & 0 deletions src/audio/stream_sound_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#pragma once

#include <memory>

#include "audio/openal_sound_source.hpp"

class SoundFile;
Expand All @@ -37,6 +39,8 @@ class StreamSoundSource final : public OpenALSoundSource
virtual void resume() override;
virtual void update() override;
virtual void set_looping(bool looping_) override { m_looping = looping_; }
virtual void set_gain(float gain) override;
virtual void set_volume(float gain) override;

void set_sound_file(std::unique_ptr<SoundFile> newfile);

Expand Down
Loading