63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
/**
|
|
* @file TestSimpleSinusoid.cpp
|
|
* @brief Play a sinus wave using the Raki engine.
|
|
*/
|
|
|
|
#include "Precompiled.h"
|
|
#include "RakiTests/Initializer/TestInitializer.h"
|
|
#include "RakiEngine/Sounds/SoftwareEngine/StreamSoftwareSound.h"
|
|
#include "RakiEngine/Sources/SineSource.h"
|
|
#include "RakiEngine/System/RakiThread.h"
|
|
#include "RakiEngine/System/RakiDebug.h"
|
|
|
|
#if defined ( RAKI_USING_XAUDIO2 )
|
|
#include "RakiTests/_Win32/CoInitializeInitObject.h"
|
|
#include "RakiEngine/Sounds/_XAudio2/PCMStreamSoundNative.h"
|
|
using StreamSound = raki::PCMStreamSoundNative;
|
|
#else
|
|
using StreamSound = raki::StreamSoftwareSound;
|
|
#endif
|
|
|
|
constexpr uint32_t g_soundChannels = 2; /**< Number of channels to use. */
|
|
|
|
/**
|
|
* Play a sinus sound using a raki sound stream.
|
|
*/
|
|
#if defined ( RAKI_USING_XAUDIO2 )
|
|
int _tmain()
|
|
#else // RAKI_USING_XAUDIO2
|
|
int main()
|
|
#endif // RAKI_USING_XAUDIO2
|
|
{
|
|
#if defined ( RAKI_USING_XAUDIO2 )
|
|
raki::CoInitializeInitObject coInitialize;
|
|
#endif // RAKI_USING_XAUDIO2
|
|
raki::TestInitializer initializer;
|
|
|
|
StreamSound pcmStreamSound(g_soundChannels);
|
|
raki::SineSource source(g_soundChannels);
|
|
raki::SoundParams sourceSoundParams(false, true);
|
|
|
|
source.setFrequency(440.0f);
|
|
bool result = pcmStreamSound.createVoice(&source, sourceSoundParams);
|
|
RAKI_ASSERT(result);
|
|
result = pcmStreamSound.allocateBuffers(8192);
|
|
RAKI_ASSERT(result);
|
|
pcmStreamSound.prepare(&source);
|
|
pcmStreamSound.updateRouting(true);
|
|
pcmStreamSound.start();
|
|
result = pcmStreamSound.isPlaying();
|
|
RAKI_ASSERT(result);
|
|
for (;;)
|
|
{
|
|
raki::Thread::sleep(25);
|
|
pcmStreamSound.update();
|
|
if (!pcmStreamSound.isPlaying())
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
pcmStreamSound.stop();
|
|
return 0;
|
|
}
|
|
|