waveInOpen Code Help

S

saverain

//WaveIn.h
MMRESULT IsFormatSupported(LPWAVEFORMATEX pwfx, UINT uDeviceID)
{
return waveInOpen (
NULL, // ptr can be NULL for query
uDeviceID, // The device identifier
pwfx, // Defines the requested
// format.
NULL, // No callback
NULL, // No instance data
WAVE_FORMAT_QUERY); // Query only, do not open.
}


//WaveIn.cpp
#include "stdafx.h"
#include "WaveIn.h"

int main()
{
UINT wReturn;
WAVEFORMATEX pcmWaveFormat;

pcmWaveFormat.wFormatTag = WAVE_FORMAT_PCM;
pcmWaveFormat.nChannels = 1;
pcmWaveFormat.nSamplesPerSec = 44100L;
pcmWaveFormat.nAvgBytesPerSec = 88200L;
pcmWaveFormat.nBlockAlign = 2;
pcmWaveFormat.wBitsPerSample = 16;
pcmWaveFormat.cbSize = 0;

waveInOpen (
NULL, // ptr can be NULL for query
WAVE_MAPPER, // The device identifier
pwfx, // Defines the requested
// format.
NULL, // No callback
NULL, // No instance data
WAVE_FORMAT_QUERY); // Query only, do not open.
}

// See if format is supported by any device in the system.

wReturn = IsFormatSupported(&pcmWaveFormat, WAVE_MAPPER);

// Report results.

if (wReturn == MMSYSERR_NOERROR)
MessageBox(NULL, "44.1 kHz 16-bit stereo is supported.",
"", MB_ICONINFORMATION);
else if (wReturn == WAVERR_BADFORMAT)
MessageBox(NULL, "44.1 kHz 16-bit stereo NOT supported.",
"", MB_ICONINFORMATION);
else
MessageBox(NULL, "Error opening waveform device.",
"Error", MB_ICONEXCLAMATION);
}

I get these errors along with others

e:\Amp\Tabs\WaveIn.cpp(29): error C2065: 'pcmWaveFormat' : undeclared
identifier
e:\Amp\Tabs\WaveIn.cpp(29): error C2501: 'wReturn' : missing
storage-class or type specifiers
e:\Amp\Tabs\WaveIn.cpp(20): error C2065: 'pwfx' : undeclared identifier


Hi, new to the group, I'm trying to check to see if a waveformatex
format is supported by my sound card. Everything seems to be working
except for the waveInOpen struct. Any suggestions about the pwfx or
uDeviceDriver or anything? Thanks
 
V

Victor Bazarov

saverain said:
//WaveIn.h
MMRESULT IsFormatSupported(LPWAVEFORMATEX pwfx, UINT uDeviceID)
{
return waveInOpen (
NULL, // ptr can be NULL for query
uDeviceID, // The device identifier
pwfx, // Defines the requested
// format.
NULL, // No callback
NULL, // No instance data
WAVE_FORMAT_QUERY); // Query only, do not open.
}


//WaveIn.cpp
#include "stdafx.h"
#include "WaveIn.h"

int main()
{
UINT wReturn;
WAVEFORMATEX pcmWaveFormat;

pcmWaveFormat.wFormatTag = WAVE_FORMAT_PCM;
pcmWaveFormat.nChannels = 1;
pcmWaveFormat.nSamplesPerSec = 44100L;
pcmWaveFormat.nAvgBytesPerSec = 88200L;
pcmWaveFormat.nBlockAlign = 2;
pcmWaveFormat.wBitsPerSample = 16;
pcmWaveFormat.cbSize = 0;

waveInOpen (
NULL, // ptr can be NULL for query
WAVE_MAPPER, // The device identifier
pwfx, // Defines the requested
// format.
NULL, // No callback
NULL, // No instance data
WAVE_FORMAT_QUERY); // Query only, do not open.
}
^^^
I believe this curly brace is what screws you up. It closes the 'main'
function and the following statements are placed _outside_ of any function,
which is not what you wanted.
// See if format is supported by any device in the system.

wReturn = IsFormatSupported(&pcmWaveFormat, WAVE_MAPPER);

// Report results.

if (wReturn == MMSYSERR_NOERROR)
MessageBox(NULL, "44.1 kHz 16-bit stereo is supported.",
"", MB_ICONINFORMATION);
else if (wReturn == WAVERR_BADFORMAT)
MessageBox(NULL, "44.1 kHz 16-bit stereo NOT supported.",
"", MB_ICONINFORMATION);
else
MessageBox(NULL, "Error opening waveform device.",
"Error", MB_ICONEXCLAMATION);
}

I get these errors along with others

e:\Amp\Tabs\WaveIn.cpp(29): error C2065: 'pcmWaveFormat' : undeclared
identifier
e:\Amp\Tabs\WaveIn.cpp(29): error C2501: 'wReturn' : missing
storage-class or type specifiers
e:\Amp\Tabs\WaveIn.cpp(20): error C2065: 'pwfx' : undeclared
identifier


Hi, new to the group, I'm trying to check to see if a waveformatex
format is supported by my sound card. Everything seems to be working
except for the waveInOpen struct. Any suggestions about the pwfx or
uDeviceDriver or anything? Thanks

See above

V
 
S

saverain

Thanks now the only error I have is
e:\Amp\Tabs\WaveIn.cpp(20): error C2065: 'pwfx' : undeclared identifier

I believe this points to the pcmwaveformat but not shure.
 
V

Victor Bazarov

saverain said:
Thanks now the only error I have is
e:\Amp\Tabs\WaveIn.cpp(20): error C2065: 'pwfx' : undeclared
identifier

I believe this points to the pcmwaveformat but not shure.

Undeclared identifier usually is either scoping issue or the result of
a typo. You've got to be able to take care of those on your own.

V
 
V

voytello

maybe try to erase definition of WAVEFORMATEX value. create the pointer
LPWAVEFORMATEX pwfx.

this:
pcmWaveFormat.wFormatTag = WAVE_FORMAT_PCM;
(...) You can do the same with pwfx->wFormatTag and so on.

Then function IsFormatSupported() call with pwfx.
Maybe this will help.

Greets,
V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top