From d289bf3134d2194b47b3a8ca5a7ed123c91148b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20S=C5=82omkowski?= Date: Wed, 28 Oct 2015 00:19:42 +0100 Subject: [PATCH] Change example to be simple echo. --- mumlib_example.cpp | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/mumlib_example.cpp b/mumlib_example.cpp index cd80212..85025cd 100644 --- a/mumlib_example.cpp +++ b/mumlib_example.cpp @@ -4,27 +4,14 @@ #include "log4cpp/FileAppender.hh" #include "log4cpp/OstreamAppender.hh" -#include -#include -#include +class MyCallback : public mumlib::BasicCallback { +public: + mumlib::Mumlib *mum; -void audioSenderThreadFunction(mumlib::Mumlib *mum) { - while (mum->getConnectionState() != mumlib::ConnectionState::FAILED) { - if (mum->getConnectionState() == mumlib::ConnectionState::CONNECTED) { - constexpr double FREQUENCY = 1000; // Hz - constexpr int BUFF_SIZE = mumlib::SAMPLE_RATE / 100; // 10 ms - int16_t buff[BUFF_SIZE]; - - for (int i = 0; i < BUFF_SIZE; ++i) { - buff[i] = 10000 * std::sin(2.0 * M_PI * FREQUENCY * ((double) i) / ((double) mumlib::SAMPLE_RATE)); - } - - mum->sendAudioData(buff, BUFF_SIZE); - } - - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + virtual void audio(int16_t *pcm_data, uint32_t pcm_data_size) { + mum->sendAudioData(pcm_data, pcm_data_size); } -} +}; int main(int argc, char *argv[]) { @@ -39,13 +26,12 @@ int main(int argc, char *argv[]) { return 1; } - mumlib::BasicCallback callback; - mumlib::Mumlib mum(callback); + MyCallback myCallback; + mumlib::Mumlib mum(myCallback); + myCallback.mum = &mum; mum.connect(argv[1], 64738, "mumlib_example", argv[2]); - std::thread audioSenderThread(audioSenderThreadFunction, &mum); - mum.run(); return 0;