audio-river/test/testVolume.cpp

148 lines
5.3 KiB
C++
Raw Normal View History

2015-03-03 23:17:43 +01:00
/** @file
* @author Edouard DUPIN
* @copyright 2015, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
2015-03-03 23:17:43 +01:00
*/
2017-11-07 13:38:04 +01:00
#include <test-debug/debug.hpp>
#include <audio/river/river.hpp>
#include <audio/river/Manager.hpp>
#include <audio/river/Interface.hpp>
#include <etest/etest.hpp>
#include <etk/etk.hpp>
#include <etk/os/FSNode.hpp>
extern "C" {
#include <math.h>
}
#include <ethread/Thread.hpp>
#include <ethread/tools.hpp>
#include "main.hpp"
2015-03-03 23:17:43 +01:00
namespace river_test_volume {
2017-08-28 00:08:50 +02:00
static const etk::String configurationRiver =
2015-03-13 23:22:17 +01:00
"{\n"
" speaker:{\n"
" io:'output',\n"
" map-on:{\n"
" interface:'auto',\n"
" name:'default',\n"
" },\n"
" frequency:0,\n"
" channel-map:['front-left', 'front-right'],\n"
" type:'auto',\n"
" nb-chunk:1024,\n"
" volume-name:'MASTER'\n"
" }\n"
"}\n";
2015-03-03 23:17:43 +01:00
class testCallbackVolume {
private:
2016-07-19 21:43:58 +02:00
ememory::SharedPtr<audio::river::Manager> m_manager;
ememory::SharedPtr<audio::river::Interface> m_interface;
2015-03-03 23:17:43 +01:00
double m_phase;
public:
2016-07-19 21:43:58 +02:00
testCallbackVolume(ememory::SharedPtr<audio::river::Manager> _manager) :
2015-03-03 23:17:43 +01:00
m_manager(_manager),
m_phase(0) {
//Set stereo output:
2017-08-28 00:08:50 +02:00
etk::Vector<audio::channel> channelMap;
channelMap.pushBack(audio::channel_frontLeft);
channelMap.pushBack(audio::channel_frontRight);
2015-03-03 23:17:43 +01:00
m_interface = m_manager->createOutput(48000,
channelMap,
audio::format_int16,
2015-03-13 23:22:17 +01:00
"speaker");
2018-06-19 22:13:48 +02:00
if(m_interface == null) {
TEST_ERROR("null interface");
return;
}
2015-03-03 23:17:43 +01:00
// set callback mode ...
2017-11-07 13:38:04 +01:00
m_interface->setOutputCallback([=](void* _data,
2017-09-26 15:57:44 +02:00
const audio::Time& _time,
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
const etk::Vector<audio::channel>& _map) {
onDataNeeded(_data, _time, _nbChunk, _format, _frequency, _map);
});
2015-03-03 23:17:43 +01:00
m_interface->addVolumeGroup("MEDIA");
m_interface->addVolumeGroup("FLOW");
}
void onDataNeeded(void* _data,
2015-04-13 21:49:48 +02:00
const audio::Time& _time,
2015-03-03 23:17:43 +01:00
size_t _nbChunk,
enum audio::format _format,
uint32_t _frequency,
2017-08-28 00:08:50 +02:00
const etk::Vector<audio::channel>& _map) {
2015-03-03 23:17:43 +01:00
int16_t* data = static_cast<int16_t*>(_data);
double baseCycle = 2.0*M_PI/(double)48000 * (double)550;
for (int32_t iii=0; iii<_nbChunk; iii++) {
for (int32_t jjj=0; jjj<_map.size(); jjj++) {
data[_map.size()*iii+jjj] = cos(m_phase) * 30000;
}
m_phase += baseCycle;
if (m_phase >= 2*M_PI) {
m_phase -= 2*M_PI;
}
}
}
void run() {
2018-06-19 22:13:48 +02:00
if(m_interface == null) {
TEST_ERROR("null interface");
return;
}
2015-03-03 23:17:43 +01:00
m_interface->start();
2017-09-26 15:57:44 +02:00
ethread::sleepMilliSeconds(1000*(1));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "-3dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "-6dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "-9dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "-12dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "-3dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "3dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "6dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "9dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_interface->setParameter("volume", "FLOW", "0dB");
2015-10-14 21:21:03 +02:00
TEST_INFO(" get volume : " << m_interface->getParameter("volume", "FLOW") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_manager->setVolume("MASTER", -3.0f);
2015-10-14 21:21:03 +02:00
TEST_INFO("get volume MASTER: " << m_manager->getVolume("MASTER") );
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-03-03 23:17:43 +01:00
m_manager->setVolume("MEDIA", -3.0f);
2015-10-14 21:21:03 +02:00
TEST_INFO("get volume MEDIA: " << m_manager->getVolume("MEDIA") );
2017-09-26 15:57:44 +02:00
ethread::sleepMilliSeconds(1000*(1));
2015-03-03 23:17:43 +01:00
m_interface->stop();
}
};
TEST(TestALL, testVolume) {
2015-04-11 09:38:30 +02:00
audio::river::initString(configurationRiver);
2016-07-19 21:43:58 +02:00
ememory::SharedPtr<audio::river::Manager> manager;
2015-04-11 09:38:30 +02:00
manager = audio::river::Manager::create("testApplication");
2016-07-19 21:43:58 +02:00
ememory::SharedPtr<testCallbackVolume> process = ememory::makeShared<testCallbackVolume>(manager);
2015-03-03 23:17:43 +01:00
process->run();
process.reset();
2017-09-14 00:59:21 +02:00
ethread::sleepMilliSeconds((500));
2015-04-11 09:38:30 +02:00
audio::river::unInit();
2015-03-03 23:17:43 +01:00
}
};