Developer World
Spresense Arduino Library v3.2.0-77d75a4
MediaRecorder.h
Go to the documentation of this file.
1/*
2 * MediaRecorder.h - Audio include file for the Spresense SDK
3 * Copyright 2018 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
28#ifndef MediaRecorder_h
29#define MediaRecorder_h
30
31#ifdef SUBCORE
32#error "Audio library is NOT supported by SubCore."
33#endif
34
35class File;
36#include <audio/audio_high_level_api.h>
37#include <audio/audio_message_types.h>
38#include <audio/utilities/frame_samples.h>
39#include <audio/utilities/wav_containerformat.h>
40#include <memutils/simple_fifo/CMN_SimpleFifo.h>
41
42#include "FrontEnd.h"
43
44/*--------------------------------------------------------------------------*/
45
50#define MEDIARECORDER_LOG_DEBUG
51
52#define print_err printf
53
54#ifdef MEDIARECORDER_LOG_DEBUG
55#define print_dbg(...) printf(__VA_ARGS__)
56#else
57#define print_dbg(x...)
58#endif
59
64#define MEDIARECORDER_ECODE_OK 0
65#define MEDIARECORDER_ECODE_COMMAND_ERROR 1
66#define MEDIARECORDER_ECODE_BUFFER_INIT_ERROR 2
67#define MEDIARECORDER_ECODE_BUFFER_POLL_ERROR 3
68#define MEDIARECORDER_ECODE_DSP_ACCESS_ERROR 4
69#define MEDIARECORDER_ECODE_FILEACCESS_ERROR 5
70#define MEDIARECORDER_ECODE_BUFFER_SIZE_ERROR 6
71#define MEDIARECORDER_ECODE_BUFFER_AREA_ERROR 7
72#define MEDIARECORDER_ECODE_INSUFFICIENT_BUFFER_AREA 8
73#define MEDIARECORDER_ECODE_BASEBAND_ERROR 9
74#define MEDIARECORDER_ECODE_BUFFER_ALLOC_ERROR 10
75
80#define MEDIARECORDER_BUF_FRAME_NUM 10
81#define MEDIARECORDER_BUF_FRAME_SIZE (768 * 2 * 8)
82#define MEDIARECORDER_BUF_SIZE (MEDIARECORDER_BUF_FRAME_NUM * MEDIARECORDER_BUF_FRAME_SIZE)
83
88#define MEDIARECORDER_CAPCLK_NORMAL (0)
89#define MEDIARECORDER_CAPCLK_HIRESO (1)
90
91/*--------------------------------------------------------------------------*/
92
99{
100public:
101
107 {
108 static MediaRecorder instance;
109 return &instance;
110 }
111
122
130 err_t begin(AudioAttentionCb attcb);
131 err_t begin(AudioAttentionCb attcb, bool use_frontend);
132
140 err_t end(void);
141
154 AsSetRecorderStsInputDevice input_device,
155 MediaRecorderCallback mrcb
156 );
157
167 AsSetRecorderStsInputDevice input_device,
168 MediaRecorderCallback mrcb,
169 uint32_t recorder_bufsize
170 );
171
172
182 AsSetRecorderStsInputDevice input_device,
183 MediaRecorderCallback mrcb,
184 uint32_t recorder_bufsize,
185 AsMicFrontendPreProcType proc_type,
186 bool is_digital = false
187 );
188
204 uint8_t codec_type,
205 uint8_t channel_number
206 );
207
221 uint8_t codec_type,
222 uint8_t channel_number,
223 uint32_t sampling_rate,
224 uint8_t bit_length,
225 uint32_t bit_rate
226 );
227
239 uint8_t codec_type,
240 uint8_t channel_number,
241 uint32_t sampling_rate,
242 uint8_t bit_length,
243 uint32_t bit_rate,
244 const char *codec_path
245 );
246
261
273 err_t stop(void);
274
283
294 err_t setMicGain(int16_t mic_gain);
295
307 uint8_t* p_buffer,
308 uint32_t buffer_size,
309 uint32_t* read_size
310 );
311
321
331 uint8_t clk_mode
332 );
333
334private:
335
341 : m_recorder_simple_fifo_buf(NULL)
342 , m_mr_callback(NULL)
343 , m_p_fed_ins(NULL)
344 {}
346 MediaRecorder& operator=(const MediaRecorder&);
347 ~MediaRecorder() {}
348
353 CMN_SimpleFifoHandle m_recorder_simple_fifo_handle;
354 uint32_t *m_recorder_simple_fifo_buf;
355 char m_es_recorder_buf[MEDIARECORDER_BUF_FRAME_SIZE];
356
357 AsRecorderOutputDeviceHdlr m_output_device_handler;
358 int m_es_size;
359 WAVHEADER m_wav_format;
360 MediaRecorderCallback m_mr_callback;
361
362 FrontEnd *m_p_fed_ins;
363
364 bool check_encode_dsp(uint8_t codec_type, const char *path, uint32_t sampling_rate);
365
370 void init_wav(AsInitRecorderParam *param);
371 void init_mp3(AsInitRecorderParam *param);
372 void init_opus(AsInitRecorderParam *param);
373 void init_pcm(AsInitRecorderParam *param);
374};
375
376#endif // MediaRecorder_h
377
Mic Frontend Class for Arduino on Spresense.
The File class allows for reading from and writing to individual files on the File System.
Definition: File.h:55
FrontEnd Class Definitions.
Definition: FrontEnd.h:82
MediaRecorder Class Definitions.
Definition: MediaRecorder.h:99
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).
err_t begin(void)
Initialize the MediaRecorder.
static MediaRecorder * getInstance()
Get instance of MediaRecorder for singleton.
Definition: MediaRecorder.h:106
err_t init(uint8_t codec_type, uint8_t channel_number)
Initialize the MediaRecorder (Abridged version).
err_t begin(AudioAttentionCb attcb)
Initialize the MediaRecorder.
err_t start(void)
Start Recording.
err_t activate(AsSetRecorderStsInputDevice input_device, MediaRecorderCallback mrcb, uint32_t recorder_bufsize, AsMicFrontendPreProcType proc_type, bool is_digital=false)
Activate the MediaRecorder.
err_t activate(AsSetRecorderStsInputDevice input_device, MediaRecorderCallback mrcb, uint32_t recorder_bufsize)
Activate the MediaRecorder.
err_t writeWavHeader(File &myfile)
Write WAV header to file.
err_t readFrames(uint8_t *p_buffer, uint32_t buffer_size, uint32_t *read_size)
Read a recorded audio data.
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.
err_t end(void)
Finalize the MediaRecorder.
err_t setMicGain(int16_t mic_gain)
Set MicActivate the .
err_t deactivate(void)
Deactivate the MediaRecorder.
err_t stop(void)
Stop Recording.
bool setCapturingClkMode(uint8_t clk_mode)
Set capturing clock mode.
err_t activate(AsSetRecorderStsInputDevice input_device, MediaRecorderCallback mrcb)
Activate the MediaRecorder.
unsigned int err_t
Definition: Audio.h:108