audio-river/doc/read.md

3.6 KiB

Read stream form Audio input

@tableofcontents

Objectifs:

  • Understand basis of river
  • Create a simple recording interface that print the average of sample absolute value.

When you will create an application based on the river audio interface you need :

Include:

Include manager and interface node @snippet read.cpp audio_river_sample_include

Initilize the River library:

We first need to initialize etk sub library (needed to select the log level of sub-libraries and file access abstraction @snippet read.cpp audio_river_sample_init

Now we will initilaize the river library. To do this We have 2 posibilities: With a file:

	// initialize river interface
	river::init("DATA:configFileName.json");

With a json string:

@snippet read.cpp audio_river_sample_read_config_file

// initialize river interface
river::initString(configurationRiver);

For the example we select the second solution (faster to implement example and resource at the same position.

river::init / river::initString must be called only one time for all the application, this represent the hardware configuration. It is NOT dynamic

To understand the configuration file Please see @ref audio_river_config_file

This json is parsed by the @ref {#ejson_mainpage_what} it contain some update like:

  • Optionnal " in the name of element.
  • The possibilities to remplace " with '.

Get the river interface manager:

An application can have many interface and only one Manager. And a process can contain many application.

Then, we will get the first application manager handle. @snippet read.cpp audio_river_sample_get_interface

Note: You can get back the application handle when you create a new one with the same name.

Create your read interface:

Generic code: @snippet read.cpp audio_river_sample_create_read_interface

Here we create an interface with:

  • The frequency of 48000 Hz.
  • The default Low level definition channel
  • A data interface of 16 bits samples coded in [-32768..32767]
  • Select input interaface name "microphone"

set data callback:

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.

@snippet read.cpp audio_river_sample_set_callback

Callback inplementation:

Simply declare your function and do what you want inside.

@snippet read.cpp audio_river_sample_callback_implement

start and stop the stream:

@snippet read.cpp audio_river_sample_read_start_stop

Remove interfaces:

@snippet read.cpp audio_river_sample_read_reset

Full Sample:

@snippet read.cpp audio_river_sample_read_all