Arduino possibly failing to honor if/else logic

Using a Freeduino duemilanove analog, with Arduino 1.0.2 IDE, Adafruit WaveHC library and FFT library found here: http://neuroelec.com/2011/03/fft-library-for-arduino/

I am building a replica Ghostbusters Proton Pack with lights and sound. I would like to expand its functionality to be able to use ambient sound as a source for a visualizer effect on the various lights.

However, I've run into an unusual problem.

Here is my loop():

void loop()
{
  if(!equalizerMode)
  {
    cyclotron();
    powerCell();
    delay(1000/16);
  }
  else
  {
    //calcViz();
    doLowFreq();
    doHighFreq();
  }
}

equalizerMode is a boolean that will be true when the switch to enable this visualizer mode is "on." As I haven't wired up that switch yet, I am not actually checking and thus equalizerMode is always false, meaning what should happen is the first part of that if statement should be all that ever happens. As it is posted above, it works fine. However, if I un-comment the call to calcViz() (which will take input from the microphone, run a fast fourier transform (using the FFT library, and store the result to a global byte that will be used to determine how to light the lights) nothing works. The sounds don't play and the lights freeze.

Correct me if I'm wrong, but even though the input to calcViz() is just electronic noise, that part of the program never gets touched, since equalizerMode is always false. So, what could be causing this?

I can post the entire sketch, but it's fairly large, and I'm not sure if it's relevant, but if anyone wants to see it, I'll post it.

Side Note: The lights are controlled using shift registers. I can't use Serial output to try and debug, because for some reason, even enabling the Serial output (with a Serial.begin() call) causes the light patterns to lock up. Help with this would also be appreciated, although I don't actually need to read from Serial, so it's not a big deal for me if that doesn't get fixed.

Edit: cyclotron(), powerCell(), doHighFreq(), and doLowFreq() all simply take a global byte (for the first two, it's simply a counter, the second two use the result of calcViz()), and apply that to a preset byte array to choose what byte patterns to send to the shift registers, and then send it.

There's nothing wrong with if/else, or nothing would work.

I strongly suspect your FFT calculation, possibly buffer overrun, as that is what is causing it to fail.

I know, that's why I'm so confused. If equalizerMode is always false, then calcViz() should never run, correct? and the method is sitting in the code, so it should get compiled, unless the compiler sees that it's never called and doesn't bother. But, if the code is never called, is it possible for it to cause an overrun, or do anything else that could cause it to fail?

Oh, I see. If the code isn't called it may not even be included in the object file. See if the generated file size goes up markedly if you uncomment the line. One function call would only be about 3 bytes.

Say that the function has a lot of variables, and because of that it exceeds available RAM. Merely including the function could cause it to crash.

OK, I think you were right. That one call increased the sketch size by almost 1 kB. I looked into the FFT library, there's a define that sets how many "pools" it breaks the source into. I cut that in half, and it seems to have fixed the problem. Thanks!

qantravon:
Freeduino duemilanove analog,

I have never heard of such a thing. I suspect you just put random words together and didn't bother to post your entire code. Let's see the next immediate post. Oh.