stuff-from-scratch/test/audio/TestAudioWriter.cpp

63 lines
1.3 KiB
C++
Raw Normal View History

2021-05-23 20:02:38 +00:00
#include "AudioSample.h"
#include "AudioSynth.h"
#include "AudioWriter.h"
2021-10-31 13:04:48 +00:00
#include "WasapiInterface.h"
2021-05-23 20:02:38 +00:00
#include "TestCase.h"
#include "TestCaseRunner.h"
#include <memory>
#include <string>
2022-01-01 18:46:31 +00:00
#ifdef _WIN32
2021-10-31 13:04:48 +00:00
#include <windows.h>
2022-01-01 18:46:31 +00:00
#endif
2021-10-31 13:04:48 +00:00
#include <iostream>
2021-05-23 20:02:38 +00:00
class TestWriteWav : public TestCase
{
public:
bool Run() override
{
AudioWriter writer;
writer.SetPath("test.wav");
AudioSynth synth;
auto sample = synth.GetSineWave(240, 5);
writer.Write(sample);
return true;
}
};
2021-10-31 13:04:48 +00:00
class TestAudioRender : public TestCase
{
public:
bool Run() override
{
2022-01-01 18:46:31 +00:00
#ifdef _WIN32
2021-10-31 13:04:48 +00:00
WasapiInterface audio_interface;
auto device = AudioDevice::Create();
audio_interface.Play(device);
2022-01-01 18:46:31 +00:00
#endif
2021-10-31 13:04:48 +00:00
return true;
}
};
//int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
2021-05-23 20:02:38 +00:00
int main()
{
2022-01-01 18:46:31 +00:00
#ifdef _WIN32
2021-10-31 13:04:48 +00:00
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
2022-01-01 18:46:31 +00:00
#endif
2021-10-31 13:04:48 +00:00
std::cout << "into entry point" << std::endl;
2021-05-23 20:02:38 +00:00
TestCaseRunner runner;
2022-05-15 13:58:31 +00:00
runner.AddTestCase("TestWriteNav", std::make_unique<TestWriteWav>());
2021-10-31 13:04:48 +00:00
runner.AddTestCase("TestAudioRender", std::make_unique<TestAudioRender>());
2021-05-23 20:02:38 +00:00
const auto testsPassed = runner.Run();
return testsPassed ? 0 : -1;
2022-01-01 18:46:31 +00:00
#ifdef _WIN32
2021-10-31 13:04:48 +00:00
CoUninitialize();
2022-01-01 18:46:31 +00:00
#endif
2021-05-23 20:02:38 +00:00
}