🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.multimedia
Article #50

Re: mmioDescend() / mmioAscend()

#50
From: Remy Lebeau (TeamB)
Date: Mon, 17 Jul 2006 04:12
135 lines
5297 bytes
"TMBTC" <jkofsky@bellsouth.net> wrote in message
news:44b994f9$1@newsgroups.borland.com...

> Can anyone help me understand how to use the
> mmioDescend() / mmioAscend() API functions for
> a read operation.

What exactly is unclear about them that you want to know?

> I have a test.wav file that contains the CART chunk. When I read
> it all is fine. When I read a WAVE file that does not contain it, I
> also can't find the 'data' chunk.

That is because you are not seeking the file properly when the chunk is
missing.  In fact, you should not be seeking the file at all.

Try this code instead:

    void __fastcall TForm1::OpenButtonClick(TObject *Sender)
    {
        MMCKINFO mmckInfoWave = {0};
        HMMIO mmioFileHandle = NULL;
        WAVEFORMATEX WaveFormat = {0};
        MMCKINFO mmckInfoSubChunk = {0};
        MMRESULT mmResult = 0;
        CartChunkTagURL cartTag = {0};
        AnsiString asTemp = "";

        Memo1->Lines->Clear();

        mmioFileHandle = mmioOpen(".\\test.wav", NULL, MMIO_READ);
        if( !mmioFileHandle )
        {
            Memo1->Lines->Add("Unable to open file");
            return;
        }

        mmckInfoWave.fccType = mmioFOURCC('W','A','V','E');
        if( mmioDescend(mmioFileHandle, &mmckInfoWave, NULL, MMIO_FINDRIFF)
!= MMSYSERR_NOERROR )
        {
            Memo1->Lines->Add("Error finding WAVE chunk");
            mmioClose(mmioFileHandle, 0);
            return;
        }

        mmckInfoSubChunk.ckid = mmioFOURCC('f','m','t',' ');
        if( mmioDescend(mmioFileHandle, &mmckInfoSubChunk, &mmckInfoWave,
MMIO_FINDCHUNK) != MMSYSERR_NOERROR )
        {
            Memo1->Lines->Add("Error finding FMT chunk");
            mmioClose(mmioFileHandle, 0);
            return;
        }

        if( mmioRead(mmioFileHandle, (HPSTR)&WaveFormat,
mmckInfoSubChunk.cksize) < mmckInfoSubChunk.cksize )
        {
            Memo1->Lines->Add("Error reading FMT chunk");
            mmioClose(mmioFileHandle, 0);
            return;
        }

        asTemp.sprintf("Number of Channels: %d", WaveFormat.nChannels);
        Memo1->Lines->Add(asTemp);
        asTemp.sprintf("Sample Per Second: %d", WaveFormat.nSamplesPerSec);
        Memo1->Lines->Add(asTemp);
        asTemp.sprintf("Avg. Bytes Per Second: %d",
WaveFormat.nAvgBytesPerSec);
        Memo1->Lines->Add(asTemp);
        asTemp.sprintf("Block Alignment: %d", WaveFormat.nBlockAlign);
        Memo1->Lines->Add(asTemp);

        if( mmioAscend(mmioFileHandle, &mmckInfoSubChunk, 0) !=
MMSYSERR_NOERROR )
        {
            Memo1->Lines->Add("Error ascending from FMT chunk");
            mmioClose(mmioFileHandle, 0);
            return;
        }

        mmckInfoSubChunk.ckid = mmioFOURCC('C','A','R','T');
        mmResult = mmioDescend(mmioFileHandle, &mmckInfoSubChunk,
&mmckInfoWave, MMIO_FINDCHUNK);
        if( mmResult != MMSYSERR_NOERROR )
        {
            if( mmResult != MMIOERR_CHUNKNOTFOUND )
            {
                Memo1->Lines->Add("Error finding CART chunk");
                mmioClose(mmioFileHandle, 0);
                return;
            }

            Memo1->Lines->Add("No CART chunk was found");
        }
        else
        {
            if( mmioRead(mmioFileHandle, (HPSTR)&cartTag,
mmckInfoSubChunk.cksize) < mmckInfoSubChunk.cksize )
            {
                Memo1->Lines->Add("Error reading CART chunk");
                mmioClose(mmioFileHandle, 0);
                return;
            }

            asTemp.sprintf("Size of CART: %d", mmckInfoSubChunk.cksize);
            Memo1->Lines->Add(asTemp);

            mmioAscend(mmioFileHandle, &mmckInfoSubChunk, 0);
        }

        ZeroMemory(&mmckInfoSubChunk, sizeof(mmckInfoSubChunk));

        mmckInfoSubChunk.ckid = mmioFOURCC('d','a','t','a');
        mmResult = mmioDescend(mmioFileHandle, &mmckInfoSubChunk,
&mmckInfoWave, MMIO_FINDCHUNK);
        if( mmResult != MMSYSERR_NOERROR )
        {
            if( mmResult != MMIOERR_CHUNKNOTFOUND )
                Memo1->Lines->Add("Error finding DATA chunk");
            else
                Memo1->Lines->Add("No DATA chunk was found.");
        }
        else
        {
            asTemp.sprintf("Size of Data: %d", mmckInfoSubChunk.cksize);
            Memo1->Lines->Add(asTemp);
        }

        mmioClose(mmioFileHandle, 0);
    }


Gambit
Technical Details
Message-ID: <44bb0e5c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <44b994f9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,1c42c7cbd941d437
X-Google-Attributes: gid10d0fc,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.multimedia
References: <44b994f9$1@newsgroups.borland.com>
Subject: Re: mmioDescend() / mmioAscend()
Date: Sun, 16 Jul 2006 21:12:52 -0700
Lines: 137
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <44bb0e5c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1153109596 68.69.17.41 (16 Jul 2006 21:13:16 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail