1

This code is supposed to repeatedly check the state of the D9 slider on an Axiom keyboard and use its value to control the pitch of a frequency.

int main()
{
    int note;
    int modwheel;
    float frequency;


    while (modwheel != 0)

    {
        note = aserveGetControl(74);
        modwheel = aserveGetControl(01);

        frequency = 440 * pow(2, (note-69) /12.0);
        aserveOscillator(1,frequency,1.0,0);
        aserveSleep(100);
    }



    return 0;
}
Neo
  • 203
  • 1
  • 11
  • 10
    You forgot to initialise `modwheel` before testing its value. You also forgot to enable your compiler's warnings. – Mike Seymour Nov 21 '14 at 15:32
  • 4
    You also forgot to decide whether you're using C or C++. – Paul R Nov 21 '14 at 15:37
  • Well it can be either. –  Nov 21 '14 at 15:38
  • Also note that `01` is an octal constant - it doesn't matter in this instance, but you need to be aware of it, otherwise you'll get very confused when one day you try to use a value such as `012`. – Paul R Nov 21 '14 at 15:40
  • It is C, I thought I'd tag it with both – Neo Nov 21 '14 at 15:56
  • Don't do that - C and C++ are very different languages and in general you will get very different answers for each. – Paul R Nov 23 '14 at 11:34

1 Answers1

3

You never initialize modwheel, so when the while loop starts, its value is "random", i.e. it can be zero, which causes the loop to end immediately.

Use a do/while loop to ensure it has at least one iteration, or use an infinite while (true) loop with an if inside to avoid actually handling 0 as valid input.

unwind
  • 391,730
  • 64
  • 469
  • 606