Developer World
Spresense Arduino Library v3.2.0-77d75a4
MediaRecorder Class Reference

MediaRecorder Class Definitions. More...

#include <MediaRecorder.h>

Public Member Functions

err_t begin (void)
 Initialize the MediaRecorder. More...
 
err_t begin (AudioAttentionCb attcb)
 Initialize the MediaRecorder. More...
 
err_t begin (AudioAttentionCb attcb, bool use_frontend)
 
err_t end (void)
 Finalize the MediaRecorder. More...
 
err_t activate (AsSetRecorderStsInputDevice input_device, MediaRecorderCallback mrcb)
 Activate the MediaRecorder. More...
 
err_t activate (AsSetRecorderStsInputDevice input_device, MediaRecorderCallback mrcb, uint32_t recorder_bufsize)
 Activate the MediaRecorder. More...
 
err_t activate (AsSetRecorderStsInputDevice input_device, MediaRecorderCallback mrcb, uint32_t recorder_bufsize, AsMicFrontendPreProcType proc_type, bool is_digital=false)
 Activate the MediaRecorder. More...
 
err_t init (uint8_t codec_type, uint8_t channel_number)
 Initialize the MediaRecorder (Abridged version). More...
 
err_t init (uint8_t codec_type, uint8_t channel_number, uint32_t sampling_rate, uint8_t bit_length, uint32_t bit_rate)
 Initialize the MediaRecorder (Abridged version). More...
 
err_t init (uint8_t codec_type, uint8_t channel_number, uint32_t sampling_rate, uint8_t bit_length, uint32_t bit_rate, const char *codec_path)
 Initialize the MediaRecorder. More...
 
err_t start (void)
 Start Recording. More...
 
err_t stop (void)
 Stop Recording. More...
 
err_t deactivate (void)
 Deactivate the MediaRecorder. More...
 
err_t setMicGain (int16_t mic_gain)
 Set MicActivate the . More...
 
err_t readFrames (uint8_t *p_buffer, uint32_t buffer_size, uint32_t *read_size)
 Read a recorded audio data. More...
 
err_t writeWavHeader (File &myfile)
 Write WAV header to file. More...
 
bool setCapturingClkMode (uint8_t clk_mode)
 Set capturing clock mode. More...
 

Static Public Member Functions

static MediaRecordergetInstance ()
 Get instance of MediaRecorder for singleton.
 

Detailed Description

MediaRecorder Class Definitions.

Member Function Documentation

◆ begin() [1/2]

err_t MediaRecorder::begin ( void  )

Initialize the MediaRecorder.

This function is called only once when using the MediaRecorder. In this function, alloc memory area of FIFO for ES data exchange, creation of objects for audio data capturing and encoding.

◆ begin() [2/2]

err_t MediaRecorder::begin ( AudioAttentionCb  attcb)

Initialize the MediaRecorder.

This function can set callback funtion which receive attention notify.

◆ end()

err_t MediaRecorder::end ( void  )

Finalize the MediaRecorder.

This function is called only once when finish the MediaRecorder.

◆ activate() [1/3]

err_t MediaRecorder::activate ( AsSetRecorderStsInputDevice  input_device,
MediaRecorderCallback  mrcb 
)

Activate the MediaRecorder.

This function activates media recorder system and audio HW. You should specify input device which you would like to record. You can set "Mic-in" or "I2S-in". The result of APIs will be returnd by callback function which is specified by this function.

Parameters
input_deviceSelect input device. AS_SETRECDR_STS_INPUTDEVICE_MIC or AS_SETRECDR_STS_INPUTDEVICE_I2S
mrcbSepcify callback function which is called to notify API results.

◆ activate() [2/3]

err_t MediaRecorder::activate ( AsSetRecorderStsInputDevice  input_device,
MediaRecorderCallback  mrcb,
uint32_t  recorder_bufsize 
)

Activate the MediaRecorder.

This function works as same as above activate(input_device, mrcb). But is able to set buffer size of recorder.

Parameters
input_deviceSelect input device. AS_SETRECDR_STS_INPUTDEVICE_MIC or AS_SETRECDR_STS_INPUTDEVICE_I2S
mrcbSepcify callback function which is called to notify API results.

◆ activate() [3/3]

err_t MediaRecorder::activate ( AsSetRecorderStsInputDevice  input_device,
MediaRecorderCallback  mrcb,
uint32_t  recorder_bufsize,
AsMicFrontendPreProcType  proc_type,
bool  is_digital = false 
)

Activate the MediaRecorder.

This function works as same as above activate(input_device, mrcb, bufsize). But is able to set PreProcessing type. If ommit it, fix to Through.

Parameters
input_deviceSelect input device. AS_SETRECDR_STS_INPUTDEVICE_MIC or AS_SETRECDR_STS_INPUTDEVICE_I2S
mrcbSepcify callback function which is called to notify API results.

◆ init() [1/3]

err_t MediaRecorder::init ( uint8_t  codec_type,
uint8_t  channel_number 
)

Initialize the MediaRecorder (Abridged version).

This is abridged version on initialize API. You can init media recorder by only 2 parameters, Codec type and number of channels. When this API is called, other parameters are fixed as below.

Sampling Rate : 48kHz Bit length : 16bit Bit rate : 96kbps(effective only when mp3) DSP binary path : /mnt/sd0/BIN

Parameters
codec_typeSelect compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
channel_numberSet chennel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO, 2CH, 4CH, 8CH

◆ init() [2/3]

err_t MediaRecorder::init ( uint8_t  codec_type,
uint8_t  channel_number,
uint32_t  sampling_rate,
uint8_t  bit_length,
uint32_t  bit_rate 
)

Initialize the MediaRecorder (Abridged version).

This is abridged version on initialize API. In this API, you can set initialize parameters exclude DSP binary path. If you don't heve needs to set DSP binary path, call this API. DSP binary path is fixed as below.

DSP binary path : /mnt/sd0/BIN

Parameters
codec_typeSelect compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
channel_numberSet chennel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO, 2CH, 4CH, 8CH
sampling_rateSet sampling rate. AS_SAMPLINGRATE_XXXXX
bit_lengthSet bit length. AS_BITLENGTH_16 or AS_BITLENGTH_24
bit_rateSet bit rate. AS_BITRATE_XXXXX

◆ init() [3/3]

err_t MediaRecorder::init ( uint8_t  codec_type,
uint8_t  channel_number,
uint32_t  sampling_rate,
uint8_t  bit_length,
uint32_t  bit_rate,
const char *  codec_path 
)

Initialize the MediaRecorder.

This is full version on initialize API. In this API, you can should set all of initialize parameters. Before you start recording, you must initialize media recorder by this API or abridged versions of this API

Parameters
codec_typeSelect compression code. AS_CODECTYPE_MP3 or AS_CODECTYPE_WAV
channel_numberSet chennel number. AS_CHANNEL_MONO or AS_CHANNEL_STEREO, 2CH, 4CH, 8CH
sampling_rateSet sampling rate. AS_SAMPLINGRATE_XXXXX
bit_lengthSet bit length. AS_BITLENGTH_16 or AS_BITLENGTH_24
bit_rateSet bit rate. AS_BITRATE_XXXXX
codec_pathSet DSP binary placement path

◆ start()

err_t MediaRecorder::start ( void  )

Start Recording.

This function starts recoding. Once you call this function, the media recorder will be in active state and encoded data will be stored into internal FIFO. You shold pull out the data as soon as possible by "read frame API". If you do not, FIFO will overflow and data will lack.

This will continue until you call "stop API".

◆ stop()

err_t MediaRecorder::stop ( void  )

Stop Recording.

This function stops recoding. You can call this API when recording is activate. When you call this API, return of API will back soon but internal work cannot stop immediately. So, after API call, encoded data will be stored to FIFO a little. It is better to pull out them.

◆ deactivate()

err_t MediaRecorder::deactivate ( void  )

Deactivate the MediaRecorder.

This function deactivates media recorder system, and audio HW.

◆ setMicGain()

err_t MediaRecorder::setMicGain ( int16_t  mic_gain)

Set MicActivate the .

The gain set when microphone is used can be specified by the "mic_gain" argument. You can set every 0.5 dB between 0 dB and 21 dB. In this parameter, a value from 0 to 210 is set for every 5.

◆ readFrames()

err_t MediaRecorder::readFrames ( uint8_t *  p_buffer,
uint32_t  buffer_size,
uint32_t *  read_size 
)

Read a recorded audio data.

This function reads encoded audio data from media recorder. When you call this API, the data will be copied to p_buffer at buffer_size byte. Sometimes, a size of encoded data will be larger than buffer_size, but this API copies up to buffer_size. In the case, you should call this API again.

◆ writeWavHeader()

err_t MediaRecorder::writeWavHeader ( File myfile)

Write WAV header to file.

This function writes WAV header information to specified file. WAV heeader will be written top of the file.

◆ setCapturingClkMode()

bool MediaRecorder::setCapturingClkMode ( uint8_t  clk_mode)

Set capturing clock mode.

This API set internal audio capture clock mode to Normal(48kHz) or HiReso(192kHz). Default on boot is Normal, if you set HiReso, call this API with HiReso set.

Parameters
clk_modeSet clock mode. MEDIARECORDER_CAPCLK_NORMAL, MEDIARECORDER_CAPCLK_HIRESO

The documentation for this class was generated from the following file: