程序立即结束,为什么

The program ends straight away, why?

本文关键字:为什么 结束 程序      更新时间:2023-10-16

这段代码应该反复检查Axiom键盘上D9滑块的状态,并使用它的值来控制频率的音高。

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;
}

你从不初始化modwheel,所以当while循环开始时,它的值是"随机的",即它可以为零,这会导致循环立即结束。

使用

do/while 循环来确保它至少有一个迭代,或者使用内部带有if的无限while (true)循环,以避免实际将0作为有效输入处理。