Software volume control
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 1
- Joined: Sun Oct 25, 2009 6:17 am
Software volume control
Hi there,
recently put together my Waveshield, thanks for this great kit and the clear instructions for assembly and great libraries and examples and lots of information here on this forum. Everything worked out of the box for me, which i didn't really expect would happen but ok thats great.
I want to do software volume control, un#defined the DVOLUME const in the AF_Wave library and that worked. But i get a popping noise when i change the volume. I tried with WaveHC as well, which required a bit more hacking than just the #define in AF_Wave, but with the same results. Have others experienced this as well, or maybe i've done something wrong? If this is expected, any tips on how to eliminate this popping?
thanks in advance
dave
recently put together my Waveshield, thanks for this great kit and the clear instructions for assembly and great libraries and examples and lots of information here on this forum. Everything worked out of the box for me, which i didn't really expect would happen but ok thats great.
I want to do software volume control, un#defined the DVOLUME const in the AF_Wave library and that worked. But i get a popping noise when i change the volume. I tried with WaveHC as well, which required a bit more hacking than just the #define in AF_Wave, but with the same results. Have others experienced this as well, or maybe i've done something wrong? If this is expected, any tips on how to eliminate this popping?
thanks in advance
dave
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Software volume control
the volume control is kinda iffy. and if you change the volume quickly you'll make a square wvae. so adjust it -slooowly- 

-
- Posts: 2
- Joined: Thu Mar 24, 2011 3:36 pm
Re: Software volume control
Hi there,
I am a new Arduino and Waveshield user and I know It has been a while since the last reply in this post, but I would like to know how to use volume control with WaveHC.
I tried "SoftVolumeHC", an example that came with WaveHC, but it wont compile in any way. This is what I get as error messages:
'class WaveHC has no member named volume'
SoftVolumeHC.cpp: In function 'void playcomplete(FatReader&)':
SoftVolumeHC:109: error: 'class WaveHC' has no member named 'volume'
SoftVolumeHC:112: error: 'class WaveHC' has no member named 'volume'
SoftVolumeHC:113: error: 'class WaveHC' has no member named 'volume'
SoftVolumeHC:114: error: 'class WaveHC' has no member named 'volume'
If somebody has any clue about it, I'd be very glad to hear it.
Thanks in advance,
Rafael Vasconcelos
I am a new Arduino and Waveshield user and I know It has been a while since the last reply in this post, but I would like to know how to use volume control with WaveHC.
I tried "SoftVolumeHC", an example that came with WaveHC, but it wont compile in any way. This is what I get as error messages:
'class WaveHC has no member named volume'
SoftVolumeHC.cpp: In function 'void playcomplete(FatReader&)':
SoftVolumeHC:109: error: 'class WaveHC' has no member named 'volume'
SoftVolumeHC:112: error: 'class WaveHC' has no member named 'volume'
SoftVolumeHC:113: error: 'class WaveHC' has no member named 'volume'
SoftVolumeHC:114: error: 'class WaveHC' has no member named 'volume'
If somebody has any clue about it, I'd be very glad to hear it.
Thanks in advance,
Rafael Vasconcelos
-
- Posts: 2
- Joined: Thu Mar 10, 2011 9:10 pm
Re: Software volume control
It compiles if you change DVOLUME to nonzero in the WaveHC.h file (from zero to one, for example). This step is in the comment right above the line that the compiler has an issue with, near the bottom of the sketch:
Reading the comments in the sketch is a good thing to do when you're a noob (finding this out myself, as I'm also a noob). 
Code: Select all
// DVOLUME must be nonzero in WaveHC.h to use volume.
Serial.println(wave.volume, DEC);
delay(2000);
wave.volume++;
if ( wave.volume == 12) {
wave.volume = 0;
}
}
sdErrorCheck();
}

-
- Posts: 2
- Joined: Thu Mar 24, 2011 3:36 pm
Re: Software volume control
thanks, mtague, for the help. It is working now very nicely.
Yes, you're right about reading the comments. But I am quite sure I read it, but of course I missed it. I'll pay more attention next time.
Thanks again. Best regards,
Rafael Vasconcelos
Yes, you're right about reading the comments. But I am quite sure I read it, but of course I missed it. I'll pay more attention next time.
Thanks again. Best regards,
Rafael Vasconcelos
-
- Posts: 2
- Joined: Thu Mar 10, 2011 9:10 pm
Re: Software volume control
I was actually having the exact same problem you were, but reading your post made me recheck the code again and I found that sneaky little code comment. 

- maurin
- Posts: 6
- Joined: Wed May 20, 2009 1:05 pm
Re: Software volume control
I'm trying to use wave.volume but each time I change the value I get a clic 

- adafruit_support_bill
- Posts: 85866
- Joined: Sat Feb 07, 2009 10:11 am
Re: Software volume control
the volume control is kinda iffy. and if you change the volume quickly you'll make a square wvae. so adjust it -slooowly-
- maurin
- Posts: 6
- Joined: Wed May 20, 2009 1:05 pm
Re: Software volume control
Below the code i use, I added a fadeIn fadeOut fonction.
The delay between each wave.volume changes is set @ 500 millis but I still have those clic.
Is ther a way to avoid it ?
The delay between each wave.volume changes is set @ 500 millis but I still have those clic.
Is ther a way to avoid it ?
Code: Select all
#include "WaveUtil.h"
#include "WaveHC.h"
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader file; // This holds the information for the file we're play
WaveHC wave; // This is the only wave (audio) object...
# define THRESHOLD 250 // define threshold
# define fadeTime 500 // define fade time
boolean rising = false;
boolean fade = false; // set the fade direction IN - OUT
boolean DEBUG = true;
unsigned int reading = 0;
unsigned int fadeValue = 12; // hold fade value
unsigned long lastTime = 0; // hold time value
unsigned int volume = 0; // hold volume value
/////////////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600); // set up serial port
putstring_nl("WaveHC IR sensor");
// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT); // SLAVESELECT
pinMode(3, OUTPUT); // CLOCK
pinMode(4, OUTPUT); // DATA
pinMode(5, OUTPUT); // GND
pinMode(13, OUTPUT); // LED pin also SCK pin for (ISP)
if(!card.init()) { // play with 8 MHz spi (default faster!)
putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
while(1); // then 'halt' - do nothing!
}
card.partialBlockRead(true); // enable optimize read
// Now we will look for a FAT partition!
uint8_t part;
for(part = 0; part < 5; part++) { // we have up to 5 slots to look in
if(vol.init(card, part))
break; // we found one, lets bail
}
if(part == 5) { // if we ended up not finding one :(
putstring_nl("No valid FAT!");
while(1); // then 'halt' - do nothing!
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?
// Try to open the root directory
if(!root.openRoot(vol)) {
putstring_nl("Can't open root dir!"); // Something went wrong,
while(1); // then 'halt' - do nothing!
}
putstring_nl("Ready!"); // Whew! We got past the tough parts.
}
/////////////////////////////////////////////////////////////////////////////////
void loop(){
reading = analogRead(A0);
if(reading < THRESHOLD && rising == true){
if(DEBUG)Serial.println("OFF");
rising = false;
}
if(reading > THRESHOLD && rising == false){
if(DEBUG)Serial.println("ON");
rising = true;
playfile("LOOP.WAV");
}
wave.volume = fadeInOut(fadeTime, rising, fadeValue);
}
/////////////////////////////////////////////////////////////////////////////////
void playfile(char *name){
// see if the wave object is currently doing something
if(wave.isplaying) { // already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if(!file.open(root, name)) {
putstring("Couldn't open file");
Serial.print(name);
return;
}
// OK read the file and turn it into a wave object
if(!wave.create(file)){
putstring_nl("Not a valid WAV");
return;
}
wave.play(); // ok time to play! start playback
}
////////////////////////////////////////////////////////////
unsigned int fadeInOut(const int del, boolean fade, unsigned int &fadeVal){
if(fade == true){ // fade IN
if(fadeVal < 1) return 0;
if((millis() - lastTime) > del){
fadeVal--;
lastTime = millis();
if(DEBUG)Serial.println(fadeVal, DEC);
return fadeVal;
}
}
if(fade == false){ // fade OUT
if(fadeVal > 11) return 12;
if((millis() - lastTime) > del){
fadeVal++;
lastTime = millis();
Serial.println(fadeVal, DEC);
return fadeVal;
}
}
}
- adafruit_support_bill
- Posts: 85866
- Joined: Sat Feb 07, 2009 10:11 am
Re: Software volume control
Anytime you have a step-change in the output level there will be a click. The best you can do is to keep the step levels as small as possible.
-
- Posts: 593
- Joined: Wed Dec 24, 2008 1:54 pm
Re: Software volume control
The volume steps in WaveHC are large so there are clicks.
I worked with an artist to develop a player with finer volume control based on my other audio library, WaveRP.
It is limited to 22.05 ksps files due to the overhead of finer volume control and is very experimental.
It tries to do one db steps in volume.
You need to install the latest version of SdFat to use it.
http://code.google.com/p/sdfatlib/downloads/list
I have attached the library.
See the readme file and try the sketch, dapRPvol.pde.
I worked with an artist to develop a player with finer volume control based on my other audio library, WaveRP.
It is limited to 22.05 ksps files due to the overhead of finer volume control and is very experimental.
It tries to do one db steps in volume.
You need to install the latest version of SdFat to use it.
http://code.google.com/p/sdfatlib/downloads/list
I have attached the library.
See the readme file and try the sketch, dapRPvol.pde.
- Attachments
-
- dbPerStep.zip
- (14.06 KiB) Downloaded 149 times
-
- Posts: 16
- Joined: Fri Sep 28, 2012 7:38 am
Re: Software volume control
Hi man, I'm trying this library but, after the installation, I can't compile due to this error:
'Class WaveRP' has no member named 'setVolume'
DBperStep.cpp: In function 'void play(SdBaseFile*)':
DBperStep:104: error: 'class WaveRP' has no member named 'setVolume'
DBperStep:116: error: 'class WaveRP' has no member named 'setVolume'
Thanks man, I hope this library will solve my volume changing problems
'Class WaveRP' has no member named 'setVolume'
DBperStep.cpp: In function 'void play(SdBaseFile*)':
DBperStep:104: error: 'class WaveRP' has no member named 'setVolume'
DBperStep:116: error: 'class WaveRP' has no member named 'setVolume'
Thanks man, I hope this library will solve my volume changing problems

-
- Posts: 16
- Joined: Fri Sep 28, 2012 7:38 am
Re: Software volume control
Sorry, i forgot to set DVOLUME 1 in the library, my fault 
Anyway now it works well, tnx for the library!

Anyway now it works well, tnx for the library!
Please be positive and constructive with your questions and comments.