Thread View: borland.public.cppbuilder.multimedia
2 messages
2 total messages
Started by TMBTC
Sun, 16 Jul 2006 01:23
mmioDescend() / mmioAscend()
Author: TMBTC
Date: Sun, 16 Jul 2006 01:23
Date: Sun, 16 Jul 2006 01:23
81 lines
4042 bytes
4042 bytes
Can anyone help me understand how to use the mmioDescend() / mmioAscend()
API functions for a read operation. I have searched the Web and Help files
but am still having problems. I need to write an app that will add the CART
(www.cartchunk.org) chunk information to a WAVE file.
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.
//Code --------------------------------------------------------------------
void __fastcall TForm1::OpenButtonClick(TObject *Sender)
{
//
MMCKINFO mmckInfoWave = {0};
HMMIO mmioFileHandle = NULL;
WAVEFORMATEX WaveFormat = {0};
MMCKINFO mmckInfoSubChunk = {0};
CartChunkTagURL cartTag = {0};
AnsiString asTemp = "";
mmioFileHandle = mmioOpen("test.wav", 0, MMIO_READ);
if (mmioFileHandle) {
mmckInfoWave.fccType = mmioFOURCC('W','A','V','E');
if (mmioDescend(mmioFileHandle, (LPMMCKINFO)&mmckInfoWave, 0,
MMIO_FINDRIFF)
== MMIOERR_CHUNKNOTFOUND) {
mmioClose(mmioFileHandle, 0);
return;
} //EndIf (mmioDescend(...))
//
mmckInfoSubChunk.ckid = mmioFOURCC('f','m','t',' ');
if(mmioDescend(mmioFileHandle, &mmckInfoSubChunk, &mmckInfoWave,
MMIO_FINDCHUNK)
== MMIOERR_CHUNKNOTFOUND) {
mmioClose(mmioFileHandle, 0);
return;
} //EndIf (mmioDescend(..))
} //EndIf (mmioFileHandle)
mmioRead(mmioFileHandle, (HPSTR)&WaveFormat, mmckInfoSubChunk.cksize);
Memo1->Lines->Clear();
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);
//
// Get CART Info
mmioAscend(mmioFileHandle, &mmckInfoSubChunk, 0);
mmckInfoSubChunk.ckid = mmioFOURCC('C','A','R','T');
if(mmioDescend(mmioFileHandle, &mmckInfoSubChunk, &mmckInfoWave,
MMIO_FINDCHUNK)
== MMIOERR_CHUNKNOTFOUND) {
Memo1->Lines->Add("No 'CART' chunk found.");
mmioSeek(mmioFileHandle, mmckInfoWave.dwDataOffset, SEEK_SET);
mmckInfoSubChunk.dwDataOffset = mmckInfoWave.dwDataOffset;
mmckInfoSubChunk.fccType = 0;
} else {
mmioRead(mmioFileHandle, (HPSTR)&cartTag, mmckInfoSubChunk.cksize);
asTemp.sprintf("Size of CART: %d", mmckInfoSubChunk.cksize);
Memo1->Lines->Add(asTemp);
}
// get data info
mmioAscend(mmioFileHandle, &mmckInfoSubChunk, 0);
mmckInfoSubChunk.ckid = mmioFOURCC('d','a','t','a');
if(mmioDescend(mmioFileHandle, &mmckInfoSubChunk, &mmckInfoWave,
MMIO_FINDCHUNK)
== MMIOERR_CHUNKNOTFOUND) {
Memo1->Lines->Add("No 'data' chunk found.");
} else {
asTemp.sprintf("Size of Data: %d", mmckInfoSubChunk.cksize);
Memo1->Lines->Add(asTemp);
}
mmioClose(mmioFileHandle, 0);
} //End OpenButtonClick()
Re: mmioDescend() / mmioAscend()
Author: Remy Lebeau (TeamB)
Date: Mon, 17 Jul 2006 04:12
Date: Mon, 17 Jul 2006 04:12
135 lines
5297 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads