JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
SoundPanning.hpp
Go to the documentation of this file.
1// Copyright 2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include <memory>
8#include <vector>
9
10namespace jngl {
11
12class Channel;
13class Sound;
14class SoundFile;
15
45public:
48
51 SoundPanning(const SoundPanning&) = delete;
52 SoundPanning& operator=(const SoundPanning&) = delete;
53 SoundPanning(SoundPanning&&) noexcept;
54
56 SoundPanning& operator=(SoundPanning&&) noexcept;
57
68 void setPanning(float panning);
69
71 void stop();
72
74 bool isPlaying() const;
75
79 void setVolume(float volume);
80
81private:
82 friend class SoundFile;
83 SoundPanning(std::shared_ptr<std::vector<float>> buffer, Channel&, bool loop);
84
86 std::shared_ptr<std::vector<float>> buffer;
87 Channel* channel = nullptr;
88 bool loop = false;
89 float volume = 1.f;
90
92 std::weak_ptr<Sound> sound;
93};
94
95} // namespace jngl
An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects".
Definition Channel.hpp:30
Sound loaded from an OGG or MP3 file.
Definition SoundFile.hpp:34
A sound which can be positioned in the stereo field.
SoundPanning()
Creates an empty object on which all methods do nothing.
bool isPlaying() const
Whether the sound has been started (using setPanning) and is still playing.
void setPanning(float panning)
Set the stereo position, the first call starts playing the sound.
void setVolume(float volume)
Set volume in [0, ∞].
~SoundPanning()
Stops the sound.
void stop()
Stops the sound. If it hasn't been started yet, it won't start anymore.
JNGL's main namespace.