coastline 0.0.4
Loading...
Searching...
No Matches
playbackimplementations.h
Go to the documentation of this file.
1#ifndef COASTLINE_EAR_PLAYBACKIMPLEMENTATIONS_H
2#define COASTLINE_EAR_PLAYBACKIMPLEMENTATIONS_H
3
4#if TGR_PLATFORM == TGR_PLATFORM_WIN
5#include <windows.h>
6// Multimedia declarations require the core Windows SDK types first.
7#include <mmreg.h>
8#include <mmsystem.h>
9#endif
10
11#include "ear/earplayback.h"
12#include "ear/wavechunks.h"
13
18class [[gnu::packed]] PcmWaveStream : public EarPlayback {
19public:
26
27private:
29 void ReleaseEarPlaybackResources() override;
31 int InitializeEarPlayback(const void *source, int streaming, int looping) override;
32
33protected:
42
43private:
44protected:
51
52private:
54 void RefillEarPlaybackStream() override;
55
56protected:
64
65private:
67 void CompleteEarPlayback() override;
68
69protected:
76
77private:
80
82 int OpenWaveFileStream(const char *path);
84 int PreparePcmWaveStream(const void *source);
85
86 void CloseWaveFileStream();
87 int FailPcmWavePreparation(std::uint32_t error);
88
89protected:
95
104};
105
107class [[gnu::packed]] MemoryWaveStream : public PcmWaveStream {
108public:
114
115private:
117 void ReleaseEarPlaybackResources() override;
119 int InitializeEarPlayback(const void *source, int streaming, int looping) override;
121 void CloseRegisteredEarPlayback() override;
122
130 int OpenMemoryWaveStream(const void *source);
131};
132
134class [[gnu::packed]] SampleWavePlayback : public PcmWaveStream {
135public:
141
142private:
144 void ReleaseEarPlaybackResources() override;
146 int InitializeEarPlayback(const void *source, int streaming, int looping) override;
148 void CloseRegisteredEarPlayback() override;
150 void ApplyPreset(EarWaveSample *preset) override;
151};
152
153#if TGR_PLATFORM == TGR_PLATFORM_WIN
158class [[gnu::packed]] MidiPlayback : public EarPlayback {
159public:
165
180 double gain,
181 std::uint16_t matrix) override;
192 int InitializeEarPlayback(const void *source, int streaming, int looping) override;
198 int StartEarPlayback() override;
204 int PauseEarPlayback() override;
210 int ResumeEarPlayback() override;
216 void SetEarPlaybackMute(int muted) override;
225
226protected:
233
234private:
235 // The native slots share the empty folded body of CObject::AssertValid.
236 void UpdateDirectSoundPlaybackGainAndPan() override;
237 void UpdateDirectSoundPlaybackFrequency() override;
238
239 MCI_PLAY_PARMS playParameters;
240 MCI_PLAY_PARMS resumeParameters;
241 DWORD lengthMilliseconds;
242 char *path;
243 int ownsTemporaryFile;
244 double pendingGain;
245};
246
251class [[gnu::packed]] CdAudioPlayback : public EarPlayback {
252public:
258
272 double gain,
273 std::uint16_t matrix) override;
282 int InitializeEarPlayback(const void *source, int streaming, int looping) override;
290 int StartEarPlayback() override;
296 int PauseEarPlayback() override;
302 int ResumeEarPlayback() override;
313 void SetEarPlaybackMute(int muted) override;
321
322protected:
329
330private:
331 // The native slots share the empty folded body of CObject::AssertValid.
332 void UpdateDirectSoundPlaybackGainAndPan() override;
333 void UpdateDirectSoundPlaybackFrequency() override;
334
335 MCI_PLAY_PARMS playParameters;
336 MCI_PLAY_PARMS resumeParameters;
337 int wholeDisc;
338 DWORD durationMilliseconds;
339};
340#endif
341
347
349class [[gnu::packed]] ImaAdpcmWaveStream : public PcmWaveStream {
350public:
357
358private:
360 void ReleaseEarPlaybackResources() override;
362 int InitializeEarPlayback(const void *source, int streaming, int looping) override;
364 void CloseRegisteredEarPlayback() override;
366 void RefillEarPlaybackStream() override;
368 void CompleteEarPlayback() override;
376
385 int OpenImaAdpcmWaveStream(const void *source);
386
393 void DecodeImaAdpcmStreamBlocks();
394
395 EarImaAdpcmWaveFormat adpcmFormat;
396 std::uint8_t *blockBuffer;
397 DWORD adpcmDataBytes;
398 DWORD blockBufferBytes;
399 DWORD blockHalfBytes;
400 int decodedSample;
401 int decodedDifference;
402 std::uint8_t decodedNibble;
403 ImaAdpcmChannelState *channelStates;
404 std::uint16_t blocksPerHalf;
405 DWORD dataWordsPerBlock;
406 int memorySource;
407};
408
416inline std::uint32_t TruncatePlaybackInteger(long double value) {
417 // Invalid x87 integer conversions produce zero in the low 32 bits.
418 return value >= -0x1p63L && value < 0x1p63L ?
419 static_cast<std::uint32_t>(static_cast<std::int64_t>(value)) :
420 0;
421}
422
423#endif /* COASTLINE_EAR_PLAYBACKIMPLEMENTATIONS_H */
int InitializeEarPlayback(const void *source, int streaming, int looping) override
Configure a track range from the loaded CD positions without starting playback.
void ReleaseEarPlaybackResources() override
Release playback through the registered-closure operation without closing the shared device.
int IsBufferedEarPlaybackComplete() override
Query MCI stop state while active and restart a completed looping range.
void SetEarPlaybackMute(int muted) override
Store mute state and write the shared Windows CD mixer's mute control.
int ResumeEarPlayback() override
Resume an active paused range from the cached position and clear pause status on success.
int PauseEarPlayback() override
Pause CD playback and cache its position for a later resume when pausing succeeds.
CdAudioPlayback()
Initialise single-track mode with zero duration; media initialisation sets command ranges.
int StartEarPlayback() override
Apply specified start and end overrides, post an enabled start message, and play the range.
void CloseRegisteredEarPlayback() override
Stop CD playback, post an enabled end message, clear mute, restore full gain, and unregister.
void SetEarPlaybackDirectionalGain(std::uint16_t direction, double gain, std::uint16_t matrix) override
Write the shared CD mixer volume control immediately.
std::uint32_t GetEarPlaybackMediaLength() override
virtual std::uint32_t GetEarPlaybackMediaLength()
int looping
Nonzero while looping is requested.
Definition earplayback.h:493
int streaming
Nonzero while media requires half-buffer refills.
Definition earplayback.h:495
virtual int InitializeEarPlayback(const void *source, int streaming, int looping)
Initialise implementation-specific media; the base implementation does not change state.
virtual void ReleaseEarPlaybackResources()
Release registered playback through the virtual closure hook.
virtual void CompleteEarPlayback()
Perform implementation-specific completion; the base implementation does not change state.
virtual void ApplyPreset(EarWaveSample *preset)
Apply implementation-specific preset data; the base implementation ignores the request.
virtual void CloseRegisteredEarPlayback()
Stop and release a registered buffer, post an enabled closure notification, and unregister playback.
int muted
Nonzero when muted; cached gain remains available for unmuting.
Definition earplayback.h:503
EarPlayback()
Initialise inactive playback and smoothing defaults without allocating media or a buffer.
A wave file loaded whole into memory, which a preset registers and sample playbacks share.
Definition wavesample.h:15
ImaAdpcmWaveStream()
Initialise inherited stream state and empty ADPCM decoder and block-buffer state.
MemoryWaveStream()
Initialise inherited stream state without allocating or attaching a memory image.
int ResumeEarPlayback() override
Attempt to resume an active paused sequencer and clear paused status on success.
int PauseEarPlayback() override
Set paused status and pause the sequencer when active.
void SetEarPlaybackDirectionalGain(std::uint16_t direction, double gain, std::uint16_t matrix) override
Set shared MIDI mixer volume when active, or cache gain for the next start when inactive.
int StartEarPlayback() override
Seek to a specified fractional start, post an enabled notification, and play the sequence.
int InitializeEarPlayback(const void *source, int streaming, int looping) override
Open source media in the shared sequencer and query sequence length.
void CloseRegisteredEarPlayback() override
Request zero gain, record shared sequencer use, post an enabled end message, and unregister.
void SetEarPlaybackMute(int muted) override
Store mute state and write the shared Windows MIDI mixer's mute control.
void ReleaseEarPlaybackResources() override
Unregister playback and delete any temporary MIDI file and allocated temporary path.
int IsBufferedEarPlaybackComplete() override
Query MCI stop state unless inactive or a shared completion query is already in progress.
MidiPlayback()
Initialise empty media state; a gain adjustment must assign pendingGain before playback.
LONG originalFileOffset
Definition playbackimplementations.h:99
DWORD writeOffset
Definition playbackimplementations.h:103
DWORD dataBytes
Definition playbackimplementations.h:101
EarWaveFile file
Definition playbackimplementations.h:96
void CopyEarPlaybackSamplesToOutput() override
Copy the sample half opposite the refill index into the corresponding device-buffer half.
char * sampleBuffer
Definition playbackimplementations.h:100
LONG dataStartOffset
Definition playbackimplementations.h:98
int CheckEarPlaybackLoopCompletion() override
Drain a completed stream by copying its first trailing half and stopping on later checks.
std::uint16_t AllocateEarEventId() override
Create and fill the device buffer, apply initial frequency, and seek when requested.
int CheckWavePlaybackDeviceAccess()
EarWaveFormat format
Definition playbackimplementations.h:102
PcmWaveStream()
Initialise null file and sample references with zero read and write counters.
void CloseRegisteredEarPlayback() override
Release registered playback, close or restore the source file, and free sample storage.
DWORD readOffset
Definition playbackimplementations.h:97
SampleWavePlayback()
Initialise inherited stream state without attaching a preset.
std::uint32_t TruncatePlaybackInteger(long double value)
Convert a value to an integer as the x87 instruction of the original does, retaining the low 32 bits.
Definition playbackimplementations.h:416
The state of the decoder of one channel of IMA ADPCM, from the header of each block.
Definition playbackimplementations.h:343
std::int16_t stepIndex
Definition playbackimplementations.h:345
std::int16_t predictor
Definition playbackimplementations.h:344
WAVEFORMATEX EarWaveFormat
Definition wavechunks.h:23
IMAADPCMWAVEFORMAT EarImaAdpcmWaveFormat
Definition wavechunks.h:24
HMMIO EarWaveFile
Definition wavechunks.h:25
typedef DWORD
typedef LONG