2

I have an Arduino MKR Zero with an UDA1334 I2S module, alongside 2 Speakers and I am trying to play Stereo sound. So far everything seems to work well, connections are also properly done, and i can play wav files. But i also want to be able to play sound either on the right channel only or sometimes only on the left channel. I tried to use audacity to make sounds only on the right channel for example, but when i play the .wav file, i still get the sound on both speakers. How can i fix this please? Is there any syntax to play sound only on the right channel? Thank you.

PS. TestR.wav is a only on the right channel.

#include <SD.h>
#include <ArduinoSound.h> 

const char filename[] = "testR.wav";
SDWaveFile waveFile;

void setup() {
   Serial.begin(9600);
   while (!Serial){;};

   Serial.print("Initializing SD card...");
   if (!SD.begin(28)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card is valid.");
  waveFile = SDWaveFile(filename);   // create a SDWaveFile
//  Serial.println(typeof(waveFile));
 if (!waveFile) {
    Serial.println("wave file is invalid!");
    while (1); // do nothing
  }

// print out some info. about the wave file
  
Serial.print("Bits per sample = ");
Serial.println(waveFile.bitsPerSample());
long channels = waveFile.channels();
Serial.print("Channels = ");
Serial.println(channels);
long sampleRate = waveFile.sampleRate();
Serial.print("Sample rate = ");
Serial.print(sampleRate);
Serial.println(" Hz");
long duration = waveFile.duration();
Serial.print("Duration = ");
Serial.print(duration);
Serial.println(" seconds");

AudioOutI2S.volume(100);

 if (!AudioOutI2S.canPlay(waveFile)) {
    Serial.println("unable to play wave file using I2S!");
    while (1); // do nothing
  }
 Serial.println("starting playback");
  AudioOutI2S.play(waveFile); 
}

void loop() {
  if (!AudioOutI2S.isPlaying()) {
    Serial.println("playback stopped");
    while (1); 
  }
}
Swedgin
  • 240
  • 2
  • 8
Mr. Chin
  • 21
  • 3
  • 1
    Can you at least, at the very minimum, post your code? – Swedgin Jun 07 '21 at 08:26
  • 2
    Sure, there you go! @Swedgin. – Mr. Chin Jun 07 '21 at 10:45
  • I went throught that library and I doens't seem like there is functionality to do what you want. `channels()` returns hardcoded `2` lol (I think that's the left and right channel). You'll have to write your own function to split the two. I don't know how `SDWaveFile` looks like (how the data is presented), so can't help you with that. – Swedgin Jun 07 '21 at 15:21
  • Thank you @Swedgin – Mr. Chin Jun 08 '21 at 08:15

0 Answers0