In examples-> AmebaMultimedia-> RecordMP4->AudioOnly , we use the mp4.begin() to recording audio file. but if doing once examples SDCardplayMP3 and wait for playing done, then call mp4.begin() again will never work again.
It seems like you have started the second recording before completing the first recording. Kindly ensure that you have inserted adequate delay interval (>=recording duration) between two consequent recordings.
Thanks for your reply, We’re sure the first recording is finish, and between first and second recording we playing the example “Audio_test.mp3”, then the second recording will show Log like my statement 2, seems like not do some action like STORAGE_INIT…
Actually, If play Audio_test.mp3 first, then first recording will have same situation.
The duplicate recording and duplicate playing it look like good, but can’t recording after playing once.
Thanks for your description. I was able to replicate your issue based on your description. Here’s the workaround, you might need to split your play mp3 and record mp4 tasks into two separate functions, constructors for each tasks will be called separately within task specific function. This is to ensure deinitialization of the audio module and to avoid overlapping of underlying variables. Please refer to the example code below for testing,
#include "StreamIO.h"
#include "AudioStream.h"
#include "AudioEncoder.h"
#include "MP4Recording.h"
#include "AmebaFatFS.h"
#include "AmebaFatFSFile.h"
// Default audio preset configurations:
// 0 : 8kHz Mono Analog Mic
// 1 : 16kHz Mono Analog Mic
// 2 : 8kHz Mono Digital PDM Mic
// 3 : 16kHz Mono Digital PDM Mic
#define FILENAME "Audio_test"
void setup()
{
Serial.begin(115200);
playMP3();
recordMP4("1");
Serial.println("--------First Recording done");
playMP3();
recordMP4("2");
Serial.println("--------Second Recording done");
Serial.println("done");
}
void loop()
{
// do nothing
}
void playMP3(void)
{
AmebaFatFS fs;
File file;
Serial.println("Start to play mp3");
fs.begin();
file = fs.open(String(fs.getRootPath()) + String(FILENAME) + String(".mp3"));
file.close();
fs.end();
Serial.println("Play mp3 done");
}
void recordMP4(String c)
{
AudioSetting configA(0);
Audio audio;
AAC aac;
MP4Recording mp4;
StreamIO audioStreamer1(1, 1); // 1 Input Audio -> 1 Output AAC
StreamIO audioStreamer2(1, 1); // 1 Input AAC -> 1 Output MP4
// Configure audio peripheral for audio data output
audio.configAudio(configA);
audio.begin();
// Configure AAC audio encoder
aac.configAudio(configA);
aac.begin();
// Configure MP4 recording settings
mp4.configAudio(configA, CODEC_AAC);
mp4.setRecordingDuration(5);
mp4.setRecordingFileCount(1);
mp4.setRecordingFileName("TestRecordingAudioOnly" + c);
mp4.setRecordingDataType(STORAGE_AUDIO); // Set MP4 to record audio only
// Configure StreamIO object to stream data from audio channel to AAC encoder
audioStreamer1.registerInput(audio);
audioStreamer1.registerOutput(aac);
if (audioStreamer1.begin() != 0) {
Serial.println("StreamIO link start failed");
}
// Configure StreamIO object to stream data from AAC encoder to MP4
audioStreamer2.registerInput(aac);
audioStreamer2.registerOutput(mp4);
if (audioStreamer2.begin() != 0) {
Serial.println("StreamIO link start failed");
}
// Start recording MP4 data to SD card
mp4.begin();
delay(7000);
Serial.println("------------------------------");
Serial.println("- Summary of Streaming -");
Serial.println("------------------------------");
Serial.println("- Audio Information -");
audio.printInfo();
Serial.println("- MP4 Recording Information -");
mp4.printInfo();
}