Change volume of sample while its playing

Status
Not open for further replies.
In your code, I did not see:

Code:
pinmode (5, OUTPUT);
digitialWrite (5, HIGH);

which enables the amplifier.

On the prop shield, the following pins are used to enable features:
  • Pin 2 -- usable as an interrupt pin if the i2c sensors on the full featured prop shield have new data;
  • Pin 5 -- enable amplifier;
  • Pin 6 -- enable flash memory SPI calls;
  • Pin 7 -- enable LED buffers for ws2812b/apa102 LEDs.

If you use both the flash memory and the LED buffers (or some other SPI device), you need to set the appropriate pin to LOW when the flash/LEDs are not in use, to allow the other device access.
 
I've got this which covers that. Eventually I will be doing some LED stuff, so that's good to know as well, but this example excludes all other code.
Code:
#define PROP_AMP_ENABLE    5
#define FLASH_CHIP_SELECT 6

// Enable the amplifier on the prop shield
  pinMode(PROP_AMP_ENABLE, OUTPUT);
  digitalWrite(PROP_AMP_ENABLE, HIGH);
 
Sorry, typed incorrectly. The speaker clicks at the same delay set in the code but the actual sound effect that I loaded does NOT play. It's just a click. I thought maybe the delay was too short and it was interrupting itself, but even with a longer delay, there is still only a clicking sound.
 
This file is short. Maybe write a small program than reads and prints its data, or perhaps the first 1000 bytes. Then compare against the original.

Or you could try running one of the library's examples that doesn't require reading files, with a slight modification to send to the DAC instead of I2S. The idea is to be able to test individual parts, to determine which are working, so you know where to focus your effort. At least hearing it make sound (or not) with code that doesn't read a file could help to know if the audio output actually works.
 
Ah, good stuff, thank you. I got the pulse width example working quickly and it played the pulse correctly. So, the problem must be in my files. I'll look and see if I'm missing some spec for the audio.
 
Ok, update for you guys. Thank you all for your help. A couple of things. Looks like the audio conversion app I was using was the culprit, eventhough it theoretically should have been the same as Audacity. I tried Audacity and that seemed to be the correct fix once I got it to 16-bit.
After that, the 5.0f gain was distorting the audio to the point where it was unrecognizable. but once I took it to 1.0f, I could hear the sounds correctly, just not as loud as I'd like.

Thanks again for the help everyone! This project can finally move forward!
 
Question about variable

Maybe a newbie question... What does the "f" represent here?

// Set initial volume
// mixer1.gain(0, 0.5f);
 
A newbie question, yes, showing that you didn't yet dive deeply enough into the basics of C/C++. The f postfix tells the compiler to see the number as a float format.
 
OK, I figured it was just another way to declare a float, which I am doing as follows:

float gestureVol = x (or whatever calculation I need)

I can dig into this some more.
 
Status
Not open for further replies.
Back
Top