33#error "Audio library is NOT supported by SubCore."
42#include <pins_arduino.h>
48#include <audio/audio_high_level_api.h>
49#include <audio/utilities/wav_containerformat.h>
50#include <audio/utilities/wav_containerformat_parser.h>
51#include <audio/utilities/frame_samples.h>
52#include <memutils/simple_fifo/CMN_SimpleFifo.h>
54#define WRITE_FIFO_FRAME_NUM (8)
55#define WRITE_FIFO_FRAME_SIZE (1024*2*3)
56#define WRITE_BUF_SIZE (WRITE_FIFO_FRAME_NUM * WRITE_FIFO_FRAME_SIZE)
58#define READ_FIFO_FRAME_NUM (10)
59#define READ_FIFO_FRAME_SIZE (1024*2*8)
60#define READ_BUF_SIZE (READ_FIFO_FRAME_NUM * READ_FIFO_FRAME_SIZE)
62#define FIFO_FRAME_SIZE (\
63 (WRITE_BUF_SIZE > READ_BUF_SIZE) ?\
64 (WRITE_FIFO_FRAME_SIZE) : (READ_FIFO_FRAME_SIZE)\
67#define SIMPLE_FIFO_BUF_SIZE (\
68 ((WRITE_BUF_SIZE) > (READ_BUF_SIZE)) ? \
69 (WRITE_BUF_SIZE) : (READ_BUF_SIZE)\
72extern "C" void outputDeviceCallback(uint32_t);
75#define print_err printf
78#define print_dbg(...) printf(__VA_ARGS__)
80#define print_dbg(x...)
85#define AS_CODECTYPE_PCM 5
91#define AUDIOLIB_ECODE_OK 0
92#define AUDIOLIB_ECODE_SHARED_MEMORY_ERROR 1
93#define AUDIOLIB_ECODE_SIMPLEFIFO_ERROR 2
94#define AUDIOLIB_ECODE_AUDIOCOMMAND_ERROR 3
95#define AUDIOLIB_ECODE_FILEACCESS_ERROR 4
96#define AUDIOLIB_ECODE_FILEEND 5
97#define AUDIOLIB_ECODE_BUFFER_AREA_ERROR 6
98#define AUDIOLIB_ECODE_BUFFER_SIZE_ERROR 7
99#define AUDIOLIB_ECODE_INSUFFICIENT_BUFFER_AREA 8
100#define AUDIOLIB_ECODE_WAV_PARSE_ERROR 9
101#define AUDIOLIB_ECODE_PARAMETER_ERROR 10
207 uint32_t player0bufsize,
208 uint32_t player1bufsize
238 uint32_t player0bufsize,
239 uint32_t player1bufsize
275 uint8_t input_device,
290 uint8_t input_device,
306 uint8_t input_device,
451 const char *codec_path,
476 const char *codec_path,
548 const char *codec_path,
572 const char *codec_path,
699 unsigned char l_gain,
822 uint32_t buffer_size,
863 : m_player0_simple_fifo_buf(NULL)
864 , m_player1_simple_fifo_buf(NULL)
865 , m_attention_callback(NULL)
871 char m_es_player0_buf[FIFO_FRAME_SIZE];
872 char m_es_player1_buf[WRITE_FIFO_FRAME_SIZE];
874 CMN_SimpleFifoHandle m_player0_simple_fifo_handle;
875 CMN_SimpleFifoHandle m_player1_simple_fifo_handle;
876 uint32_t *m_player0_simple_fifo_buf;
877 uint32_t *m_player1_simple_fifo_buf;
879 AsPlayerInputDeviceHdlrForRAM m_player0_input_device_handler;
880 AsPlayerInputDeviceHdlrForRAM m_player1_input_device_handler;
882 AsRecorderOutputDeviceHdlr m_output_device_handler;
884 WAVHEADER m_wav_format;
887 AudioAttentionCb m_attention_callback;
892 err_t begin_manager(
void);
893 err_t begin_player(
void);
894 err_t begin_recorder(
void);
896 err_t end_manager(
void);
897 err_t end_player(
void);
898 err_t end_recorder(
void);
900 err_t activateAudio(
void);
903 err_t powerOff(
void);
907 err_t initMicFrontend(uint8_t ch_num, uint8_t bit_length, uint16_t sample);
908 err_t init_recorder_wav(AudioCommand* command, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number);
909 err_t init_recorder_mp3(AudioCommand* command, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number);
910 err_t init_recorder_opus(AudioCommand* command, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number);
911 err_t init_recorder_pcm(AudioCommand* command, uint32_t sampling_rate, uint8_t bit_length, uint8_t channel_number);
914 err_t set_output(uint8_t device, uint8_t sp_drv);
916 err_t write_fifo(
int,
char*, uint32_t, CMN_SimpleFifoHandle*);
917 err_t write_fifo(
File&,
char*, uint32_t, CMN_SimpleFifoHandle*);
920 err_t set_mic_map(uint8_t map[AS_MIC_CHANNEL_MAX]);
921 err_t init_mic_gain(
int,
int);
924 err_t send_set_through(
void);
926 bool check_decode_dsp(uint8_t codec_type,
const char *path);
927 bool check_encode_dsp(uint8_t codec_type,
const char *path, uint32_t fs);
Audio Library Class Definitions.
Definition: Audio.h:117
err_t setPlayerMode(uint8_t device, uint32_t player0bufsize, uint32_t player1bufsize)
Set Audio Library Mode to Music Player.
err_t setPlayerMode(uint8_t device, uint8_t sp_drv)
Set Audio Library Mode to Music Player.
err_t closeOutputFile(File &myFile)
Close Outputfile.
err_t initRecorder(uint8_t codec, const char *codec_path, uint32_t fs, uint8_t bitlen, uint8_t channel)
Initialize recorder.
err_t stopPlayer(PlayerId id)
Stop Player.
err_t setRecorderMode(uint8_t input_device, int32_t input_gain, uint32_t bufsize)
Set Audio Library Mode to Sound Recorder.
err_t setVolume(int volume)
Set Player Volume.
err_t writeFrames(PlayerId id, File &myfile)
Write Stream Data from a file to FIFO by some frames.(now 5 frames)
err_t setPlayerMode(uint8_t device)
Set Audio Library Mode to Music Player.
err_t setBeep(char enable, short volume, short frequency)
Set Beep Sound.
int getRecordingSize()
Get recording ES size.
Definition: Audio.h:852
err_t stopRecorder(void)
Stop Recorder.
err_t startPlayer(PlayerId id)
Start Player.
err_t end(void)
Finalization the audio library and HW modules.
err_t initRecorder(uint8_t codec, const char *codec_path, uint32_t fs, uint8_t channel)
Initialize recorder.
err_t setPlayerMode(uint8_t device, uint8_t sp_drv, uint32_t player0bufsize, uint32_t player1bufsize)
Set Audio Library Mode to Music Player.
err_t setLRgain(PlayerId id, unsigned char l_gain, unsigned char r_gain)
Set Player L/R Gain.
err_t begin(AudioAttentionCb attcb)
Initialize the audio library and HW modules.
PlayerId
Audio library allows you to use two players simultaneously. Please set Player ID that player instance...
Definition: Audio.h:137
@ Player1
Definition: Audio.h:139
@ Player0
Definition: Audio.h:138
err_t startRecorder(void)
Start Recorder.
err_t writeWavHeader(File &myFile)
Write WAV Header.
err_t readFrames(char *p_buffer, uint32_t buffer_size, uint32_t *read_size)
Read Stream Data from FIFO to a file by some frames.(now 5 frames)
err_t initPlayer(PlayerId id, uint8_t codec, const char *codec_path, uint32_t fs, uint8_t channel)
Initialize player.
err_t stopPlayer(PlayerId id, uint8_t mode)
Stop Player (mode specified)
ThroughInput
Input select parameter at baseband through mode.
Definition: Audio.h:322
@ BothIn
Definition: Audio.h:325
@ I2sIn
Definition: Audio.h:324
@ MicIn
Definition: Audio.h:323
err_t begin(void)
Initialize the audio library and HW modules.
err_t setRecorderMode(uint8_t input_device, int32_t input_gain, uint32_t bufsize, bool is_digital)
Set Audio Library Mode to Sound Recorder.
err_t setRecorderMode(uint8_t input_device, int32_t input_gain)
Set Audio Library Mode to Sound Recorder.
err_t initRecorder(uint8_t codec, uint32_t fs, uint8_t channel)
Initialize recorder.
err_t setReadyMode(void)
Set Audio Library Mode to Ready.
err_t setRenderingClockMode(AsClkMode mode)
Set Rendering clock mode.
err_t setVolume(int master, int player0, int player1)
Set Player Volume.
err_t readFrames(File &myFile)
Read Stream Data from FIFO to a file by some frames.(now 5 frames)
err_t initRecorder(uint8_t codec, uint32_t fs, uint8_t bitlen, uint8_t channel)
Initialize recorder.
err_t setThroughMode(ThroughInput input, ThroughI2sOut i2s_out, bool sp_out, int32_t input_gain, uint8_t sp_drv)
Set Audio Library Mode to BaseBand Through.
static AudioClass * getInstance()
Get instance of AudioClass for singleton.
Definition: Audio.h:123
err_t writeFrames(PlayerId id, uint8_t *data, uint32_t write_size)
Write Stream Data from buffer.
err_t initPlayer(PlayerId id, uint8_t codec, uint32_t fs, uint8_t bitlen, uint8_t channel)
Initialize player.
err_t initPlayer(PlayerId id, uint8_t codec, uint32_t fs, uint8_t channel)
Initialize player.
err_t setRecorderMode(uint8_t input_device)
Set Audio Library Mode to Sound Recorder.
err_t initPlayer(PlayerId id, uint8_t codec, const char *codec_path, uint32_t fs, uint8_t bitlen, uint8_t channel)
Initialize player.
err_t writeFrames(PlayerId id, int fd)
Write Stream Data from a file to FIFO by some frames.(now 5 frames)
ThroughI2sOut
I2S output select parameter at baseband through mode.
Definition: Audio.h:335
@ Mixer
Definition: Audio.h:337
@ Mic
Definition: Audio.h:338
@ None
Definition: Audio.h:336
The File class allows for reading from and writing to individual files on the File System.
Definition: File.h:55
unsigned int err_t
Definition: Audio.h:108