Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
Unable to save large array of data into File
-
I am trying to find FFT values for microphone data(stereo data) and save it into a file. The number of samples present are 512. I am trying to print those data on console. But I get the below error.
Even when I try to save the data into file I get the same error.Any help would be really appreciated.
Below is the code snippet:
/*
- MainAudio.ino - FFT Example with Audio (Peak detector)
- Copyright 2019 Sony Semiconductor Solutions Corporation
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <MP.h>
#include <Audio.h>
#include <File.h>File myFile; /**< File object */
AudioClass *theAudio;
/* Select mic channel number */
//const int mic_channel_num = 1;
const int mic_channel_num = 2;
//const int mic_channel_num = 4;const int subcore = 1;
struct Request {
void *buffer;
int sample;
int channel;
};struct Result {
float fft_value[512];
//float peak[mic_channel_num];
int channel;
};void setup()
{
Serial.begin(115200);
while (!Serial);Serial.println("Init Audio Library");
theAudio = AudioClass::getInstance();
theAudio->begin();myFile = File("/mnt/sd0/audio_data.txt", FILE_WRITE);
Serial.println("Init Audio Recorder");
/* Select input device as AMIC */
//theAudio->setRecorderMode(AS_SETRECDR_STS_INPUTDEVICE_MIC, 210);
theAudio->setRecorderMode(AS_SETRECDR_STS_INPUTDEVICE_MIC);/* Set PCM capture */
uint8_t channel;
switch (mic_channel_num) {
case 1: channel = AS_CHANNEL_MONO; break;
case 2: channel = AS_CHANNEL_STEREO; break;
case 4: channel = AS_CHANNEL_4CH; break;
}
theAudio->initRecorder(AS_CODECTYPE_PCM, "/mnt/sd0/BIN", AS_SAMPLINGRATE_48000, channel);/* Launch SubCore /
int ret = MP.begin(subcore);
if (ret < 0) {
printf("MP.begin error = %d\n", ret);
}
/ receive with non-blocking */
MP.RecvTimeout(1);Serial.println("Rec start!");
theAudio->startRecorder();
}void loop()
{
int8_t sndid = 100; /* user-defined msgid /
int8_t rcvid = 0;
Request request;
Result result;static const int32_t buffer_sample = 768 * mic_channel_num;
static const int32_t buffer_size = buffer_sample * sizeof(int16_t);
static char buffer[buffer_size];
uint32_t read_size;/* Read frames to record in buffer */
int err = theAudio->readFrames(buffer, buffer_size, &read_size);if (err != AUDIOLIB_ECODE_OK && err != AUDIOLIB_ECODE_INSUFFICIENT_BUFFER_AREA) {
printf("Error err = %d\n", err);
sleep(1);
theAudio->stopRecorder();
exit(1);
}if ((read_size != 0) && (read_size == buffer_size)) {
request.buffer = buffer;
request.sample = buffer_sample / mic_channel_num;
request.channel = mic_channel_num;
MP.Send(sndid, &request, subcore);
} else {
/* Receive detector results from SubCore */int ret = MP.Recv(&rcvid, &result, subcore); if (ret >= 0) { for (int i=0;i<mic_channel_num;i++) { //printf("%8.3f, ", result->peak[i]); for(int j=0; j<512;j++){ myFile.println(result[i].fft_value[j]); //printf("%8.3f\n", result[i].fft_value[j]); } printf("\n"); printf("\n"); } //printf("\n"); } myFile.close();
}
myFile = File("/mnt/sd0/audio_data.txt");
if (myFile) {
/* Read from the file until there's nothing else in it /
while (myFile.available()) {
Serial.write(myFile.read());
}
/ Close the file */
myFile.close();
}}
-
Hi @NavaneethRao-2,
Did you also modify the subcore code? If so, can you send it?
Best Regards,
Kamil Tomaszewski