MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / SOUND

Class SOUND

extensions/olcPGEX_Sound.h:127–214  ·  view source on GitHub ↗

Container class for Advanced 2D Drawing functions

Source from the content-addressed store, hash-verified

125{
126 // Container class for Advanced 2D Drawing functions
127 class SOUND : public olc::PGEX
128 {
129 // A representation of an affine transform, used to rotate, scale, offset & shear space
130 public:
131 class AudioSample
132 {
133 public:
134 AudioSample();
135 AudioSample(std::string sWavFile, olc::ResourcePack *pack = nullptr);
136 olc::rcode LoadFromFile(std::string sWavFile, olc::ResourcePack *pack = nullptr);
137
138 public:
139 OLC_WAVEFORMATEX wavHeader;
140 float *fSample = nullptr;
141 long nSamples = 0;
142 int nChannels = 0;
143 bool bSampleValid = false;
144 };
145
146 struct sCurrentlyPlayingSample
147 {
148 int nAudioSampleID = 0;
149 long nSamplePosition = 0;
150 bool bFinished = false;
151 bool bLoop = false;
152 bool bFlagForStop = false;
153 };
154
155 static std::list<sCurrentlyPlayingSample> listActiveSamples;
156
157 public:
158 static bool InitialiseAudio(unsigned int nSampleRate = 44100, unsigned int nChannels = 1, unsigned int nBlocks = 8, unsigned int nBlockSamples = 512);
159 static bool DestroyAudio();
160 static void SetUserSynthFunction(std::function<float(int, float, float)> func);
161 static void SetUserFilterFunction(std::function<float(int, float, float)> func);
162
163 public:
164 static int LoadAudioSample(std::string sWavFile, olc::ResourcePack *pack = nullptr);
165 static void PlaySample(int id, bool bLoop = false);
166 static void StopSample(int id);
167 static void StopAll();
168 static float GetMixerOutput(int nChannel, float fGlobalTime, float fTimeStep);
169
170
171 private:
172#ifdef USE_WINDOWS // Windows specific sound management
173 static void CALLBACK waveOutProc(HWAVEOUT hWaveOut, UINT uMsg, DWORD dwParam1, DWORD dwParam2);
174 static unsigned int m_nSampleRate;
175 static unsigned int m_nChannels;
176 static unsigned int m_nBlockCount;
177 static unsigned int m_nBlockSamples;
178 static unsigned int m_nBlockCurrent;
179 static short* m_pBlockMemory;
180 static WAVEHDR *m_pWaveHeaders;
181 static HWAVEOUT m_hwDevice;
182 static std::atomic<unsigned int> m_nBlockFree;
183 static std::condition_variable m_cvBlockNotZero;
184 static std::mutex m_muxBlockNotZero;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected