Qt 不同频率的蜂鸣音
如何在Qt 不同频率的蜂鸣音,qt,Qt,如何在Qt中以不同频率生成音频。 对于ex,在下面的代码中,我在三种情况下使用相同的频率beep 但是,我需要三种不同的声音来表示三种情况 if(a_vertical> LevelOne ) { QApplication::beep(); } else if(a_vertical> LevelTwo ) { QApplication::beep(); } else { QA
Qt
中以不同频率生成音频。
对于ex,在下面的代码中,我在三种情况下使用相同的频率beep
但是,我需要三种不同的声音来表示三种情况
if(a_vertical> LevelOne )
{
QApplication::beep();
}
else if(a_vertical> LevelTwo )
{
QApplication::beep();
}
else
{
QApplication::beep();
}
您不能直接在Qt中执行此操作。如果您使用的是Windows,则可以使用window.h软件包执行
蜂鸣音(频率,毫秒)
然而,在Qt中,还有其他几种方法可以操纵声音
#define FREQ_CONST ((2.0 * M_PI) / SAMPLE_RATE)
QByteArray* bytebuf = new QByteArray();
buf->resize(seconds * SAMPLE_RATE);
for (int i=0; i<(seconds * SAMPLE_RATE); i++) {
qreal t = (qreal)(freq * i);
t = t * FREQ_CONST;
t = qSin(t);
// now we normalize t
t *= TG_MAX_VAL;
(*bytebuf)[i] = (quint8)t;
}
// Make a QBuffer from our QByteArray
QBuffer* input = new QBuffer(bytebuf);
input->open(QIODevice::ReadOnly);
// Create an output with our premade QAudioFormat (See example in QAudioOutput)
QAudioOutput* audio = new QAudioOutput(format, this);
audio->start(input);