Developer World
Spresense Arduino Library v3.2.0-77d75a4
MediaPlayer.h
Go to the documentation of this file.
1/*
2 * MediaPlayer.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
26#ifndef MediaPlayer_h
27#define MediaPlayer_h
28
29#ifdef SUBCORE
30#error "Audio library is NOT supported by SubCore."
31#endif
32
33class File;
34
35// #ifdef __cplusplus
36
37#include <audio/audio_high_level_api.h>
38#include <audio/utilities/wav_containerformat_parser.h>
39#include <memutils/simple_fifo/CMN_SimpleFifo.h>
40
41/*--------------------------------------------------------------------------*/
42
46#define MEDIAPLAYER_LOG_DEBUG
47
48#define print_err printf
49
50#ifdef MEDIAPLAYER_LOG_DEBUG
51#define print_dbg(...) printf(__VA_ARGS__)
52#else
53#define print_dbg(x...)
54#endif
55
60#define MEDIAPLAYER_ECODE_OK 0
61#define MEDIAPLAYER_ECODE_COMMAND_ERROR 1
62#define MEDIAPLAYER_ECODE_SIMPLEFIFO_ERROR 2
63#define MEDIAPLAYER_ECODE_FILEACCESS_ERROR 3
64#define MEDIAPLAYER_ECODE_FILEEND 4
65#define MEDIAPLAYER_ECODE_SHARED_MEMORY_ERROR 5
66#define MEDIAPLAYER_ECODE_WAV_PARSER_ERROR 6
67#define MEDIAPLAYER_ECODE_BUFFERSIZE_ERROR 7
68#define MEDIAPLAYER_ECODE_BUFFERALLOC_ERROR 8
69
70#define MEDIAPLAYER_BUF_FRAME_NUM 8
71#define MEDIAPLAYER_BUF_FRAME_SIZE 6144
72#define MEDIAPLAYER_BUF_SIZE (MEDIAPLAYER_BUF_FRAME_NUM * MEDIAPLAYER_BUF_FRAME_SIZE)
73
74/*--------------------------------------------------------------------------*/
75
82{
83public:
84
90 {
91 static MediaPlayer instance;
92 return &instance;
93 }
94
102 typedef enum
103 {
105 Player1
107
117
126
136 PlayerId id
137 );
138
147 PlayerId id,
148 AudioAttentionCb attcb
149 );
150
161 PlayerId id,
162 MediaPlayerCallback mpcb
163 );
164
175 PlayerId id,
176 uint8_t output_device,
177 MediaPlayerCallback mpcb
178 );
179
189 PlayerId id,
190 MediaPlayerCallback mpcb,
191 uint32_t player_bufsize
192 );
193
203 PlayerId id,
204 uint8_t output_device,
205 MediaPlayerCallback mpcb,
206 uint32_t player_bufsize
207 );
208
222 PlayerId id,
223 uint8_t codec_type,
224 uint32_t sampling_rate,
225 uint8_t channel_number
226 );
227
240 PlayerId id,
241 uint8_t codec_type,
242 uint32_t sampling_rate,
243 uint8_t bit_length,
244 uint8_t channel_number
245 );
246
259 PlayerId id,
260 uint8_t codec_type,
261 const char *codec_path,
262 uint32_t sampling_rate,
263 uint8_t channel_number
264 );
265
277 PlayerId id,
278 uint8_t codec_type,
279 const char *codec_path,
280 uint32_t sampling_rate,
281 uint8_t bit_length,
282 uint8_t channel_number
283 );
284
297 PlayerId id,
298 DecodeDoneCallback dccb
299 );
300
313
324 PlayerId id,
325 uint8_t mode
326 );
327
338 PlayerId id,
339 AsRequestNextType type
340 );
341
350 PlayerId id
351 );
352
363 PlayerId id,
364 File& myfile
365 );
366
376 PlayerId id,
377 uint8_t *data,
378 uint32_t size
379 );
380
381private:
382
388 : m_player0_simple_fifo_buf(NULL)
389 , m_player1_simple_fifo_buf(NULL)
390 {}
391 MediaPlayer(const MediaPlayer&);
392 MediaPlayer& operator=(const MediaPlayer&);
393 ~MediaPlayer() {}
394
395
396 CMN_SimpleFifoHandle m_player0_simple_fifo_handle;
397 CMN_SimpleFifoHandle m_player1_simple_fifo_handle;
398
399 uint32_t *m_player0_simple_fifo_buf;
400 uint32_t *m_player1_simple_fifo_buf;
401
402 AsPlayerInputDeviceHdlrForRAM m_player0_input_device_handler;
403 AsPlayerInputDeviceHdlrForRAM m_player1_input_device_handler;
404
405 char m_es_player0_buf[MEDIAPLAYER_BUF_FRAME_SIZE];
406 char m_es_player1_buf[MEDIAPLAYER_BUF_FRAME_SIZE];
407
408 err_t write_fifo(File& myFile, char *p_es_buf, CMN_SimpleFifoHandle *handle);
409 err_t write_fifo(uint8_t *data, uint32_t size, CMN_SimpleFifoHandle *handle);
410
411 bool check_decode_dsp(uint8_t codec_type, const char *path);
412};
413
414// #endif // __cplusplus
415#endif // MediaPlayer_h
416
#define MEDIAPLAYER_ECODE_OK
Definition: MediaPlayer.h:60
The File class allows for reading from and writing to individual files on the File System.
Definition: File.h:55
MediaPlayer Class Definitions.
Definition: MediaPlayer.h:82
err_t create(PlayerId id, AudioAttentionCb attcb)
Creation of the MediaPlayer.
err_t end(void)
Finalize the MediaPlayer.
Definition: MediaPlayer.h:125
err_t deactivate(PlayerId id)
Deactivate the MediaPlayer.
err_t create(PlayerId id)
Creation of the MediaPlayer.
err_t reqNextProcess(PlayerId id, AsRequestNextType type)
Request next process to player.
err_t activate(PlayerId id, MediaPlayerCallback mpcb, uint32_t player_bufsize)
Activate the MediaPlayer.
err_t init(PlayerId id, uint8_t codec_type, uint32_t sampling_rate, uint8_t channel_number)
Initialize the MediaPlayer (Abridged version).
err_t stop(PlayerId id, uint8_t mode)
Stop playing (Stop mode specify).
static MediaPlayer * getInstance()
Get instance of MediaRecorder for singleton.
Definition: MediaPlayer.h:89
err_t writeFrames(PlayerId id, File &myfile)
Write(Supply) audio data to play.
err_t stop(PlayerId id)
Stop playing.
err_t activate(PlayerId id, MediaPlayerCallback mpcb)
Activate the MediaPlayer.
err_t begin(void)
Initialize the MediaPlayer.
err_t init(PlayerId id, uint8_t codec_type, const char *codec_path, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number)
Initialize the MediaPlayer.
err_t init(PlayerId id, uint8_t codec_type, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number)
Initialize the MediaPlayer (Abridged version).
err_t activate(PlayerId id, uint8_t output_device, MediaPlayerCallback mpcb)
Activate the MediaPlayer (old interface)
err_t init(PlayerId id, uint8_t codec_type, const char *codec_path, uint32_t sampling_rate, uint8_t channel_number)
Initialize the MediaPlayer (Abridged version).
PlayerId
Audio library allows you to use two players simultaneously. Please set Player ID that player instance...
Definition: MediaPlayer.h:103
@ Player0
Definition: MediaPlayer.h:104
@ Player1
Definition: MediaPlayer.h:105
err_t activate(PlayerId id, uint8_t output_device, MediaPlayerCallback mpcb, uint32_t player_bufsize)
Activate the MediaPlayer (Old compatible)
err_t start(PlayerId id, DecodeDoneCallback dccb)
Start playing.
err_t writeFrames(PlayerId id, uint8_t *data, uint32_t size)
Write(Supply) audio data to play.
unsigned int err_t
Definition: Audio.h:108