WaveIn
BCC32C/BCC64编译器非常简单的音频采集类
描述
这是一个非常小的仅标题库,用于使用Windows捕获音频。它仅由一个标头文件组成,尽管“空” .CPP文件与.h文件配对以形成所谓的单元。
在内部,它使用来自Multimedia API(MMEAPI.H Header)的回调过程在运行类实例(对象)的上下文中产生另一个回调,因此请小心,因为回调的代码在分离的多媒体线程的上下文中运行。
用法
用法相当简单:首先,包括标头文件WaveIn并根据要处理的样本类型声明特定的WaveIn CO设备:
WaveIn.h"
// Declare a type representing a WaveIn device treating 16 bit signed samples
using WaveIn Type = App:: WaveIn CO<int16_t>;\”>
# include < cstdint > # include \" WaveIn .h \" // Declare a type representing a WaveIn device treating 16 bit signed samples using WaveIn Type = App:: WaveIn CO< int16_t >;
然后,让我们定义一个实例传递一些参数(设备,输入通道计数,缓冲区长度和采样速率)和可callable对象(lambda,function,functor …等)。在下面的示例中,使用了lambda。
WaveInType Wi(
0, // Input device number
2, // Stereo channels (2 channels)
1024, // 1 KiB buffer lenght
44100, // Sample rate (CD)
[]( auto& Buffer ) {
// Buffer contains the samples to process
// In this example, Buffer is a
//
// std::vector<int16_t> const &
//
// Note: this code runs in the context
// of a separate thread from the one that
// created the WaveIn CO object.
}
);
// Start acquisition
Wi.Start(); \”>
// Declare an instance WaveIn Type Wi ( 0 , // Input device number 2 , // Stereo channels (2 channels) 1024 , // 1 KiB buffer lenght 44100 , // Sample rate (CD) []( auto & Buffer ) { // Buffer contains the samples to process // In this example, Buffer is a // // std::vector<int16_t> const & // // Note: this code runs in the context // of a separate thread from the one that // created the WaveIn CO object. } ); // Start acquisition Wi.Start();
最后,当采集必须结束时,只需调用停止功能(或破坏实例)。
Wi.Stop();
