libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
AudioPlayer.h
Go to the documentation of this file.
1#pragma once
2#include "stdint.h"
3#include "stddef.h"
4#include <string>
5#include <memory>
8
9namespace Ship {
10
15 int32_t SampleRate = 44100;
16 int32_t SampleLength = 1024;
17 int32_t DesiredBuffered = 2480;
19 AudioChannelsSetting::audioStereo;
20};
21
33
34 public:
39 AudioPlayer(AudioSettings settings) : mAudioSettings(settings) {
40 }
42
47 bool Init();
48
55 virtual int32_t Buffered() = 0;
56
69 void Play(const uint8_t* buf, size_t len);
70
73
75 int32_t GetSampleRate() const;
76
78 int32_t GetSampleLength() const;
79
81 int32_t GetDesiredBuffered() const;
82
85
90 void SetSampleRate(int32_t rate);
91
96 void SetSampleLength(int32_t length);
97
102 void SetDesiredBuffered(int32_t size);
103
114
119 int32_t GetNumOutputChannels() const;
120
121 protected:
129 virtual bool DoInit() = 0;
130
136 virtual void DoClose() = 0;
137
146 virtual void DoPlay(const uint8_t* buf, size_t len) = 0;
147
148 private:
149 std::unique_ptr<SoundMatrixDecoder>
150 mSoundMatrixDecoder;
151
152 AudioSettings mAudioSettings;
153 bool mInitialized = false;
154};
155} // namespace Ship
156
157#ifdef _WIN32
158#include "WasapiAudioPlayer.h"
159#endif
160
161#ifdef __APPLE__
162#include "CoreAudioAudioPlayer.h"
163#endif
164
165#include "SDLAudioPlayer.h"
166#include "NullAudioPlayer.h"
AudioChannelsSetting
Selects the number and arrangement of output audio channels.
Definition AudioChannelsSetting.h:9
Abstract base class for platform-specific audio output backends.
Definition AudioPlayer.h:32
void Play(const uint8_t *buf, size_t len)
Submits a frame of PCM audio to the output device.
int32_t GetSampleLength() const
Returns the configured number of samples per audio frame.
bool SetAudioChannels(AudioChannelsSetting channels)
Changes the channel mode and reinitialises the audio device.
virtual void DoClose()=0
Closes the platform audio device and releases its resources.
void SetDesiredBuffered(int32_t size)
Sets the target number of buffered frames.
int32_t GetSampleRate() const
Returns the configured output sample rate in Hz.
int32_t GetDesiredBuffered() const
Returns the target number of frames to keep buffered.
virtual void DoPlay(const uint8_t *buf, size_t len)=0
Writes interleaved PCM samples to the platform audio device.
bool IsInitialized()
Returns true if Init() has been called and succeeded.
virtual bool DoInit()=0
Opens and configures the platform audio device.
AudioChannelsSetting GetAudioChannels() const
Returns the current channel-output mode.
int32_t GetNumOutputChannels() const
Returns the number of output channels implied by the current channel setting.
void SetSampleLength(int32_t length)
Sets the number of samples per audio frame.
bool Init()
Calls DoInit() and sets the initialised flag on success.
virtual int32_t Buffered()=0
Returns the number of audio frames currently queued in the device buffer.
void SetSampleRate(int32_t rate)
Sets the output sample rate.
AudioPlayer(AudioSettings settings)
Constructs an AudioPlayer with the given configuration.
Definition AudioPlayer.h:39
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
Configuration parameters shared by all AudioPlayer backends.
Definition AudioPlayer.h:14
int32_t SampleLength
Number of samples per audio frame.
Definition AudioPlayer.h:16
AudioChannelsSetting ChannelSetting
Channel mode (stereo / 5.1 matrix / 5.1 raw).
Definition AudioPlayer.h:18
int32_t DesiredBuffered
Target number of frames to keep buffered.
Definition AudioPlayer.h:17
int32_t SampleRate
Output sample rate in Hz.
Definition AudioPlayer.h:15