Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Adafruit AudioFX Sound board Serial response time
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit AudioFX Sound board Serial response time

by SilverwolfMD on Mon Aug 10, 2020 8:17 pm

I'm presently working on a replica prop, and I have it making sounds depending on user actions. I have the Adafruit AudioFX sound board on pins 12 and 13 of an Arduino Uno for RX and TX, and pin 7 tied in as the reset.

I keep running into the problem of failed sound commands during use. In the program, I expect that at some point, the user will initiate an action that requires that a sound start playing when another sound is currently playing. So, what I'm looking for is a way to:
1) rapidly acquire the status of the sound board (like a method which instructs the board to tell me whether or not a file is playing).
2) If a sound is playing, stop it immediately.
3) Start playback of the requested sound.

Here's the code for the function:
Code: Select all | TOGGLE FULL SIZE
void SndInfoStop(SndInfo sound, bool &mode){ // handles rapid sound transition as events rapidly change, written for the SndInfo class

    //begin SndInfoStop;
    if(!snd.playTrack((mode ? sound.tFileName : sound.fileName))){
      Serial.println("Sound stopped, delay?");
      snd.stop();
      delay(100);
      if(!snd.playTrack((mode ? sound.tFileName : sound.fileName))){
        Serial.println("Playback Fail");
      }
    }
    else{
      Serial.println("sound played");
    }
}//end SndInfoStop


The Serial.println calls are for debugging. The time consuming part seems to be when I throw another snd.playTrack call behind an existing call. I'm looking for a better method that just gives me a simple flag and tells me whether the sound board is playing a sound and ready to receive commands. I don't mind some delays, but when it gets to half a second or so, it interferes with other operations.

SilverwolfMD
 
Posts: 3
Joined: Thu Jul 16, 2020 12:16 pm

Re: Adafruit AudioFX Sound board Serial response time

by Disciple on Mon Aug 10, 2020 9:05 pm

Hi, another hobbyist here.
If your Arduino has a GPIO pin available, you can use it to read the ACT pin on the FX board. It goes low when playback's in progress. That might shorten the response time. Hope this helps.

Hallelujah!
Disciple

Disciple
 
Posts: 757
Joined: Tue Jan 06, 2015 8:13 pm

Re: Adafruit AudioFX Sound board Serial response time

by SilverwolfMD on Tue Aug 11, 2020 12:26 pm

Thanks for the advice about the ACT pin, I completely forgot about it.
On the plus side, it helped me clean up my code. The function I have to simplify things now looks like this:
Code: Select all | TOGGLE FULL SIZE
void Sound (SndInfo sound, bool interrupt, bool mode){ // handles sound playback, and if necessary, stopping previous sound

//  snd.playTrack((mode ? sound.tFileName : sound.fileName)); // template line

  if (interrupt && sndPins[0] == LOW){ // intervention required only if the interrupt flag is set and a sound is playing
    Serial.println("sound in progress");
    while(!snd.stop()){
      CounterWrite(ammo);
      Serial.println("stopping...");
    }
    CounterWrite(ammo);
    while(sndPins[0] == LOW){ // null loop, should terminate as soon as the activity pin indicates ready state
      CounterWrite(ammo);
    }
    snd.playTrack((mode ? sound.tFileName : sound.fileName));
  }
  else{
    while(sndPins[0]==LOW){ // safety as earlier, no interrupt needed. In this state, the function waits its turn.
      CounterWrite(ammo);
    }
    snd.playTrack((mode ? sound.tFileName : sound.fileName)); // playback
  }

}


Code: Select all | TOGGLE FULL SIZE
sndPins[0]
is the GPIO pin connected to the ACT pin on the board.
Also, the frequent calls to
Code: Select all | TOGGLE FULL SIZE
CounterWrite()
are due to the nature of the counter: it's a 2-digit 7-segment counter driven by a 74HC595N shift register and an SN7414N hex schmitt trigger inverter.
Code: Select all | TOGGLE FULL SIZE
 CounterWrite();
takes the integer parameter and lights one digit, then the other in rapid-fire succession. In the loop, this is fast enough to make both digits appear to be illuminated simultaneously. When I get lag events, it frequently only shows one digit illuminated until the event passes. Adding additional calls seems to mitigate this in parts.

However, even when monitoring the ACT pin (so the program doesn't send a command at the inappropriate time), the
Code: Select all | TOGGLE FULL SIZE
snd.stop()
call doesn't seem to work. What I expect to happen is that if the interrupt parameter is set to true, the program will check for activity, and if present, transmit a stop command to stop the current playback before sending the play command for the requested sound. The sound should appear to stop immediately and then the new sound begins (although this accounts for a few ms of time between the stop and starts to account for transmission and processing).

I have a feeling that the solution is just one of those things that's so simple but I'm not seeing it, any fresh perspectives will help!

SilverwolfMD
 
Posts: 3
Joined: Thu Jul 16, 2020 12:16 pm

Please be positive and constructive with your questions and comments.


cron