|
Windows环境下的麦克风录音系统(16) m_btnStop.EnableWindow(FALSE); theSoundCapture().__closeMic(); m_btnStart.EnableWindow(TRUE); } 看完整段代码你可能会很奇怪怎么在CmicDemoDlg中居然都没有定义一个CSoundIn对象??呵呵,原因很简单,因为设备的独占性所以在一个时刻只能有一个CSoundIn对象存在(因为CSoundIn对象需要占据录音设备),所以我们必须限制程序员生成CSoundIn对象的数量,怎么限制呢?那就是把CSoundIn的构造函数放在private区域里面: private: BOOL GetBestWaveFormat(WAVEFORMATEX & waveFormatEx); // because sound card is one and only so i must limit the number of CSoundIn object, // but how to limit the class object nums?maybe put constructor into private scope is // a good idea,:-) CSoundIn(); 这样的话就根本无法声明一个CSoundIn对象,不信你试一下在你的代码中写上: CSoundIn soundInObj; 能编译通过吗?肯定是不能,那如何调用CSoundIn的成员函数呢?答案是通过一个全局函数: // global function,:-( // client can only through this function to use CSoundIn object CSoundIn & theSoundCapture() { static CSoundIn p; return p; } 这时候你应该明白了为什么上面的代码中调用CSoundIn的成员函数的时候都是用theSoundCapture来做的原因了吧. 参考资料 1.Microsoft MSDN Library April 2003
|