On Jun 10, 12:23�pm, cs_post...@hotmail.com wrote:
> On Jun 10, 11:36 am, ldkha1979 <ledinh...@gmail.com> wrote:
>
> > Thks for your answer, but could you please explain more in detail?
>
> You have your data in a data buffer.
>
> Windows wants to play a collection of one or more "wave headers".
> Each of these is a structure of items describing a chunk of audio
> data. �One of the items in the structure is a pointer to the actual
> payload data. �You'll have to make that point to your buffer of audio
> data. �And then fill in the other items. �You call a function to
> "prepare" the header, and then you call a function to play it.
>
> See MSDN (just google one of the function names from Vladimir's
> example), I think their example code has something that will play from
> a wave file, if you just have raw data then delete the bit about the
> file header.
On Jun 10, 11:36 am, ldkha1979 <ledinh...@gmail.com> wrote:
> Thks for your answer, but could you please explain more in detail?
You have your data in a data buffer.
Windows wants to play a collection of one or more "wave headers".
Each of these is a structure of items describing a chunk of audio
data. One of the items in the structure is a pointer to the actual
payload data. You'll have to make that point to your buffer of audio
data. And then fill in the other items. You call a function to
"prepare" the header, and then you call a function to play it.
See MSDN (just google one of the function names from Vladimir's
example), I think their example code has something that will play from
a wave file, if you just have raw data then delete the bit about the
file header.
Reply by ldkha1979●June 10, 20082008-06-10
On Jun 9, 5:36�pm, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
> ldkha1979 wrote:
> > hi all,
> > I want to know how to play sound form an array of value with a given
> > frequency sampling (Fs = 16000Hz).
> > I have an array of value (16 bit) then I wwant to play like with
> > sound.m in matlab.
> > Thks a lot!
>
> This will help you:
>
> waveformatex.wFormatTag = WAVE_FORMAT_PCM;
> waveformatex.nChannels �= WAVEOUT_CHANNELS;
> waveformatex.nSamplesPerSec �= (int)WAVEOUT_FS;
> waveformatex.nAvgBytesPerSec = (int)(WAVEOUT_FS*2*WAVEOUT_CHANNELS);
> waveformatex.nBlockAlign = 2*WAVEOUT_CHANNELS;
> waveformatex.wBitsPerSample = 16;
> waveformatex.cbSize = 0;
>
> for(i=0;i<WAVEOUT_NUM_OF_BUFFERS;i++)
> � {
> � wh_data[i] = new char[WAVEOUT_BUFFER_LENGTH];
> � memset(wh_data[i],0,WAVEOUT_BUFFER_LENGTH);
> � wh[i].lpData = wh_data[i];
> � wh[i].dwBufferLength = WAVEOUT_BUFFER_LENGTH;
> � wh[i].dwBytesRecorded = �0;
> � wh[i].dwUser = 0;
> � wh[i].dwFlags = 0;
> � wh[i].dwLoops = 0;
> � }
>
> waveOutOpen(&hwo,
> � � � � � � �WAVEOUT_DEVICE_ID,
> � � � � � � �&waveformatex,
> � � � � � � �(DWORD)waveOutProc,
> � � � � � � �(DWORD)this, // Callbackinstance
> � � � � � � �CALLBACK_FUNCTION|WAVE_FORMAT_DIRECT);
>
> for(i = 0; i < (WAVEOUT_NUM_OF_BUFFERS - 1); i++)
> � {
> � waveOutPrepareHeader(hwo,&wh[i],sizeof(wh[i]));
> � waveOutWrite(hwo,&wh[i],sizeof(wh[i]));
> � }
>
> waveout_buffer_id = WAVEOUT_NUM_OF_BUFFERS - 1;
> waveout_flag = 0;
> //------------------------------------
>
> Vladimir Vassilevsky
> DSP and Mixed Signal Design Consultanthttp://www.abvolt.com
Thks for your answer, but could you please explain more in detail?
Because I'm new with this. Here is my code to read from a binary file
the data that i want to play:
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
std::fstream f_in;
short speech, value[10000];
f_in.open ("myfile.pcm", std::ios::in | std::ios::binary);
int i = 0;
while (i < 10000) {
f_in.read((char *)&speech, 2);
value[i] = speech;
cout << speech << std::endl;
i++;
}
}
From this, I have an array of data (name value) with 10000 values. Now
I want to play them in sound with Fs = 16000 Hz, mono. It would be
great if you could you me a little bit more in detail.
Thank you very much!
Reply by ●June 10, 20082008-06-10
On Jun 9, 5:36 pm, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
Will probably also be necessary to link winmm.lib
There may also be #include requirements though I'm not sure (looks
like I may be getting by with windows.h and windowsx.h)
MSDN is one's friend. The example code there isn't a bad starting
point when trying to figure out how to make a widoze box do something.
Reply by Vladimir Vassilevsky●June 9, 20082008-06-09
ldkha1979 wrote:
> hi all,
> I want to know how to play sound form an array of value with a given
> frequency sampling (Fs = 16000Hz).
> I have an array of value (16 bit) then I wwant to play like with
> sound.m in matlab.
> Thks a lot!
hi all,
I want to know how to play sound form an array of value with a given
frequency sampling (Fs = 16000Hz).
I have an array of value (16 bit) then I wwant to play like with
sound.m in matlab.
Thks a lot!