Hi all,

please anyone tell me what is wrong with the code... I did everything said
in the memory management section to allocate memory and tried to play the
wave file. but the playfunction always return that not enough memory to
complete the operation (errorcode 14 ).

here is the code... first is with file mapping and the other reading the
file to memory allocated with virtualalloc function.

The code works perfectly in emulator but not in the device. I am using an
iPAQ hx2700
with 256Mb, up to 144Mb of it is for user.

I have written a program using IO device but I have no idea how to fill the
details of the WAVEFORMATEX struct (samplebitrate, etc), because I dont know
anything about the wav file in hand.

anyhelp please .....

Thanks



{HANDLE hFile;

hFile = CreateFileForMapping(TEXT("\\My
Documents\\Music01.wav"),GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

HANDLE hMapFile = CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,0);

DWORD dw = GetLastError();

DWORD nWords,dwSize;

dwSize = GetFileSize(hFile,&nWords);

LPVOID pMap = MapViewOfFile(hMapFile,FILE_MAP_READ,0,0,0);

dw = GetLastError();

BOOL b;

pMap = MapC

int ret = PlaySound((LPCWSTR)pMap,NULL,SND_MEMORY);

DWORD res = GetLastError();

UnmapViewOfFile(pMap);

CloseHandle(hMapFile);

b = CloseHandle(hFile);}



//

{HANDLE hFile;

hFile = CreateFile(TEXT("\\My
Documents\\Music01.wav"),GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

LPVOID pBase = NULL;

LPVOID pBuff = NULL;

pBase = VirtualAlloc(0,5*1024*1024,MEM_RESERVE,PAGE_NOACCESS);

pBuff = VirtualAlloc(pBase,5*1024*1024,MEM_COMMIT,PAGE_READWRITE);

DWORD nWords,dwSize;

dwSize = GetFileSize(hFile,&nWords);

BOOL b;

b = ReadFile(hFile,pBuff,dwSize,&nWords,0);

b = PlaySound((LPCWSTR)pBuff,NULL,SND_SYNC|SND_MEMORY);

DWORD res = GetLastError();

b = VirtualFree(pBase,0,MEM_RELEASE);

b = CloseHandle(hFile);}

Re: playing .wav file more than 4 Mb by grubbymaster

grubbymaster
Thu May 04 08:45:48 CDT 2006

load the file with WinAmp and see its properties ... after that:

// WAVE format structure
WAVEFORMATEX pWavePCM = {0};
// GSM format structure
GSM610WAVEFORMAT pWaveGSM610 = {0};
// MP3 format structure
MPEGLAYER3WAVEFORMAT pWaveMP3 = {0};
//buffer
WAVEHDR wbuffer;

pWavePCM.wFormatTag = WAVE_FORMAT_PCM;
pWavePCM.nChannels = 2;
pWavePCM.nSamplesPerSec = 44100; // samples per second (Hertz), that
each channel should be played or recorded
pWavePCM.wBitsPerSample = 16; //16 for stereo ( 16bits/sample) , 8 for
mono (8 bits/sample)
pWavePCM.cbSize = 0;
pWavePCM.nBlockAlign = pWavePCM.nChannels * (pWavePCM.wBitsPerSample /
8);
pWavePCM.nAvgBytesPerSec = pWavePCM.nSamplesPerSec *
pWavePCM.nBlockAlign;

fullsize = 10L * (long)pWavePCM.nSamplesPerSec *
(long)pWavePCM.wBitsPerSample / 8L; // this will be the max length of
the buffer

wbuffer.dwBufferLength = fullsize;
wbuffer.lpData = (LPSTR)mybuffer;
wbuffer.dwFlags = 0;

also you can find more facts about using the Wave API on this page :

http://www.borg.com/~jglatt/tech/lowaud.htm

Regards,
GruBBy