mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-04 13:47:04 -04:00
Graphics: Added font rendering functions Graphics::DrawText and Graphics::StringImage.
FileHandler: Added support for wav Audio: Added support to play back a sound with XAudio2. We can't delete sounds until we make our own system to keep track of available voices. LoginScreen scene: Upped framerate from 15fps to tickless, and added new logic to clone the scrolling text at the bottom. All of it.
This commit is contained in:
parent
64a5c0a425
commit
06f13d50ac
14 changed files with 429 additions and 162 deletions
|
@ -16,8 +16,21 @@
|
|||
*/
|
||||
|
||||
#include "windows/xaudio2.hpp"
|
||||
#ifdef PlaySound //defined by the Windows API
|
||||
#undef PlaySound
|
||||
#endif
|
||||
|
||||
struct PlayableSound_t {
|
||||
bool Playing;
|
||||
uint8_t * Data;
|
||||
IXAudio2SourceVoice* pSourceVoice;
|
||||
};
|
||||
|
||||
namespace Audio {
|
||||
int Initialize();
|
||||
PlayableSound_t * LoadSound(const Sound_t * Sound);
|
||||
bool PlaySound(PlayableSound_t * Sound);
|
||||
bool StopSound(PlayableSound_t * Sound);
|
||||
void DeleteSound(PlayableSound_t * Sound);
|
||||
void Shutdown();
|
||||
}
|
|
@ -49,6 +49,65 @@ int Initialize(){
|
|||
return 0;
|
||||
}
|
||||
|
||||
PlayableSound_t * LoadSound(const Sound_t * Sound){
|
||||
const WAVEFORMATEX wfx = {
|
||||
WAVE_FORMAT_PCM, //wFormatTag
|
||||
Sound->Channels, //nChannels
|
||||
Sound->SamplingRate, //nSamplesPerSec
|
||||
((Sound->Channels * Sound->BitDepth) >> 3) * Sound->SamplingRate, //nAvgBytesPerSec
|
||||
((Sound->Channels * Sound->BitDepth) >> 3), //nBlockAlign
|
||||
Sound->BitDepth, //wBitsPerSample;
|
||||
0 //cbSize
|
||||
};
|
||||
|
||||
const XAUDIO2_BUFFER buffer = {
|
||||
0, //Flags
|
||||
Sound->Duration * wfx.nBlockAlign, //AudioBytes
|
||||
Sound->Data, //pAudioData
|
||||
0, //PlayBegin
|
||||
0, //PlayLength
|
||||
0, //LoopBegin
|
||||
0, //LoopLength
|
||||
XAUDIO2_LOOP_INFINITE, //LoopCount
|
||||
NULL, //pContext
|
||||
};
|
||||
|
||||
IXAudio2SourceVoice* pSourceVoice;
|
||||
if(FAILED(pXAudio2->CreateSourceVoice(&pSourceVoice, &wfx)))
|
||||
return NULL;
|
||||
if(FAILED(pSourceVoice->SubmitSourceBuffer(&buffer)))
|
||||
return NULL;
|
||||
|
||||
PlayableSound_t * PlayableSound = (PlayableSound_t*) malloc(sizeof(PlayableSound_t));
|
||||
if(!PlayableSound)
|
||||
return NULL;
|
||||
PlayableSound->pSourceVoice = pSourceVoice;
|
||||
PlayableSound->Playing = false;
|
||||
PlayableSound->Data = Sound->Data;
|
||||
return PlayableSound;
|
||||
}
|
||||
|
||||
bool PlaySound(PlayableSound_t * Sound){
|
||||
if(!Sound->Playing && !FAILED(Sound->pSourceVoice->Start(0))){
|
||||
Sound->Playing = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StopSound(PlayableSound_t * Sound){
|
||||
int success = false;
|
||||
if(Sound->Playing && !FAILED(Sound->pSourceVoice->Stop(0)))
|
||||
success = true;
|
||||
Sound->Playing = false;
|
||||
return success;
|
||||
}
|
||||
|
||||
void DeleteSound(PlayableSound_t * Sound){
|
||||
StopSound(Sound);
|
||||
//Sound->pSourceVoice->Release();
|
||||
}
|
||||
|
||||
void Shutdown(){
|
||||
if(MasterVoice){
|
||||
MasterVoice->DestroyVoice();
|
||||
|
|
|
@ -23,6 +23,7 @@ DECLARE_INTERFACE(IXAudio2Voice);
|
|||
#define XAUDIO2_DEFAULT_SAMPLERATE 0
|
||||
#define XAUDIO2_DEFAULT_FREQ_RATIO 4.0f
|
||||
#define XAUDIO2_DEBUG_ENGINE 0x0001
|
||||
#define XAUDIO2_LOOP_INFINITE 255
|
||||
#define XAUDIO2_VOICE_NOSRC 0x0004
|
||||
|
||||
enum XAUDIO2_DEVICE_ROLE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue