We help IT Professionals succeed at work.

Wave File Format

WDB
WDB asked
on
Medium Priority
909 Views
Last Modified: 2013-12-03
I'm creating wave files for my application. I'm using the low level waveIn() and mmio() functions to manage several different formats. I create a RIFF file and am able to add the main RIFF chunk, the fmt chunk and the fact chunks. I also add the data chunk with a size 0 before I start actually writing to the file. I write to the file and everything seems to flow smoothly. The file size seems to be correct but when I attempt to open it with a media player device (i.e. "Sound Recorder") it opens fine but it says it's media length is 0 and it's size is 0. Below is my source.

hmmio = mmioOpen szFileName ,NULL,MMIO_CREATE MMIO_WRITE | MMIO_EXCLUSIVE);

    //
    //  create the RIFF chunk of form type 'WAVE'
    //
    mmckinfo.fccType = mmioFOURCC('W', 'A', 'V', 'E');
    mmckinfo.cksize  = 0L;
    mmioCreateChunk(hmmio, &mmckinfo, MMIO_CREATERIFF);


    //
    //  now create the destination fmt, fact, and data chunks _in that order_
    //
    //  hmmio is now descended into the 'RIFF' chunk--create the format chunk
    //  and write the format header into it
    //

    cbwfx = sizeof(WAVEFORMATEX)+(Acm.pwfx)->cbSize;
    ck.ckid   = mmioFOURCC('f', 'm', 't', ' ');
    ck.cksize = 0L;
    mmioCreateChunk(hmmio, &ck, 0);

    mmioWrite(hmmio, (HPSTR)(Acm.pwfx), cbwfx);
    mmioAscend(hmmio, &ck, 0);

    //
    //  create the 'fact' chunk

    ck.ckid   = mmioFOURCC('f', 'a', 'c', 't');
    ck.cksize = 0L;
    mmioCreateChunk(hmmio, &ck, 0);

    cSamples  = 0L;
    mmioWrite(hmmio, (HPSTR)&cSamples, sizeof(DWORD));
    mmioAscend(hmmio, &ck, 0);

    //
    //  create the data chunk with no data..
    //
    ck.ckid   = mmioFOURCC('d', 'a', 't', 'a');
    ck.cksize = 0L;
    mmioCreateChunk(hmmio, &ck, 0);
    mmioAscend(hmmio, &ck, 0);

    mmioAscend(hmmio, &mmckinfo, 0);

I use the following code with each additional write to the file.

ck.cksize = lpwh->dwBytesRecorded;
ck.ckid = mmioFOURCC('d', 'a', 't', 'a');
mmioCreateChunk(hmmio,&ck,0);
mmioWrite(hmmio,lpwh->lpData,lpwh->dwBytesRecorded);
mmioAscend(hmmio, &ck, 0);

What Am I missing? Thanks for your help!
Comment
Watch Question

Commented:
   cbwfx = sizeof(WAVEFORMATEX)+(Acm.pwfx)->cbSize;
    ck.ckid   = mmioFOURCC('f', 'm', 't', ' ');
    ck.cksize = cbwfx; // this should be cbwfx instead of 0L
    mmioCreateChunk(hmmio, &ck, 0);

If the problem still exists, check out the utility RiffWalk to dump the chunks to see what is wrong.

WDB

Author

Commented:
Thanks for your answer chensu but it didn't work for me. I don't think I'm building the RIFF file correclty. I create The main RIFF chunk then I create the frmt chunk and write to it. I ascend out of the fmt chunk and create the fact chunk and write to it. I ascend out of the fact chunk and then create the data chunk. I write to the data chunk several times and then I ascend out of the data chunk and then out of the main RIFF chunk. Is this correct? The fmt and fact chunks or written to correctly but the data chunk still seems to be interpreted as 0 in size?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
WDB

Author

Commented:
Thanks chensu. I needed to change the way I was using the waveInPrepareHeader() and waveInUnprepareHeader() functions. Your source didn't help since I'm using formats other than PCM. I appreciate you offering your source. Thanks Again!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.