Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hello,

I'm able to play a stereo wav file 16bit 44100hz with my esp32-audio-kit,
so I thought the board would be able to play 2 separate mono files and merge it for a stereo output ( 1 sound on left channel, the other on the right channel )

when I tried, the sound was stuttering.

I tried to use raw pcm audio so, but same issue
if I reduce the samplerate to 30000, the sound plays without stuttering.
Though I would like to be able to keep samplerate at 44100.

Has anyone tried this before ?
Reading 2 mono files takes more ressources than reading a stereo file?
I tried changing buffer size, with no improvement
I also tried to read sd card faster, then the sound speeds up for some reason...

You must be logged in to vote

The bottleneck is most likely the read speed of the SD library.
Try to increase the SPI frequency or switch to a more efficient library

Replies: 4 comments · 2 replies

Comment options

here's the code, with 2 mono wav files merged to stereo, at 22050hz samplerate
where sounds play fine :

#include <SPI.h>
#include <SD.h>
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/Disk/FileLoop.h"

const int chipSelect = PIN_AUDIO_KIT_SD_CARD_CS;

AudioInfo info(22050,2, 16);
InputMerge<int16_t> merge;
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
FileLoop loopingFile;
FileLoop loopingFile2;
EncodedAudioStream decoder(&loopingFile, new WAVDecoder());
EncodedAudioStream decoder2(&loopingFile2, new WAVDecoder());

StreamCopy copier(i2s, merge, 256); // 256-byte buffer

void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
auto config = i2s.defaultConfig(TX_MODE);
config.copyFrom(info);
config.sd_active = true;
config.buffer_size = 256; // 256-byte I2S buffer
config.buffer_count = 2; // Double buffering
i2s.begin(config);

SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO,
PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
SD.begin(chipSelect, SPI);
loopingFile.setFile(SD.open("/pinaVoix/voxNoise.wav"));
loopingFile2.setFile(SD.open("/birds/weirdBirds.wav"));
loopingFile.begin();
loopingFile2.begin();
merge.add(loopingFile, 1);
merge.add(loopingFile2, 1);
merge.begin(info);
decoder.begin();
decoder2.begin();

}
void loop() {
copier.copy();

}

You must be logged in to vote
0 replies
Comment options

The bottleneck is most likely the read speed of the SD library.
Try to increase the SPI frequency or switch to a more efficient library

You must be logged in to vote
2 replies
@KatePimbleton
Comment options

I did increase spi frequency, then the sound was playing faster

@KatePimbleton
Comment options

I will switch to sdmmc

Answer selected by pschatzmann
Comment options

switching to sdmmc solved the issue, here is a sample code:

#include "FS.h"
#include <SD_MMC.h>
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/Disk/FileLoop.h"

AudioInfo info(44100, 2, 16);
InputMerge<int16_t> merge;
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
FileLoop loopingFile;
FileLoop loopingFile2;
EncodedAudioStream decoder(&loopingFile, new WAVDecoder());
EncodedAudioStream decoder2(&loopingFile2, new WAVDecoder());

StreamCopy copier(i2s, merge, 512); // Larger buffer for stereo data

void setup() {
auto config = i2s.defaultConfig(TX_MODE);
config.copyFrom(info);
config.sd_active = true;
config.buffer_size = 256;
config.buffer_count = 2;
i2s.begin(config);
i2s.setVolume(0.7);

if (!SD_MMC.begin("/sdcard", true, true, SDMMC_FREQ_52M)) {
return;
}

File file1 = SD_MMC.open("/pinaVoix/voxNoise.wav");
if (!file1) {
return;
}

File file2 = SD_MMC.open("/birds/weirdBirds.wav");
if (!file2) {
file1.close();
return;
}

loopingFile.setFile(file1);
loopingFile2.setFile(file2);
loopingFile.begin();
loopingFile2.begin();

decoder.begin();
decoder2.begin();

merge.add(decoder, 1);
merge.add(decoder2, 1);
merge.begin(info);

uint8_t testBuffer[64];
decoder.readBytes(testBuffer, 64);
decoder2.readBytes(testBuffer, 64);
}

void loop() {
copier.copy();
}

You must be logged in to vote
0 replies
Comment options

Thanks a lot

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.