How to use converter to play 8-bit wav files using AudioPlayer? #2153
-
Problem DescriptionI don't understand how to use the format converter to play 8-bit wav files over I2C. Device DescriptionESP32S3 with ES8311 DAC SketchAudioBoard board{AudioDriverES8311, NoPins};
AudioBoardStream out(board);
AudioInfo info(16000,1,16);
AudioSourceIdxSDMMC source("/Audio", "wav", true);
MultiDecoder multi;
WAVDecoder wav;
AudioPlayer player(source, out, multi);
bool play_file(char *filename, float volume)
{
if (!SD_MMC.exists(filename)) {
Serial.println("play_file: '" + String(filename) + "' does not exist");
return false;
}
player.end(); // stop previous if any
player.setAutoNext(false);
player.setPath(filename);
return player.begin();
}
void setup()
{
Serial.begin(115200);
// wait for Serial to be ready
while (! Serial);
Serial.println();
DriverPins pins; // no pin definition
pins.addI2C(PinFunction::CODEC, Wire, true);
pins.addPin(PinFunction::PA, PAPIN, PinLogic::Output); // Power Amplifier
PinsI2S PinsI2S(PinFunction::CODEC, MCLKPIN, BCLKPIN, WSPIN, DOPIN, DIPIN);
pins.addSPI(PinFunction::SD, SDMMC_CLK, SDMMC_CMD, SDMMC_DATA, -1, SPI);
pins.addI2S(PinsI2S);
board.setPins(pins);
// start I2S & codec
Serial.println("starting I2S...");
auto config = out.defaultConfig();
config.copyFrom(info);
// define I2S pins if you dont want to use the default pins
config.pin_bck = BCLKPIN;
config.pin_ws = WSPIN;
config.pin_data = DOPIN;
config.pin_mck = MCLKPIN;
config.rx_tx_mode = TX_MODE;
config.input_device = ADC_INPUT_NONE; // no input
config.output_device = DAC_OUTPUT_ALL; // use both channels of the internal dac
config.sd_active = true;
config.use_apll = true; // use APLL for better clock
config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT; // two channel
if (!out.begin(config)) {
Serial.println("I2S failed to start!");
return false;
}
// additinal settings
out.setVolume(0.8);
Serial.println("I2S started...");
play_file("/Audio/danger.wav",1.0); // play test sound
}
void loop()
{
player.copy();
} Other Steps to ReproduceMy WAV files are 8K, mono, 8-bit and sound like noise when played. Debug logging:
What is your development environment (incl. core version info)No response I have checked existing issues, discussions and online documentation
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I guess there are quite a few possibilities that might work: e.g. ps: this is not a bug in my code, so it shuld be a discussion and not an issue! |
Beta Was this translation helpful? Give feedback.
-
To make things a bit simpler, I extended the WAVDecoder to automatically convert 8 bit data to 16 bits and tested the functioniality today! |
Beta Was this translation helpful? Give feedback.
I guess there are quite a few possibilities that might work: e.g.
a) use a CodecChain consisting of a WAVDecoder and a DecoderL8;
b) Instead of sending the output to I2SStream send it to a NumberFormatConverterStreamT<uint8_t, int16_t> nfc(out);
ps: this is not a bug in my code, so it shuld be a discussion and not an issue!