Go Down

Topic: Dual Channel Audio Synthesis (Read 356 times) previous topic - next topic

Cosford

Dec 24, 2014, 12:51 pm Last Edit: Dec 24, 2014, 12:52 pm by Cosford
Hi, I'm hoping someone may be able to give me some advice.

I'm developing something that I intend to deploy to PCB to incorporate as part of a project I'm working on. I wish to generate two channels of mono audio (seperate tracks), probably from an SD card. File format etc aren't of any real concern, nor do I have any real requirement for particularly good quality (although that's always a plus).

I've messed around with the TMRpcm library and had that working reasonably, although every now and then it seems to have a hiccup and requires resetting. I've been unable thus far to work out exactly why and when this is being a problem, but quality isn't particularly amazing either and so I'm looking at other options.

Is there any solutions out there to generating two channels of mono audio (independent of one another such that they can be started and stopped independently)?

Thanks in advance,
Iestyn.

CrossRoads

How about 2 MP3 modules? Send serial messages to each to tell them what track to play.
http://www.mdfly.com/search.php?search_query=mp3
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Paul Stoffregen

Is there any solutions out there to generating two channels of mono audio (independent of one another such that they can be started and stopped independently)?
My audio library can give you this.

http://www.pjrc.com/teensy/td_libs_Audio.html

You'd use two of these player objects:

http://www.pjrc.com/teensy/gui/?info=AudioPlaySdRaw

Just run both of their outputs into a mixer object:

http://www.pjrc.com/teensy/gui/?info=AudioMixer4

Then connect the mixer output to the DAC object:

http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog

The audio will come out of the DAC/A14 pin.

The main caveat is this requires Freescale's 32 bit ARM chips, which is more expensive than the cheaper Atmel 8 bit chips.  But it's a lot more affordable than 2 MP3 modules.

It's also pretty easy to add a 3rd and 4th player, as long as you're using a good SD card that can keep up with so many non-sequential accesses (many cheap "class 10" cards are only fast for sequential access).

You could also connect this fader object between each player and the mixer, to allow smoothly transitioning the sound from one stream to the other.

http://www.pjrc.com/teensy/gui/?info=AudioEffectFade

Cosford

#3
Dec 29, 2014, 11:58 am Last Edit: Dec 29, 2014, 02:13 pm by Cosford
Thanks for the replies.

@CrossRoads Unfortunately, running 2 seperate MP3 modules (or other formats) isn't really feasible due to the high requirements on PCB space, cost and necessity for 2 seperate SD cards.

@Paul This looks very interesting. I will have a look into Teensy and your library but your solution seems near perfect. In terms of program size, how much program space would I have left to work with using a pair of player objects set up as you've recommended? Likewise with RAM usage?
It might be feasible for me to absorb the code I was intending to run on the ATmega into the Teensy chip as it's there anyway.

Regards,
Iestyn.

Paul Stoffregen

In terms of program size, how much program space would I have left to work with using a pair of player objects set up as you've recommended? Likewise with RAM usage?
With the latest 1.21-test2 version:

Code: [Select]

Binary sketch size: 24,768 bytes (of a 262,144 byte maximum)
Estimated memory use: 8,152 bytes (of a 65,536 byte maximum)


The size with version 1.20 is slightly larger.

I compiled this code, which plays 2 songs together (which sounds terrible, to be honest):

Code: [Select]

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

AudioPlaySdWav           playWav1;
AudioPlaySdWav           playWav2;
AudioMixer4              mixLeft;
AudioMixer4              mixRight;
AudioOutputI2S           i2s1;
AudioConnection          patchCord1(playWav1, 0, mixLeft, 0);
AudioConnection          patchCord2(playWav1, 1, mixRight, 0);
AudioConnection          patchCord3(playWav2, 0, mixLeft, 1);
AudioConnection          patchCord4(playWav2, 1, mixRight, 1);
AudioConnection          patchCord5(mixLeft, 0,  i2s1, 0);
AudioConnection          patchCord6(mixRight, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;

void setup() {
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.6);
  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  mixLeft.gain(0, 0.5);
  mixLeft.gain(1, 0.5);
  mixRight.gain(0, 0.5);
  mixRight.gain(1, 0.5);
}

void loop() {
  playWav1.play("SDTEST1.WAV");
  delay(4000);
  playWav2.play("SDTEST2.WAV");  // start playing a 2nd file 4 seconds later
  delay(500000);
}

Cosford

Brilliant. I received my Teensy today and put together a sketch using your example and it's working great. Quality is definitely good enough for our requirements.
Even using these cheap chinese SD cards, I was able to have 3 tracks simultaneously with no particularly noticeable issues. I have noticed though, a (rather quiet but just about noticeable) high-ish pitch buzzing when a track is being played (even with just a single track). I don't believe it's an issue with the samples as it plays without this noise fine from my PC.

Is this just a characteristic of the on-board DAC? Or likely to be a hardware issue? I've attempted to use a 10uF electrolytic cap as a DC blocker, but this doesn't appear to have made any real difference.

Power is being supplied via the USB connector. Doesn't seem to be a huge amount of ripple on it, but I added an additional 10uF electrolytic across the 3.3v and GND rails anyway.

Thanks once again.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy