coastline 0.0.4
Loading...
Searching...
No Matches
sdlmixer.h
Go to the documentation of this file.
1#ifndef COASTLINE_EAR_SDLMIXER_H
2#define COASTLINE_EAR_SDLMIXER_H
3
4#include <cstdint>
5
6#include "ear/wavechunks.h"
7
9inline constexpr int EAR_MIX_RATE = 22050;
11inline constexpr int EAR_MIX_CHANNELS = 2;
12
18class EarSdlVoice {
19public:
27 static EarSdlVoice *Create(const EarWaveFormat &format, std::uint32_t bytes);
28
30 void Release();
31
39 void Write(std::uint32_t offset, const void *data, std::uint32_t bytes);
40
46 void Play(bool looping);
47
49 void Stop();
50
52 bool IsPlaying() const;
53
56
64
71 void SetFrequency(std::uint32_t frequency);
72
79 void SetVolume(LONG volume);
80
87 void SetPan(LONG pan);
88
95 void MixInto(float *mix, int frames);
96
97private:
98 EarSdlVoice() = default;
99 float ReadSample(std::uint32_t frame, int channel) const;
100 void UpdateGains();
101
102 EarWaveFormat format = {};
103 std::uint8_t *samples = nullptr;
104 std::uint32_t bytes = 0;
105 std::uint32_t frames = 0;
106 std::uint64_t position = 0;
107 std::uint32_t frequency = 0;
108 LONG volume = 0;
109 LONG pan = 0;
110 float leftGain = 1;
111 float rightGain = 1;
112 bool playing = false;
113 bool looping = false;
114};
115
122void EarSetSdlMixerOffline(bool offline);
123
130
133
138void EarSetSdlMixerEnabled(bool enabled);
141
148void EarRenderSdlMixer(std::int16_t *samples, int frames);
149
150#endif /* COASTLINE_EAR_SDLMIXER_H */
std::uint32_t GetPlayCursor() const
void Release()
Remove the buffer from the mix and delete it.
bool IsPlaying() const
void SetFrequency(std::uint32_t frequency)
Change playback frequency when the requested rate is within the device-compatible range.
void SetVolume(LONG volume)
Change volume when the requested attenuation is within the device-compatible range.
void Write(std::uint32_t offset, const void *data, std::uint32_t bytes)
Copy samples into the buffer, continuing at its start past its end.
void Stop()
Stop the buffer, leaving its play cursor where it is.
void Play(bool looping)
Start the buffer from its play cursor.
void MixInto(float *mix, int frames)
Add the frames the buffer plays next to a mix.
void SetPan(LONG pan)
Change stereo pan within the device-compatible range; out-of-range requests are ignored.
static EarSdlVoice * Create(const EarWaveFormat &format, std::uint32_t bytes)
Create a silent, stopped buffer and add it to the mix.
bool SetPlayCursor(std::uint32_t offset)
Move the play cursor.
constexpr int EAR_MIX_RATE
The frames a second EAR mixes at, the format it gives the primary buffer of DirectSound.
Definition sdlmixer.h:9
void EarSetSdlMixerEnabled(bool enabled)
Enable or suspend sound-effect mixing and playback updates without discarding voices.
bool EarSdlMixerEnabled()
void EarSetSdlMixerOffline(bool offline)
Select whether the mixer renders on request, through EarRenderSdlMixer(), rather than to the default ...
void EarRenderSdlMixer(std::int16_t *samples, int frames)
Mix frames of a mixer that renders on request, and advance its clock by their time.
void EarCloseSdlMixer()
Close the mixer and its device, and delete every buffer.
constexpr int EAR_MIX_CHANNELS
The channels EAR mixes, the format it gives the primary buffer of DirectSound.
Definition sdlmixer.h:11
bool EarOpenSdlMixer()
Open the mixer, and the default playback device unless it renders on request.
WAVEFORMATEX EarWaveFormat
Definition wavechunks.h:23
typedef LONG