M2-PT-DRP/source/main.cpp

35 lines
844 B
C++

#include <mpg123.h>
#include <portaudio.h>
#include <stdexcept>
#include <thread>
#include "Client.hpp"
#include "Server.hpp"
int main(int argc, char* argv[]) {
// initialize the mpg123 library
if (mpg123_init() != MPG123_OK)
throw std::runtime_error("Error while initializing mpg123.");
// initialize the PortAudio library
if (Pa_Initialize() != paNoError)
throw std::runtime_error("Could not initialize PortAudio.");
// start the client and server
Server server;
Client client (
server.getChannels(),
static_cast<double>(server.getRate())
);
std::thread serverThread(&Server::loop, server);
std::thread clientThread(&Client::loop, client);
serverThread.join();
clientThread.join();
// terminate the libraries
Pa_Terminate();
mpg123_exit();
}