[DEV] add capacity of example
This commit is contained in:
parent
f2f57d4081
commit
2071cf1c46
@ -7,6 +7,7 @@
|
||||
#include <audio/river/river.h>
|
||||
#include <audio/river/Manager.h>
|
||||
#include <audio/river/Interface.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <etk/etk.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -26,38 +27,66 @@ static const std::string configurationRiver =
|
||||
" }\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
void onDataReceived(const void* _data,
|
||||
const audio::Time& _time,
|
||||
size_t _nbChunk,
|
||||
enum audio::format _format,
|
||||
uint32_t _frequency,
|
||||
const std::vector<audio::channel>& _map) {
|
||||
const std::vector<audio::channel>& _map,
|
||||
etk::FSNode* _outputNode) {
|
||||
if (_format != audio::format_int16) {
|
||||
std::cout << "[ERROR] call wrong type ... (need int16_t)" << std::endl;
|
||||
}
|
||||
const int16_t* data = static_cast<const int16_t*>(_data);
|
||||
int64_t value = 0;
|
||||
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
|
||||
value += std::abs(data[iii]);
|
||||
if (_outputNode->fileIsOpen() == false) {
|
||||
// get the curent power of the signal.
|
||||
const int16_t* data = static_cast<const int16_t*>(_data);
|
||||
int64_t value = 0;
|
||||
for (size_t iii=0; iii<_nbChunk*_map.size(); ++iii) {
|
||||
value += std::abs(data[iii]);
|
||||
}
|
||||
value /= (_nbChunk*_map.size());
|
||||
std::cout << "Get data ... average=" << int32_t(value) << std::endl;
|
||||
} else {
|
||||
// just write data
|
||||
std::cout << "Get data ... chunks=" << _nbChunk << " time=" << _time << std::endl;
|
||||
_outputNode->fileWrite(_data, _map.size()*audio::getFormatBytes(_format), _nbChunk);
|
||||
}
|
||||
value /= (_nbChunk*_map.size());
|
||||
std::cout << "Get data ... average=" << int32_t(value) << std::endl;
|
||||
}
|
||||
|
||||
int main(int _argc, const char **_argv) {
|
||||
// the only one init for etk:
|
||||
etk::init(_argc, _argv);
|
||||
// local parameter:
|
||||
std::string configFile;
|
||||
std::string ioName="microphone";
|
||||
std::string outputFileName = "";
|
||||
for (int32_t iii=0; iii<_argc ; ++iii) {
|
||||
std::string data = _argv[iii];
|
||||
if ( data == "-h"
|
||||
|| data == "--help") {
|
||||
std::cout << "Help : " << std::endl;
|
||||
std::cout << " ./xxx ---" << std::endl;
|
||||
std::cout << " --conf=xxx.json Input/output configuration" << std::endl;
|
||||
std::cout << " --io=xxx name configuration input" << std::endl;
|
||||
std::cout << " --file=yyy.raw File name to store data" << std::endl;
|
||||
exit(0);
|
||||
} else if (etk::start_with(data, "--conf=") == true) {
|
||||
configFile = std::string(data.begin()+7, data.end());
|
||||
std::cout << "Select config: " << configFile << std::endl;
|
||||
} else if (etk::start_with(data, "--io=") == true) {
|
||||
ioName = std::string(data.begin()+5, data.end());
|
||||
std::cout << "Select io: " << ioName << std::endl;
|
||||
} else if (etk::start_with(data, "--file=") == true) {
|
||||
outputFileName = std::string(data.begin()+7, data.end());
|
||||
std::cout << "Select output file name: " << outputFileName << std::endl;
|
||||
}
|
||||
}
|
||||
// initialize river interface
|
||||
audio::river::initString(configurationRiver);
|
||||
if (configFile == "") {
|
||||
audio::river::initString(configurationRiver);
|
||||
} else {
|
||||
audio::river::init(configFile);
|
||||
}
|
||||
// Create the River manager for tha application or part of the application.
|
||||
std11::shared_ptr<audio::river::Manager> manager = audio::river::Manager::create("river_sample_read");
|
||||
// create interface:
|
||||
@ -66,11 +95,17 @@ int main(int _argc, const char **_argv) {
|
||||
interface = manager->createInput(48000,
|
||||
std::vector<audio::channel>(),
|
||||
audio::format_int16,
|
||||
"microphone");
|
||||
ioName);
|
||||
if(interface == nullptr) {
|
||||
std::cout << "nullptr interface" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
etk::FSNode outputNode;
|
||||
// open output file if needed:
|
||||
if (outputFileName != "") {
|
||||
outputNode.setName(outputFileName);
|
||||
outputNode.fileOpenWrite();
|
||||
}
|
||||
// set callback mode ...
|
||||
interface->setInputCallback(std11::bind(&onDataReceived,
|
||||
std11::placeholders::_1,
|
||||
@ -78,7 +113,8 @@ int main(int _argc, const char **_argv) {
|
||||
std11::placeholders::_3,
|
||||
std11::placeholders::_4,
|
||||
std11::placeholders::_5,
|
||||
std11::placeholders::_6));
|
||||
std11::placeholders::_6,
|
||||
&outputNode));
|
||||
// start the stream
|
||||
interface->start();
|
||||
// wait 10 second ...
|
||||
@ -88,6 +124,10 @@ int main(int _argc, const char **_argv) {
|
||||
// remove interface and manager.
|
||||
interface.reset();
|
||||
manager.reset();
|
||||
// close the output file
|
||||
if (outputFileName != "") {
|
||||
outputNode.fileClose();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user