[英]How can I capture audio signal from two channels with QAudioInput
我想使用QAudioInput.Audio捕获来自音频设备的声音。我有一个立体声(两个声道)输入信号,通常我只调用了setChannelCount()函数,带有声道数,在这种情况下为2。我的目标是保存来自文件1中通道1的信号和来自文件2中通道2的信号。我的问题是如何分离两个信号。
Judging from the documentation of QAudioInput
, you would need your own specialization of QIODevice
in which you would override writeData
in order to fan the data out into 2 files. 从QAudioInput
的文档QAudioInput
,您将需要自己的QIODevice
,其中您将重写writeData
以便将数据展开为2个文件。 I haven't tried to compile this but it should give you the general idea. 我没有尝试编译它,但是它应该给您大致的想法。
class MyIODevice : public QIODevice
{
public:
MyIODevice(QIODevice* file1, QIODevice* file2)
: m_file1(file1), m_file2(file2) {}
qint64 writeData(const char* data, qint64 maxSize)
{
// for 32-bits with the channels interleaved.
// I'm also making an assumption that QAudioInput will call this with
// a complete frame of data.
for (int i = 0; i < maxSize / 8; ++i)
{
m_file1->writeData(data, 4);
data += 4;
m_file2->writeData(data, 4);
data += 4;
}
}
private:
QIODevice* m_file1;
QIODevice* m_file2;
};
As written this would only work with one audio format but could easily be made more general by passing some parameters about the format to the constructor, etc... 如所写,这仅适用于一种音频格式,但是可以通过将有关格式的一些参数传递给构造函数等轻松地变得更通用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.