209 lines
38 KiB
HTML
209 lines
38 KiB
HTML
<!-- HTML header for doxygen 1.8.8-->
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<!-- For Mobile Devices -->
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta name="generator" content="Doxygen 1.8.12"/>
|
|
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
|
<title>audio-river: Multi-nodal audio interface: Read stream form Audio input</title>
|
|
<!--<link href="tabs.css" rel="stylesheet" type="text/css"/>-->
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
|
|
<script type="text/javascript" src="doxy-boot.js"></script>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
|
|
<div class="container">
|
|
<div class="navbar-header">
|
|
<a class="navbar-brand">audio-river: Multi-nodal audio interface 0.4.0</a>
|
|
</div>
|
|
<div id="navbar" class="navbar-collapse collapse">
|
|
<ul class="nav navbar-nav">
|
|
<li><a href="index.html">Main Page</a></li>
|
|
<li><a href="pages.html">Related Pages</a></li>
|
|
<li><a href="namespaces.html">Namespaces</a></li>
|
|
<li><a href="annotated.html">Classes</a></li>
|
|
<li><a href="files.html">Files</a></li>
|
|
</ul>
|
|
<ul class="nav navbar-nav navbar-right">
|
|
<li class="dropdown">
|
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
|
|
Link-libs<span class="caret"></span>
|
|
</a>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="http://HeeroYui.github.io/lutin">lutin</a></li>
|
|
<li><a href="http://atria-soft.github.io/ewol">ewol</a></li>
|
|
<li><a href="http://atria-soft.github.io/echrono">echrono</a></li>
|
|
<li><a href="http://atria-soft.github.io/etk">etk</a></li>
|
|
<li><a href="http://atria-soft.github.io/ejson">ejson</a></li>
|
|
<li><a href="http://atria-soft.github.io/exml">exml</a></li>
|
|
<li><a href="http://atria-soft.github.io/esvg">esvg</a></li>
|
|
<li><a href="http://atria-soft.github.io/egami">egami</a></li>
|
|
<li><a href="http://atria-soft.github.io/gale">gale</a></li>
|
|
<li><a href="http://atria-soft.github.io/ege">ege</a></li>
|
|
<li><a href="http://atria-soft.github.io/elog">elog</a></li>
|
|
<li><a href="http://atria-soft.github.io/ememory">ememory</a></li>
|
|
<li><a href="http://atria-soft.github.io/enet">enet</a></li>
|
|
<li><a href="http://atria-soft.github.io/eproperty">eproperty</a></li>
|
|
<li><a href="http://atria-soft.github.io/esignal">esignal</a></li>
|
|
<li><a href="http://atria-soft.github.io/etranslate">etranslate</a></li>
|
|
<li><a href="http://atria-soft.github.io/zeus">zeus</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-ess">audio-ess</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio">audio</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-drain">audio-drain</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-orchestra">audio-orchestra</a></li>
|
|
<li><a href="http://musicdsp.github.io/audio-river">audio-river</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<div id="search-box" class="input-group">
|
|
<div class="input-group-btn">
|
|
<button aria-expanded="false" type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
|
|
<span class="glyphicon glyphicon-search"></span>
|
|
<span class="caret"></span>
|
|
</button>
|
|
<ul class="dropdown-menu">
|
|
<li><a href="#">All</a></li>
|
|
<li><a href="#">Classes</a></li>
|
|
<li><a href="#">Namespaces</a></li>
|
|
<li><a href="#">Files</a></li>
|
|
<li><a href="#">Functions</a></li>
|
|
<li><a href="#">Variables</a></li>
|
|
<li><a href="#">Typedefs</a></li>
|
|
<li><a href="#">Enumerations</a></li>
|
|
<li><a href="#">Enumerator</a></li>
|
|
<li><a href="#">Friends</a></li>
|
|
<li><a href="#">Macros</a></li>
|
|
<li><a href="#">Pages</a></li>
|
|
</ul>
|
|
</div>
|
|
<button id="search-close" type="button" class="close" aria-label="Close">
|
|
<span aria-hidden="true"></span>
|
|
</button>
|
|
<input id="search-field" class="form-control" accesskey="S" onkeydown="searchBox.OnSearchFieldChange(event);" placeholder="Search ..." type="text">
|
|
</div>
|
|
</div><!--/.nav-collapse -->
|
|
</div>
|
|
</nav>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div class="content" id="content">
|
|
<div class="container">
|
|
<div class="row">
|
|
<div class="col-sm-12 panel panel-default" style="padding-bottom: 15px;">
|
|
<div style="margin-bottom: 15px;margin-top: 60px;">
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.12 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Read stream form Audio input </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="toc"><h3>Table of Contents</h3>
|
|
<ul><li class="level1"><a href="#audio_river_read_objectif">Objectifs: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_include">Include: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_init">Initilize the River library: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_river_interface">Get the river interface manager: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_river_read_interface">Create your read interface: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_get_data">set data callback: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_callback">Callback inplementation: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_start_stop">start and stop the stream: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_reset">Remove interfaces: </a></li>
|
|
<li class="level1"><a href="#audio_river_read_full_sample">Full Sample: </a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="textblock"><h1><a class="anchor" id="audio_river_read_objectif"></a>
|
|
Objectifs: </h1>
|
|
<ul>
|
|
<li>Understand basis of river</li>
|
|
<li>Create a simple recording interface that print the average of sample absolute value.</li>
|
|
</ul>
|
|
<p>When you will create an application based on the river audio interface you need :</p>
|
|
<h1><a class="anchor" id="audio_river_read_include"></a>
|
|
Include: </h1>
|
|
<p>Include manager and interface node </p><div class="fragment"><div class="line"><span class="preprocessor">#include <audio/river/river.hpp></span></div><div class="line"><span class="preprocessor">#include <audio/river/Manager.hpp></span></div><div class="line"><span class="preprocessor">#include <audio/river/Interface.hpp></span></div></div><!-- fragment --> <h1><a class="anchor" id="audio_river_read_init"></a>
|
|
Initilize the River library: </h1>
|
|
<p>We first need to initialize etk sub library (needed to select the log level of sub-libraries and file access abstraction </p><div class="fragment"><div class="line"> <span class="comment">// the only one init for etk:</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk.html#aa87d94d7a27bd41c9982fe0ba83d6f88">etk::init</a>(_argc, _argv);</div></div><!-- fragment --><p> Now we will initilaize the river library. To do this We have 2 posibilities: </p><h2>With a file: </h2>
|
|
<div class="fragment"><div class="line"><span class="comment">// initialize river interface</span></div><div class="line">river::init(<span class="stringliteral">"DATA:configFileName.json"</span>);</div></div><!-- fragment --><h2>With a json string: </h2>
|
|
<div class="fragment"><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> std::string configurationRiver =</div><div class="line"> <span class="stringliteral">"{\n"</span></div><div class="line"> <span class="stringliteral">" microphone:{\n"</span></div><div class="line"> <span class="stringliteral">" io:'input',\n"</span></div><div class="line"> <span class="stringliteral">" map-on:{\n"</span></div><div class="line"> <span class="stringliteral">" interface:'auto',\n"</span></div><div class="line"> <span class="stringliteral">" name:'default',\n"</span></div><div class="line"> <span class="comment">//" timestamp-mode:'trigered',\n"</span></div><div class="line"> <span class="stringliteral">" },\n"</span></div><div class="line"> <span class="stringliteral">" frequency:0,\n"</span></div><div class="line"> <span class="stringliteral">" channel-map:['front-left', 'front-right'],\n"</span></div><div class="line"> <span class="stringliteral">" type:'auto',\n"</span></div><div class="line"> <span class="stringliteral">" nb-chunk:1024\n"</span></div><div class="line"> <span class="stringliteral">" }\n"</span></div><div class="line"> <span class="stringliteral">"}\n"</span>;</div></div><!-- fragment --> <div class="fragment"><div class="line"><span class="comment">// initialize river interface</span></div><div class="line">river::initString(configurationRiver);</div></div><!-- fragment --><p>For the example we select the second solution (faster to implement example and resource at the same position.</p>
|
|
<p>river::init / river::initString must be called only one time for all the application, this represent the hardware configuration. It is NOT dynamic</p>
|
|
<p>To understand the configuration file Please see <a class="el" href="audio_river_config_file.html">River configuration file</a></p>
|
|
<p>This json is parsed by the {#ejson_mainpage_what} it contain some update like:</p><ul>
|
|
<li>Optionnal " in the name of element.
|
|
- The possibilities to remplace " with '.</li>
|
|
</ul>
|
|
<h1><a class="anchor" id="audio_river_read_river_interface"></a>
|
|
Get the river interface manager: </h1>
|
|
<p>An application can have many interface and only one Manager. And a process can contain many application.</p>
|
|
<p>Then, we will get the first application manager handle. </p><div class="fragment"><div class="line"> <span class="comment">// Create the River manager for tha application or part of the application.</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr<audio::river::Manager></a> manager = audio::river::Manager::create(<span class="stringliteral">"river_sample_read"</span>);</div></div><!-- fragment --><p> <em>Note:</em> You can get back the application handle when you create a new one with the same name.</p>
|
|
<h1><a class="anchor" id="audio_river_read_river_read_interface"></a>
|
|
Create your read interface: </h1>
|
|
<p>Generic code: </p><div class="fragment"><div class="line"> <span class="comment">// create interface:</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr<audio::river::Interface></a> interface;</div><div class="line"> <span class="comment">//Get the generic input:</span></div><div class="line"> <span class="keyword">interface </span>= manager->createInput(48000,</div><div class="line"> <a class="code" href="namespacestd.html">std</a>::vector<audio::channel>(),</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cba7ed7669dfdfed5d7ec2626caafbad9d7">audio::format_int16</a>,</div><div class="line"> ioName);</div><div class="line"> if(interface == nullptr) {</div><div class="line"> std::cout << <span class="stringliteral">"nullptr interface"</span> << std::endl;</div><div class="line"> <span class="keywordflow">return</span> -1;</div><div class="line"> }</div></div><!-- fragment --><p> Here we create an interface with:</p><ul>
|
|
<li>The frequency of 48000 Hz.</li>
|
|
<li>The default Low level definition channel</li>
|
|
<li>A data interface of 16 bits samples coded in [-32768..32767]</li>
|
|
<li>Select input interaface name "microphone"</li>
|
|
</ul>
|
|
<h1><a class="anchor" id="audio_river_read_get_data"></a>
|
|
set data callback: </h1>
|
|
<p>The best way to get data is to instanciate a simple callback. The callback is called when sample arrive and you have the nbChunk/frequency to process the data, otherwise you can generate error in data stream.</p>
|
|
<div class="fragment"><div class="line"> <span class="comment">// set callback mode ...</span></div><div class="line"> interface->setInputCallback(std::bind(&onDataReceived,</div><div class="line"> std::placeholders::_1,</div><div class="line"> std::placeholders::_2,</div><div class="line"> std::placeholders::_3,</div><div class="line"> std::placeholders::_4,</div><div class="line"> std::placeholders::_5,</div><div class="line"> std::placeholders::_6,</div><div class="line"> &outputNode));</div></div><!-- fragment --> <h1><a class="anchor" id="audio_river_read_callback"></a>
|
|
Callback inplementation: </h1>
|
|
<p>Simply declare your function and do what you want inside.</p>
|
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> onDataReceived(<span class="keyword">const</span> <span class="keywordtype">void</span>* _data,</div><div class="line"> <span class="keyword">const</span> audio::Time& _time,</div><div class="line"> <span class="keywordtype">size_t</span> _nbChunk,</div><div class="line"> <span class="keyword">enum</span> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cb">audio::format</a> _format,</div><div class="line"> uint32_t _frequency,</div><div class="line"> <span class="keyword">const</span> std::vector<audio::channel>& _map,</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html">etk::FSNode</a>* _outputNode) {</div><div class="line"> <span class="keywordflow">if</span> ( _format != <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cba7ed7669dfdfed5d7ec2626caafbad9d7">audio::format_int16</a></div><div class="line"> && _format != <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cbad325d82420c80bc087f46a12edfa617a">audio::format_float</a>) {</div><div class="line"> std::cout << <span class="stringliteral">"[ERROR] call wrong type ... (need int16_t.float)"</span> << std::endl;</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div></div><!-- fragment --> <h1><a class="anchor" id="audio_river_read_start_stop"></a>
|
|
start and stop the stream: </h1>
|
|
<div class="fragment"><div class="line"> <span class="comment">// start the stream</span></div><div class="line"> interface->start();</div><div class="line"> <span class="comment">// wait 10 second ...</span></div><div class="line"> std::this_thread::sleep_for(std::chrono::seconds(10));</div><div class="line"> <span class="comment">// stop the stream</span></div><div class="line"> interface->stop();</div></div><!-- fragment --> <h1><a class="anchor" id="audio_river_read_reset"></a>
|
|
Remove interfaces: </h1>
|
|
<div class="fragment"><div class="line"> <span class="comment">// remove interface and manager.</span></div><div class="line"> interface.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html#afa0eb096ccb28c0b229921bb6eb5fe58">reset</a>();</div><div class="line"> manager.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html#afa0eb096ccb28c0b229921bb6eb5fe58">reset</a>();</div></div><!-- fragment --><h1><a class="anchor" id="audio_river_read_full_sample"></a>
|
|
Full Sample: </h1>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include <audio/river/river.hpp></span></div><div class="line"><span class="preprocessor">#include <audio/river/Manager.hpp></span></div><div class="line"><span class="preprocessor">#include <audio/river/Interface.hpp></span></div><div class="line"><span class="preprocessor">#include <<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/__f__s__node__8hpp.html">etk/os/FSNode.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/etk__8hpp.html">etk/etk.hpp</a>></span></div><div class="line"><span class="preprocessor">#include <thread></span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keyword">const</span> std::string configurationRiver =</div><div class="line"> <span class="stringliteral">"{\n"</span></div><div class="line"> <span class="stringliteral">" microphone:{\n"</span></div><div class="line"> <span class="stringliteral">" io:'input',\n"</span></div><div class="line"> <span class="stringliteral">" map-on:{\n"</span></div><div class="line"> <span class="stringliteral">" interface:'auto',\n"</span></div><div class="line"> <span class="stringliteral">" name:'default',\n"</span></div><div class="line"> <span class="comment">//" timestamp-mode:'trigered',\n"</span></div><div class="line"> <span class="stringliteral">" },\n"</span></div><div class="line"> <span class="stringliteral">" frequency:0,\n"</span></div><div class="line"> <span class="stringliteral">" channel-map:['front-left', 'front-right'],\n"</span></div><div class="line"> <span class="stringliteral">" type:'auto',\n"</span></div><div class="line"> <span class="stringliteral">" nb-chunk:1024\n"</span></div><div class="line"> <span class="stringliteral">" }\n"</span></div><div class="line"> <span class="stringliteral">"}\n"</span>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> onDataReceived(<span class="keyword">const</span> <span class="keywordtype">void</span>* _data,</div><div class="line"> <span class="keyword">const</span> audio::Time& _time,</div><div class="line"> <span class="keywordtype">size_t</span> _nbChunk,</div><div class="line"> <span class="keyword">enum</span> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cb">audio::format</a> _format,</div><div class="line"> uint32_t _frequency,</div><div class="line"> <span class="keyword">const</span> std::vector<audio::channel>& _map,</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html">etk::FSNode</a>* _outputNode) {</div><div class="line"> <span class="keywordflow">if</span> ( _format != <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cba7ed7669dfdfed5d7ec2626caafbad9d7">audio::format_int16</a></div><div class="line"> && _format != <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cbad325d82420c80bc087f46a12edfa617a">audio::format_float</a>) {</div><div class="line"> std::cout << <span class="stringliteral">"[ERROR] call wrong type ... (need int16_t.float)"</span> << std::endl;</div><div class="line"> <span class="keywordflow">return</span>;</div><div class="line"> }</div><div class="line"> <span class="keywordflow">if</span> (_outputNode-><a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html#a66f7d8975d3f6a4c954681dd6ae3e02a">fileIsOpen</a>() == <span class="keyword">false</span>) {</div><div class="line"> <span class="keywordflow">if</span> (_format != <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cba7ed7669dfdfed5d7ec2626caafbad9d7">audio::format_int16</a>) {</div><div class="line"> <span class="comment">// get the curent power of the signal.</span></div><div class="line"> <span class="keyword">const</span> int16_t* data = <span class="keyword">static_cast<</span><span class="keyword">const </span>int16_t*<span class="keyword">></span>(_data);</div><div class="line"> int64_t <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ejson.tag:http://atria-soft.github.io/ejson/" href="http://atria-soft.github.io/ejson/namespaceejson.html#a6a37b3ae20a2b7bc207b268ab1439709a2063c1608d6e0baf80249c42e2be5804">value</a> = 0;</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii<_nbChunk*_map.size(); ++iii) {</div><div class="line"> value += std::abs(data[iii]);</div><div class="line"> }</div><div class="line"> value /= (_nbChunk*_map.size());</div><div class="line"> std::cout << <span class="stringliteral">"Get data ... average="</span> << int32_t(value) << std::endl;</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="comment">// get the curent power of the signal.</span></div><div class="line"> <span class="keyword">const</span> <span class="keywordtype">float</span>* data = <span class="keyword">static_cast<</span><span class="keyword">const </span><span class="keywordtype">float</span>*<span class="keyword">></span>(_data);</div><div class="line"> <span class="keywordtype">float</span> value = 0;</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> iii=0; iii<_nbChunk*_map.size(); ++iii) {</div><div class="line"> value += std::abs(data[iii]);</div><div class="line"> }</div><div class="line"> value /= (_nbChunk*_map.size());</div><div class="line"> std::cout << <span class="stringliteral">"Get data ... average="</span> << float(value) << std::endl;</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> <span class="comment">// just write data</span></div><div class="line"> <span class="comment">//std::cout << "Get data ... chunks=" << _nbChunk << " time=" << _time << std::endl;</span></div><div class="line"> _outputNode-><a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html#aa3473eebff7ce59fc5bb5024b035d3e5">fileWrite</a>(_data, _map.size()*audio::getFormatBytes(_format), _nbChunk);</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> _argc, <span class="keyword">const</span> <span class="keywordtype">char</span> **_argv) {</div><div class="line"> <span class="comment">// the only one init for etk:</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/namespaceetk.html#aa87d94d7a27bd41c9982fe0ba83d6f88">etk::init</a>(_argc, _argv);</div><div class="line"> <span class="comment">// local parameter:</span></div><div class="line"> std::string configFile;</div><div class="line"> std::string ioName=<span class="stringliteral">"microphone"</span>;</div><div class="line"> std::string outputFileName = <span class="stringliteral">""</span>;</div><div class="line"> <span class="keywordflow">for</span> (int32_t iii=0; iii<_argc ; ++iii) {</div><div class="line"> std::string data = _argv[iii];</div><div class="line"> <span class="keywordflow">if</span> ( data == <span class="stringliteral">"-h"</span></div><div class="line"> || data == <span class="stringliteral">"--help"</span>) {</div><div class="line"> std::cout << <span class="stringliteral">"Help : "</span> << std::endl;</div><div class="line"> std::cout << <span class="stringliteral">" --conf=xxx.json Input/output configuration"</span> << std::endl;</div><div class="line"> std::cout << <span class="stringliteral">" --io=xxx name configuration input"</span> << std::endl;</div><div class="line"> std::cout << <span class="stringliteral">" --file=yyy.raw File name to store data"</span> << std::endl;</div><div class="line"> exit(0);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (etk::start_with(data, <span class="stringliteral">"--conf="</span>) == <span class="keyword">true</span>) {</div><div class="line"> configFile = std::string(data.begin()+7, data.end());</div><div class="line"> std::cout << <span class="stringliteral">"Select config: "</span> << configFile << std::endl;</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (etk::start_with(data, <span class="stringliteral">"--io="</span>) == <span class="keyword">true</span>) {</div><div class="line"> ioName = std::string(data.begin()+5, data.end());</div><div class="line"> std::cout << <span class="stringliteral">"Select io: "</span> << ioName << std::endl;</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (etk::start_with(data, <span class="stringliteral">"--file="</span>) == <span class="keyword">true</span>) {</div><div class="line"> outputFileName = std::string(data.begin()+7, data.end());</div><div class="line"> std::cout << <span class="stringliteral">"Select output file name: "</span> << outputFileName << std::endl;</div><div class="line"> }</div><div class="line"> }</div><div class="line"> <span class="comment">// initialize river interface</span></div><div class="line"> <span class="keywordflow">if</span> (configFile == <span class="stringliteral">""</span>) {</div><div class="line"> audio::river::initString(configurationRiver);</div><div class="line"> } <span class="keywordflow">else</span> {</div><div class="line"> audio::river::init(configFile);</div><div class="line"> }</div><div class="line"> <span class="comment">// Create the River manager for tha application or part of the application.</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr<audio::river::Manager></a> manager = audio::river::Manager::create(<span class="stringliteral">"river_sample_read"</span>);</div><div class="line"> <span class="comment">// create interface:</span></div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html">ememory::SharedPtr<audio::river::Interface></a> interface;</div><div class="line"> <span class="comment">//Get the generic input:</span></div><div class="line"> <span class="keyword">interface </span>= manager->createInput(48000,</div><div class="line"> <a class="code" href="namespacestd.html">std</a>::vector<audio::channel>(),</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/audio.tag:http://musicdsp.github.io/audio/" href="http://musicdsp.github.io/audio/namespaceaudio.html#a2e69fde0e376bc9b0b6fa91fb93105cba7ed7669dfdfed5d7ec2626caafbad9d7">audio::format_int16</a>,</div><div class="line"> ioName);</div><div class="line"> if(interface == nullptr) {</div><div class="line"> std::cout << <span class="stringliteral">"nullptr interface"</span> << std::endl;</div><div class="line"> <span class="keywordflow">return</span> -1;</div><div class="line"> }</div><div class="line"> <a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html">etk::FSNode</a> outputNode;</div><div class="line"> <span class="comment">// open output file if needed:</span></div><div class="line"> <span class="keywordflow">if</span> (outputFileName != <span class="stringliteral">""</span>) {</div><div class="line"> outputNode.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html#a6e787e7f3148dae0c74139be7b05ab43">setName</a>(outputFileName);</div><div class="line"> outputNode.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html#a68cf71c003e9ba37cace50e23870feaa">fileOpenWrite</a>();</div><div class="line"> }</div><div class="line"> <span class="comment">// set callback mode ...</span></div><div class="line"> interface->setInputCallback(std::bind(&onDataReceived,</div><div class="line"> std::placeholders::_1,</div><div class="line"> std::placeholders::_2,</div><div class="line"> std::placeholders::_3,</div><div class="line"> std::placeholders::_4,</div><div class="line"> std::placeholders::_5,</div><div class="line"> std::placeholders::_6,</div><div class="line"> &outputNode));</div><div class="line"> <span class="comment">// start the stream</span></div><div class="line"> interface->start();</div><div class="line"> <span class="comment">// wait 10 second ...</span></div><div class="line"> std::this_thread::sleep_for(std::chrono::seconds(10));</div><div class="line"> <span class="comment">// stop the stream</span></div><div class="line"> interface->stop();</div><div class="line"> <span class="comment">// remove interface and manager.</span></div><div class="line"> interface.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html#afa0eb096ccb28c0b229921bb6eb5fe58">reset</a>();</div><div class="line"> manager.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/ememory.tag:http://atria-soft.github.io/ememory/" href="http://atria-soft.github.io/ememory/classememory_1_1_shared_ptr.html#afa0eb096ccb28c0b229921bb6eb5fe58">reset</a>();</div><div class="line"> <span class="comment">// close the output file</span></div><div class="line"> <span class="keywordflow">if</span> (outputFileName != <span class="stringliteral">""</span>) {</div><div class="line"> outputNode.<a class="codeRef" doxygen="/home/heero/dev/perso/out/doc/release/etk.tag:http://atria-soft.github.io/etk/" href="http://atria-soft.github.io/etk/classetk_1_1_f_s_node.html#a5e9146d1e8984f05221d4dbaa1bcf9b7">fileClose</a>();</div><div class="line"> }</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"></div></div><!-- fragment --></div></div><!-- contents -->
|
|
<!-- HTML footer for doxygen 1.8.8-->
|
|
<!-- start footer part -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated on Mon Oct 24 2016 15:35:48 for audio-river: Multi-nodal audio interface by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.12
|
|
</small></address>
|
|
</body>
|
|
</html>
|