After we can access the Internet purely using IDF functionality w/o Arduino, the final challange is to provide access to files as Streams!

IDF provides the concept of the Virtual File System (VFS): you can mount a file system under a name and access the files of that file system using the name as prefix. For this the POSIX file API is supported and therefore we have all standard C and C++ file methods available.

To use the files in the AudioTools, I created the following (easy to use) VFS classes:

and for the AudioPlayer I created the new AudioSourceVFS class, that requires the VFS as parameter and that we can use to define the audio source for the AudioPlayer.

Example Arduino Sketch

Here is a short demo that provides the first 10 files via the VFS SPI SD:

#include "AudioTools.h"
#include "AudioTools/Disk/AudioSourceVFS.h"
#include "AudioTools/Disk/VFS_SDSPI.h"

//  We use an AudioKit or LyraT for the tests which uses the following pins
//  CS,  MOSI,  MISO,  SCK
VFS_SDSPI sd(13, 15, 2, 14);
AudioSourceVFS source(sd, "/sdcard", ".mp3");

void setup() {
  Serial.begin(115200);
  AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);

  source.begin();
  for (int j = 0; j < 10; j++) {
    VFSFile* p_file = (VFSFile*)source.selectStream(j);
    if (p_file)
      Serial.println(p_file->name());
  }
}

void loop() {}

Since the IDF is part of the Arduino API, you can use this functionality also in Arduino.

With this functionality you are now able to build a working audio file player in IDF as well.

Dependencies

Source Code

You can find the actual version of the source code for this example on Github!

Categories: Machine Sound

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *