waveInOpen函数莫名其妙的错误

tts_264 2014-11-12 02:22:35
头文件定义:
private:
HWAVEIN m_hWaveIn; //输入设备
WAVEFORMATEX m_waveform; //采集音频的格式,结构体

CPP:
m_waveform.wFormatTag = WAVE_FORMAT_PCM; //声音格式为PCM
m_waveform.nSamplesPerSec = SAMPLESPERSRC_44100; //采样率,16000次/秒
m_waveform.wBitsPerSample = 16; //采样比特,16bits/次
m_waveform.nChannels = 1; //采样声道数,2声道
m_waveform.nAvgBytesPerSec = SAMPLESPERSRC_44100 * 2; //每秒的数据率,就是每秒能采集多少字节的数据
m_waveform.nBlockAlign = 2; //一个块的大小,采样bit的字节数乘以声道数
m_waveform.cbSize = 0; //一般为0

//使用waveInOpen函数开启音频采集
MMRESULT mmr = waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_waveform,
(DWORD)(MicCallback), DWORD(this), CALLBACK_FUNCTION);
if(mmr != MMSYSERR_NOERROR)
return false;

当运行到 waveInOpen这个函数的时候,程序直接报错。如图,可以保证在window xp下绝对是可以用的,现在的开发环境是window8,请高人帮忙解答下,万分感谢!



...全文
865 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
引用 11 楼 u014019207 的回复:
已解决,原因是VS2012不能支持,换了一个vs2008即可!希望以后大家不要急着升级VS的版本了。
盲目升级是码农之殇!
tts_264 2014-11-12
  • 打赏
  • 举报
回复
已解决,原因是VS2012不能支持,换了一个vs2008即可!希望以后大家不要急着升级VS的版本了。
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
Windows Multimedia Previous Next waveInOpen The waveInOpen function opens the given waveform-audio input device for recording. MMRESULT waveInOpen( LPHWAVEIN phwi, UINT_PTR uDeviceID, LPWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwCallbackInstance, DWORD fdwOpen ); Parameters phwi Pointer to a buffer that receives a handle identifying the open waveform-audio input device. Use this handle to identify the device when calling other waveform-audio input functions. This parameter can be NULL if WAVE_FORMAT_QUERY is specified for fdwOpen. uDeviceID Identifier of the waveform-audio input device to open. It can be either a device identifier or a handle of an open waveform-audio input device. You can use the following flag instead of a device identifier. Value Meaning WAVE_MAPPER The function selects a waveform-audio input device capable of recording in the specified format. pwfx Pointer to a WAVEFORMATEX structure that identifies the desired format for recording waveform-audio data. You can free this structure immediately after waveInOpen returns. dwCallback Pointer to a fixed callback function, an event handle, a handle to a window, or the identifier of a thread to be called during waveform-audio recording to process messages related to the progress of recording. If no callback function is required, this value can be zero. For more information on the callback function, see waveInProc. dwCallbackInstance User-instance data passed to the callback mechanism. This parameter is not used with the window callback mechanism. fdwOpen Flags for opening the device. The following values are defined. Value Meaning CALLBACK_EVENT The dwCallback parameter is an event handle. CALLBACK_FUNCTION The dwCallback parameter is a callback procedure address. CALLBACK_NULL No callback mechanism. This is the default setting. CALLBACK_THREAD The dwCallback parameter is a thread identifier. CALLBACK_WINDOW The dwCallback parameter is a window handle. WAVE_FORMAT_DIRECT If this flag is specified, the ACM driver does not perform conversions on the audio data. WAVE_FORMAT_QUERY The function queries the device to determine whether it supports the given format, but it does not open the device. WAVE_MAPPED The uDeviceID parameter specifies a waveform-audio device to be mapped to by the wave mapper. Return Values Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following. Value Description MMSYSERR_ALLOCATED Specified resource is already allocated. MMSYSERR_BADDEVICEID Specified device identifier is out of range. MMSYSERR_NODRIVER No device driver is present. MMSYSERR_NOMEM Unable to allocate or lock memory. WAVERR_BADFORMAT Attempted to open with an unsupported waveform-audio format. Remarks Use the waveInGetNumDevs function to determine the number of waveform-audio input devices present on the system. The device identifier specified by uDeviceID varies from zero to one less than the number of devices present. The WAVE_MAPPER constant can also be used as a device identifier. If you choose to have a window or thread receive callback information, the following messages are sent to the window procedure or thread to indicate the progress of waveform-audio input: MM_WIM_OPEN, MM_WIM_CLOSE, and MM_WIM_DATA. If you choose to have a function receive callback information, the following messages are sent to the function to indicate the progress of waveform-audio input: WIM_OPEN, WIM_CLOSE, and WIM_DATA. Requirements Windows NT/2000/XP: Included in Windows NT 3.1 and later. Windows 95/98/Me: Included in Windows 95 and later. Header: Declared in Mmsystem.h; include Windows.h. Library: Use Winmm.lib. See Also Waveform Audio, Waveform Functions, WAVEFORMATEX, waveInGetNumDevs, waveInProc, MM_WIM_OPEN, MM_WIM_CLOSE, MM_WIM_DATA Previous Next
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
VS20xx: 项目、属性、C/C++、附加包含目录:填写附加头文件所在目录 分号间隔多项 项目、属性、链接器、常规、附加库目录:填写附加依赖库所在目录 分号间隔多项 项目、属性、链接器、输入、附加依赖项:填写附加依赖库的名字.lib 空格或分号间隔多项
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
总不至于是链接的库版本太旧或32位/64位库弄混了吧。 必要的话,试试用驱动精灵软件升级声卡驱动。 GetLastError()是多少? 崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
勤奋的小游侠 2014-11-12
  • 打赏
  • 举报
回复
既然是waveInOpen报错,无非就是它的参数有误。 //使用waveInOpen函数开启音频采集 MMRESULT mmr = waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_waveform, (DWORD)(MicCallback), DWORD(this), CALLBACK_FUNCTION); waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_waveform, (DWORD)m_hWnd,NULL,CALLBACK_WINDOW) 我给个例子给你尝试改改看
tts_264 2014-11-12
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
设置输出为64位目标代码后,重建所有。
谢谢回答,工程都是重建的,您说的这些我已经避免过了,但是就是调用这个函数的时候会出错,麻烦帮我下好吗,大牛,这个问题已经纠结一星期了,各种资料都找不到。 #ifndef __CBROADCASTLIVE_H__ #define __CBROADCASTLIVE_H__ //#include <mmsystem.h> //#include <mmreg.h> //#pragma comment(lib, "winmm.lib") enum{BUFF_MAX_SIZE = 3072,SAMPLESPERSRC_8000 = 8000,SAMPLESPERSRC_11025 = 11025,SAMPLESPERSRC_22050 = 22050,SAMPLESPERSRC_44100 = 44100}; //#pragma comment(lib,"winmm.lib") class CBroadcastLive { public: CBroadcastLive(void); ~CBroadcastLive(void); protected: static DWORD CALLBACK MicCallback( //消息回掉函数 HWAVEIN hWaveIn, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); static UINT WINAPI _WorkerThread(LPVOID lpParam); public: bool Init(void); bool Start(vector<unsigned long> *pvID); bool Stop(void); private: HWAVEIN m_hWaveIn; //输入设备 WAVEFORMATEX m_waveform; //采集音频的格式,结构体 BYTE *m_pBuffer1; //采集音频时的数据缓存 BYTE *m_pBuffer2 ;//采集音频时的数据缓存 WAVEHDR m_wHdr1; //采集音频时包含数据缓存的结构体 WAVEHDR m_wHdr2; //采集音频时包含数据缓存的结构体 }; #endif //CPP CBroadcastLive::CBroadcastLive(void) { } CBroadcastLive::~CBroadcastLive(void) { } bool CBroadcastLive::Init() { m_waveform.wFormatTag = WAVE_FORMAT_PCM; //声音格式为PCM m_waveform.nSamplesPerSec = SAMPLESPERSRC_44100; //采样率,16000次/秒 m_waveform.wBitsPerSample = 16; //采样比特,16bits/次 m_waveform.nChannels = 1; //采样声道数,2声道 m_waveform.nAvgBytesPerSec = SAMPLESPERSRC_44100 * 2; //每秒的数据率,就是每秒能采集多少字节的数据 m_waveform.nBlockAlign = 2; //一个块的大小,采样bit的字节数乘以声道数 m_waveform.cbSize = 0; //一般为0 //使用waveInOpen函数开启音频采集 MMRESULT mmr = waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_waveform, (DWORD)(MicCallback), DWORD(this), CALLBACK_FUNCTION); if(mmr != MMSYSERR_NOERROR) return false; m_pBuffer1 = new BYTE(BUFF_MAX_SIZE); m_pBuffer2 = new BYTE(BUFF_MAX_SIZE); m_wHdr1.lpData = (LPSTR)m_pBuffer1; m_wHdr1.dwBufferLength = BUFF_MAX_SIZE; m_wHdr1.dwBytesRecorded = 0; m_wHdr1.dwUser = 0; m_wHdr1.dwFlags = 0; m_wHdr1.dwLoops = 1; m_wHdr1.lpNext = NULL; m_wHdr1.reserved = 0; waveInPrepareHeader(m_hWaveIn,&m_wHdr1,sizeof(WAVEHDR)); m_wHdr2.lpData = (LPSTR)m_pBuffer2; m_wHdr2.dwBufferLength = BUFF_MAX_SIZE; m_wHdr2.dwBytesRecorded = 0; m_wHdr2.dwUser = 0; m_wHdr2.dwFlags = 0; m_wHdr2.dwLoops = 1; m_wHdr2.lpNext = NULL; m_wHdr2.reserved = 0; //将建立好的wHdr2做为备用 waveInPrepareHeader(m_hWaveIn,&m_wHdr2,sizeof(WAVEHDR)); //将两个wHdr添加到waveIn中去 waveInAddBuffer (m_hWaveIn, &m_wHdr1, sizeof (WAVEHDR)) ; waveInAddBuffer (m_hWaveIn, &m_wHdr2, sizeof (WAVEHDR)) ; return true; }
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
设置输出为64位目标代码后,重建所有。
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
用 Visual C++ 创建在 64 位 Windows 操作系统中运行的应用程序时,应注意以下问题: 在 64 位 Windows 操作系统中,int 和 long 是 32 位值。对于计划为 64 位平台编译的程序,应注意不要将指针赋给 32 位变量。在 64 位平台上,指针为 64 位,如果将该指针赋给 32 位变量,则应截断该指针值。 在 64 位 Windows 操作系统中,size_t、time_t 和 ptrdiff_t 是 64 位值。 在 32 位 Windows 操作系统上 Visual C++ 2005 之前的 Visual C++ 版本中,time_t 是 32 位值。在 Visual C++ 2005 和更高版本中,默认情况下,time_t 是 64 位整数。有关更多信息,请参见时间管理。 应注意代码在哪里采用 int 值并将其作为 size_t 或 time_t 值处理。数字有可能增长得比 32 位数大,并且数据在被传递回 int 存储时有可能被截断。 %x(十六进制 int 格式)printf 修饰符在 64 位 Windows 操作系统中不会按预期的那样工作。它只对传递给它的值的前 32 位值执行操作。 Windows 32 位操作系统使用 %I32x 显示整数。 Windows 64 位操作系统使用 %I64x 显示整数。 %p(指针的十六进制格式)在 64 位 Windows 操作系统中按预期的那样工作。 The two primary areas of concern when examining your code for 64-bit compatibility are as follows: Address calculations Pointer arithmetic For many reasons, developers have stored addresses as a ULONG value. After all, on 32-bit Windows, an address, a pointer, and a ULONG value are all 32 bits long. However, on 64-bit Windows, an address and a ULONG are not the same length. While a ULONG remains a 32-bit value, all pointers are now 64-bit values. General Porting Guidelines Porting 32-bit applications to 64-bit Microsoft Windows will be easier than it was porting 16-bit applications to 32-bit Windows. However, the move will go more smoothly with some careful planning. The following are some general guidelines. Planning Determine the magnitude of the effort required for the port. Gauge how much work is involved by identifying the following items: Problem 32-bit code. Compile your 32-bit code with the 64-bit compiler and examine the extent of the errors and warnings. Shared components or dependencies. Determine which components in your application originate from other teams and whether those teams plan to develop 64-bit versions of their code. Legacy or assembly code. 16-bit Windows-based applications do not run on 64-bit Windows and must be rewritten. While x86 assembly code runs in WOW64, you may want to rewrite this code to take advantage of the speed of the Intel Itanium architecture. Port the entire application, not just portions of it. Although it is possible to port pieces of an application or to limit code to 2G with /LARGEADDRESSAWARE:NO, this strategy trades short-term gain for long-term pain. Find substitutes for technologies that will not be ported. Some technologies, including DAO (Data Access Object) and the Jet Red database engine, will not be ported to 64-bit Windows. Treat your 64-bit version as a separate product release. Even though your 64-bit product may share the same code base as your 32-bit, it needs additional testing and may have other release considerations. Development Start developing compliant code now. Developers can start writing compliant code by using the latest Platform SDK header files and the new data types with no adverse effects on 32-bit product development. For more information, see Getting Ready for 64-bit Windows. Ensure that your code can be compiled for both 32- and 64-bit Windows. The new data model was designed to allow 32- and 64-bit applications to be built from a single code base with few modifications. The SQL Server and Windows development teams are developing 32- and 64-bit versions of their products from the same code base. Use the compiler's new optimization features for best performance. Code optimization for Intel Itanium processors is more important than it was for the x86. The compiler assumes many of the optimization functions previously handled by the microprocessor. You can maximize the performance of a 64-bit application by using two new optimization features of the compiler: Profile Guided Optimization and Whole Program Optimization. Both features result in longer build times and require the early development of good test scenarios. Profile Guided Optimization involves a two-step compile process. During the first compile, the code is instrumented to capture the execution behavior. This information is used during the second compile to guide all optimization features. Whole Program Optimization analyzes the code in all application files, not just a single one. This approach increases performance in several ways, including better inlining, as well as improved side-effect analysis and custom calling conventions. Testing Determine whether you'll test 64- or 32-bit code running in WOW64. Some applications include both native 64-bit code and 32-bit code running in WOW64. Investigate this closely while developing a test plan, and decide whether your test tools should be 64-bit, 32-bit, or a combination. You will often need to test both the 64- and 32-bit versions of your application on 64-bit Windows. Test frequently used 32-bit components. First, recompile your code to 64-bit and test. Second, fix problems, recompile in 32-bits, and then test. Third, recompile to 64-bit and test. Test COM and RPC components. Make sure that both 32- and 64-bit COM and RPC components communicate correctly. You may also have to test communications with 16-bit components over a network. Test your 32-bit version on 64-bit Windows. Customers can continue to use 32-bit applications on 64-bit Windows where performance and memory issues are not major considerations. Test different memory configurations. Adding large amounts of memory on the server sometimes exposes previously unnoticed problems in either the application or the operating system. Send comments about this topic to Microsoft Build date: 8/10/2007
tts_264 2014-11-12
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
谢谢回答,但是这个是系统函数,我觉得他应该没错,但是为什么会崩溃,是不是不支持64位操作程序呢? 如果有空,能帮我在64位系统上面实验一下吗?非常感谢
赵4老师 2014-11-12
  • 打赏
  • 举报
回复
崩溃的时候在弹出的对话框按相应按钮进入调试,按Alt+7键查看Call Stack里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处,看不懂时双击下一行,直到能看懂为止。
tts_264 2014-11-12
  • 打赏
  • 举报
回复


不好意思,发错图片了。正确的图片如现在这张。

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧