1 /* bzflag 2 * Copyright (c) 1993-2021 Tim Riker 3 * 4 * This package is free software; you can redistribute it and/or 5 * modify it under the terms of the license found in the file 6 * named COPYING that should have accompanied this file. 7 * 8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11 */ 12 13 /* WinMedia: 14 * Media I/O on MS Windows. 15 */ 16 17 #ifndef BZF_WINMEDIA_H 18 #define BZF_WINMEDIA_H 19 20 #include "BzfMedia.h" 21 #include <dsound.h> 22 23 class WinWindow; 24 25 class WinMedia : public BzfMedia 26 { 27 public: 28 WinMedia(); 29 ~WinMedia(); 30 31 bool openAudio(); 32 void closeAudio(); 33 bool startAudioThread(void (*)(void*), void*); 34 void stopAudioThread(); 35 bool hasAudioThread() const; 36 void writeSoundCommand(const void*, int); 37 bool readSoundCommand(void*, int); 38 int getAudioOutputRate() const; 39 int getAudioBufferSize() const; 40 int getAudioBufferChunkSize() const; 41 bool isAudioTooEmpty() const; 42 void writeAudioFrames(const float* samples, int numFrames); 43 void audioSleep(bool checkLowWater, double maxTime); 44 45 private: 46 static DWORD WINAPI audioThreadInit(void*); 47 48 private: 49 bool audioReady; 50 bool audioPlaying; 51 IDirectSound* audioInterface; 52 IDirectSoundBuffer* audioPrimaryPort; 53 IDirectSoundBuffer* audioPort; 54 int audioNumChannels; 55 int audioOutputRate; 56 int audioBufferSize; 57 int audioBufferChunkSize; 58 int audioLowWaterMark; 59 int audioBytesPerSample; 60 int audioBytesPerFrame; 61 int audioWritePtr; 62 short* outputBuffer; 63 unsigned char* audioCommandBuffer; 64 int audioCommandBufferLen; 65 int audioCommandBufferHead; 66 int audioCommandBufferTail; 67 HANDLE audioCommandEvent; 68 HANDLE audioCommandMutex; 69 HANDLE audioThread; 70 static void (*threadProc)(void*); 71 static void* threadData; 72 }; 73 74 #endif // BZF_WINMEDIA_H 75 76 // Local Variables: *** 77 // mode: C++ *** 78 // tab-width: 4 *** 79 // c-basic-offset: 4 *** 80 // indent-tabs-mode: nil *** 81 // End: *** 82 // ex: shiftwidth=4 tabstop=4 83