So, from what I've read, it looks like you should be able to play two .RAW files at the same time. However, (from the two files on the SD) the first one loads, but the second doesn't. If I switch the order, then the other file plays--but not second. Am I doing something wrong in my code?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdRaw playRaw_sdHeartSound_A; // xy = 204.1999969482422, 193.99998474121094
AudioPlaySdRaw playRaw_sdHeartSound_B; // xy = 204.1999969482422, 280.20001220703125
AudioAnalyzeRMS rms_A; // xy = 452.20001220703125, 183.1999969482422
AudioAnalyzeRMS rms_B; // xy = 454.20001220703125, 310.20001220703125
AudioMixer4 mixer_SD; // xy = 505.20001220703125, 245.99998474121094
AudioOutputI2S i2s_speaker; // xy = 714.2000122070312, 284
AudioAnalyzePeak peak_QrsMeter; // xy = 722.2000122070312, 208.99998474121094
AudioConnection patchCord1( playRaw_sdHeartSound_A, rms_A );
AudioConnection patchCord2( playRaw_sdHeartSound_A, 0, mixer_SD, 0 );
AudioConnection patchCord3( playRaw_sdHeartSound_B, rms_A );
AudioConnection patchCord4( playRaw_sdHeartSound_B, 0, mixer_SD, 1 );
AudioConnection patchCord5( mixer_SD, peak_QrsMeter );
AudioConnection patchCord6( mixer_SD, 0, i2s_speaker, 0 );
AudioConnection patchCord7( mixer_SD, 0, i2s_speaker, 1 );
AudioControlSGTL5000 audioShield; // xy = 155.1999969482422, 354.00001525878906
// GUItool: end automatically generated code
#define inpA 0
#define inpB 1
bool equalizer = false;
float rmsA = 0.0f;
float rmsB = 0.0f;
uint32_t cnt = 0;
elapsedMillis fps;
const char *fileNameA = "HBMURMUR.RAW";
const char *fileNameB = "HBNORMAL.RAW";
Sd2Card card;
SdVolume volume;
bool reading = true;
bool playing = false;
void setup()
{
Serial.begin( 115200 );
SPI.setMOSI( 7 ); // Audio shield has MOSI on pin 7
SPI.setSCK( 14 ); // Audio shield has SCK on pin 14
if ( ( !card.init( SPI_FULL_SPEED, 10 ) ) || // Fail if SD is not on Audio shield on pin 10,
!( ( card.type() == SD_CARD_TYPE_SD1 ) // ...or if SD card is not of Type SD-1,
|| ( card.type() == SD_CARD_TYPE_SD2 ) // Type SD-2,
|| ( card.type() == SD_CARD_TYPE_SDHC ) ) ) // or Type SDHC.
{
Serial.println( "SD card is not connected or unusable" );
}
else
{
AudioMemory( 10 );
audioShield.enable();
audioShield.volume( 0.5 ); // sets headphone level (only); set between 0.5 - 0.8
if ( SD.begin( 10 ) )
{
Serial.println( "SD card is connected" );
fps = 0;
playing = true;
startPlaying( fileNameA, fileNameB );
}
}
}
void loop()
{
continuePlaying( fileNameA, fileNameB );
}
bool startPlaying( const char *fileA, const char *fileB )
{
bool returnState = true;
Serial.print( "\nEXECUTING startPlaying( " ); Serial.print( fileA ); Serial.println( " )" );
if ( SD.exists( fileA ) )
{
playRaw_sdHeartSound_A.play( fileA );
mixer_SD.gain( inpA, 0.5 );
Serial.print( "Playing " ); Serial.print( fileA ); Serial.print( " - " ); Serial.println( fps/1000.0 );
}
else
{
Serial.print( "Failed to play " ); Serial.println( fileA );
returnState = false;
}
// delay( 10 );
//
Serial.print( "\nEXECUTING startPlaying( " ); Serial.print( fileB ); Serial.println( " )" );
if ( SD.exists( fileB ) )
{
playRaw_sdHeartSound_B.play( fileB );
mixer_SD.gain( inpB, 0.5 );
Serial.print( "Playing " ); Serial.print( fileB ); Serial.print( " - " ); Serial.println( fps/1000.0 );
}
else
{
Serial.print( "Failed to play " ); Serial.println( fileB );
returnState = false;
}
Serial.println();
return returnState;
}
bool stoppedA = false;
bool stoppedB = false;
void continuePlaying( const char *fileA, const char *fileB )
{
if ( !playRaw_sdHeartSound_A.isPlaying() )
{
if ( !stoppedA )
{
playRaw_sdHeartSound_A.stop();
stoppedA = true;
Serial.print( fileA ); Serial.print( " ended - " ); Serial.println( fps/1000.0 );
}
}
if ( !playRaw_sdHeartSound_B.isPlaying() )
{
if ( !stoppedB )
{
playRaw_sdHeartSound_B.stop();
stoppedB = true;
Serial.print( fileB ); Serial.print( " ended - " ); Serial.println( fps/1000.0 );
}
}
if ( stoppedA && stoppedB && playing )
{
playing = false;
Serial.print( "*all play stopped* - " ); Serial.println( fps/1000.0 );
}
}