trium
asked on
how to set output device
Dear Experts
We have to set phone line as our output device for the playback of a wave file ? we r unable to get hang on it.our tool is Visual C++
And we also donot know how to get device identifier,,
Thanx
Bye
trium
We have to set phone line as our output device for the playback of a wave file ? we r unable to get hang on it.our tool is Visual C++
And we also donot know how to get device identifier,,
Thanx
Bye
trium
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear jack
i used the function lineGetID to get the device identifire so that
phone could be used as an output device to play the sound file.
LPCSTR deviceName="wave/out";
VARSTRING devID;
LONG retcode;
// initialize a VARSTRING structure
devID.dwTotalSize = sizeof(VARSTRING);
devID.dwNeededSize = 0;
devID.dwUsedSize = 0;
devID.dwStringFormat = STRINGFORMAT_BINARY;
devID.dwStringSize = 0;
devID.dwStringOffset = 0;
lineGetID(hLine, 0, hCall, LINECALLSELECT_LINE, &devID, deviceName) ;
ASSERT(devID.dwStringForma
retcode= *((DWORD *)(((BYTE *)&devID)+devID.dwStringOf
the value i got at "retcode" is 24 which i think is the device identifire
of the opened line.then i passed this value to "waveOutOpen" function to
open the outputdevice(phone).
LPHWAVEOUT phwo;
UINT uDeviceID=retcode1;
LPWAVEFORMATEX pwfx;
DWORD dwCallback;
DWORD dwCallbackInstance;
DWORD fdwOpen ;
waveOutOpen(
phwo,
uDeviceID,
pwfx,
dwCallback,
dwCallbackInstance,
fdwOpen
);
and then used "PlaySound" function to play the sound file.
LPCSTR pszSound ="filename.wav;
HMODULE hmod =NULL;
DWORD fdwSound =SND_FILENAME;
PlaySound(
pszSound,
hmod,
fdwSound
);
but still the sound file is played on the speaker not on the phone.
plz tell me what should i do so that phone is set as the output device
to play the sound file.
You cannot use the easy "PlaySound" to accomplish this. You need to use the waveform API directly (in this case, the waveOutXXXX calls). You will need to open a waveout device. You will then need to load the contents of the file into a RAM buffer (or, if it is a really large file, you will need to load and play the file in portions, which takes a little more code), build a WAVEHDR structure pointing to your buffer, and submit the WAVEHDR to waveOutWrite.
For more points, I will be happy to post or email you some working sample code for playing audio data using the waveOut functions (in fact, code that was used to output to phone lines using TAPI, although the output device is irrelevant).
- jack
For more points, I will be happy to post or email you some working sample code for playing audio data using the waveOut functions (in fact, code that was used to output to phone lines using TAPI, although the output device is irrelevant).
- jack
ASKER
Now that the points are increased, u must send me proper working code.
Its in your favour if u wanna get all marks,......!
trium
Its in your favour if u wanna get all marks,......!
trium
Pick up the code at:
http://www.cetasoft.com/JackThornton/code/omsrc.zip
This contains some production code of a more elaborate system than you probably need. The main file of interest is AudioDevice.cpp (the "speaker" section). It will demonstrate how to prepare a wave header for an audio buffer and submit that header (with a pointer to the buffer) to be played by the wave output API. It also demonstrates how to receive notification that the buffer has been played (or at least output to the hardware; if the audio hardware has a significant chunk of on-board RAM buffer or other latency problems then it is possible that you might get the notification before the sound has actually finished playing). You can queue up multiple buffers to be played, which makes it easy to string together different bits and pieces of audio.
Some of the code contains automatic conversion between PCM and muLaw - you can pull this code out.
Be particularly mindful of the formats the output device actually supports - you can call waveOutOpen in a way that will query for support of a particular format without actually opening the device.
You will not be able to use the classes as-is, but there is much code to study and bits and pieces you can cut and paste.
I've also included the Line source files to show how I opened the line device and got my "handle" to the waveout audio device.
Hope this helps.
- jack
http://www.cetasoft.com/JackThornton/code/omsrc.zip
This contains some production code of a more elaborate system than you probably need. The main file of interest is AudioDevice.cpp (the "speaker" section). It will demonstrate how to prepare a wave header for an audio buffer and submit that header (with a pointer to the buffer) to be played by the wave output API. It also demonstrates how to receive notification that the buffer has been played (or at least output to the hardware; if the audio hardware has a significant chunk of on-board RAM buffer or other latency problems then it is possible that you might get the notification before the sound has actually finished playing). You can queue up multiple buffers to be played, which makes it easy to string together different bits and pieces of audio.
Some of the code contains automatic conversion between PCM and muLaw - you can pull this code out.
Be particularly mindful of the formats the output device actually supports - you can call waveOutOpen in a way that will query for support of a particular format without actually opening the device.
You will not be able to use the classes as-is, but there is much code to study and bits and pieces you can cut and paste.
I've also included the Line source files to show how I opened the line device and got my "handle" to the waveout audio device.
Hope this helps.
- jack
ASKER
dear jack
thanx alot for your code.i've tried that but stucked at a point
which is the first parameter of WAVEHDR structure
LPSTR lpData // pointer to the waveform buffer.
plz guide me how to pass the waveform buffer.
thanx alot for your code.i've tried that but stucked at a point
which is the first parameter of WAVEHDR structure
LPSTR lpData // pointer to the waveform buffer.
plz guide me how to pass the waveform buffer.
The waveform buffer is the raw waveform data, WITHOUT the header or any other information. For example, if you load in a standard .WAV file, the waveform data will be encapsulated inside the "data" chunk. Examine the method AudioBuffer::GetWaveData in AudioBuffer.cpp to see how to pull the data out of a WAV file, if this is what you're stuck at.
Once you have a block of waveform data, simply pass a pointer to that data in lpData. Ignore the fact that the type is LPSTR, this is old Microsoft code back before they became more intelligent about designing API's (they should have used "LPVOID"; "BYTE *" would have been acceptable; using "LPSTR" is lazy and misleading, which is very bad policy for an API meant for others to use). Just use either a standard 'C' style cast or a C++ reinterpret_cast to cast the pointer to the beginning of the waveform data to LPSTR.
- jack
Once you have a block of waveform data, simply pass a pointer to that data in lpData. Ignore the fact that the type is LPSTR, this is old Microsoft code back before they became more intelligent about designing API's (they should have used "LPVOID"; "BYTE *" would have been acceptable; using "LPSTR" is lazy and misleading, which is very bad policy for an API meant for others to use). Just use either a standard 'C' style cast or a C++ reinterpret_cast to cast the pointer to the beginning of the waveform data to LPSTR.
- jack
ASKER
Dear jack
Thanx 4 ur guidance.i used the function GetWaveData() and tried to set the lpData parameter
here is the code
// after successfully gettin' the devise ID
//open line device;
HWAVEOUT phwo;
LPWAVEFORMATEX pwfx;
DWORD dwCallback=0;
DWORD dwCallbackInstance;
DWORD fdwOpen=CALLBACK_NULL ;
//------------------------ --------
waveOutOpen(
&phwo,
uDeviceID, //got it by lineGetID function
pwfx,
dwCallback,
dwCallbackInstance,
fdwOpen
);
//------------------------ ---------- -----
unsigned x;
void *src ="myfile.wav";
unsigned wholeChunkSize = ((DWORD *)src)[1];
unsigned fileSize = wholeChunkSize + 8;
BYTE *pFormatChunk = (BYTE *)src + 8;
++pFormatChunk;
WAVEFORMATEX *pFormat = (WAVEFORMATEX *) (pFormatChunk + 12);
unsigned formatSize = ((DWORD *)pFormatChunk)[2];
BYTE *pDataChunk = (BYTE *)src + 8;
++pDataChunk;
void *pData = (void *) (pDataChunk + 8);
unsigned dataSize = ((DWORD *)pDataChunk)[1];
HWAVEOUT hwo=phwo;
WAVEHDR *pwh;
pwh->lpData=(LPSTR)pData;
pwh->dwBufferLength=dataSi ze;
pwh->dwBufferLength=0;
pwh->dwFlags=0;
pwh->dwLoops=0;
pwh->dwUser=0;
pwh->lpNext=0;
pwh->reserved=0;
//------------------------ ---------- ---
UINT cbwh;
waveOutPrepareHeader(
hwo,
pwh,
cbwh
);
//------------------------ ------
waveOutWrite(
hwo,
pwh,
cbwh
);
//------------------------ ---------- ----
The code is without error checking.ignore this.
kindly point out my mistakes and how can i make them correct. Don't worry about the points. if i get my problem solved, i'll give u all
of my points 'cuz i need it to be solved as soon as possible.
Thanx 4 ur guidance.i used the function GetWaveData() and tried to set the lpData parameter
here is the code
// after successfully gettin' the devise ID
//open line device;
HWAVEOUT phwo;
LPWAVEFORMATEX pwfx;
DWORD dwCallback=0;
DWORD dwCallbackInstance;
DWORD fdwOpen=CALLBACK_NULL ;
//------------------------
waveOutOpen(
&phwo,
uDeviceID, //got it by lineGetID function
pwfx,
dwCallback,
dwCallbackInstance,
fdwOpen
);
//------------------------
unsigned x;
void *src ="myfile.wav";
unsigned wholeChunkSize = ((DWORD *)src)[1];
unsigned fileSize = wholeChunkSize + 8;
BYTE *pFormatChunk = (BYTE *)src + 8;
++pFormatChunk;
WAVEFORMATEX *pFormat = (WAVEFORMATEX *) (pFormatChunk + 12);
unsigned formatSize = ((DWORD *)pFormatChunk)[2];
BYTE *pDataChunk = (BYTE *)src + 8;
++pDataChunk;
void *pData = (void *) (pDataChunk + 8);
unsigned dataSize = ((DWORD *)pDataChunk)[1];
HWAVEOUT hwo=phwo;
WAVEHDR *pwh;
pwh->lpData=(LPSTR)pData;
pwh->dwBufferLength=dataSi
pwh->dwBufferLength=0;
pwh->dwFlags=0;
pwh->dwLoops=0;
pwh->dwUser=0;
pwh->lpNext=0;
pwh->reserved=0;
//------------------------
UINT cbwh;
waveOutPrepareHeader(
hwo,
pwh,
cbwh
);
//------------------------
waveOutWrite(
hwo,
pwh,
cbwh
);
//------------------------
The code is without error checking.ignore this.
kindly point out my mistakes and how can i make them correct. Don't worry about the points. if i get my problem solved, i'll give u all
of my points 'cuz i need it to be solved as soon as possible.
Could you tell me what errors you're having running this code before I take a look at it?
thanx
- jack
thanx
- jack
ASKER
......no error....but i cannot hear my sound file being played on dialed telephone
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by : JackThornton
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Roshan Davis
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by : JackThornton
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Roshan Davis
EE Cleanup Volunteer
Some details about what you are doing would really help...