//************************************** // Find a subchunk with the pID identity //************************************** WORD RIFFClass::FindCk(const CHAR* pID) { DWORD dwID = MAKE_ID(pID); Reset(); ReadCkHdr(); while (TRUE) { if ((dwID == dwLastID) || // We found our chunk (dwID == dwLastFormID)) return (SUCCESS); else if (Descend() != SUCCESS) { if (Ascend() != SUCCESS) // Jump to the next chunk break; } } return (RIFF_FINDERROR); }
// Aufstieg mit ControlUp public func ContainedUp(pClonk) { Ascend(pClonk); return(1); }
/////////////////////////////////////////////////////////////////////////////// // SeekToDirectory /////////////////////////////////////////////////////////////////////////////// bool cDbDataSourceIter::SeekToDirectory( const cFCOName& parentName, bool bCreate ) { cDebug d( "cDbDataSourceIter::SeekToDirectory" ); // // the first task is to ascend until we are in a directory that we can descend into to // reach parentName... // cFCOName curParent = GetParentName(); d.TraceDebug( _T("Entering... Seeking to %s (cwd = %s)\n"), parentName.AsString().c_str(), curParent.AsString().c_str() ); int ascendCount ; switch( curParent.GetRelationship( parentName ) ) { case cFCOName::REL_BELOW: // // we must ascend... // ascendCount = curParent.GetSize() - parentName.GetSize(); d.TraceDetail( _T("\tAscending %d times...\n"), ascendCount ); ASSERT( ascendCount > 0 ); for( ; ascendCount > 0; ascendCount-- ) Ascend(); break; case cFCOName::REL_ABOVE: // // we are above the needed directory; nothing else to do here... // d.TraceDetail( _T("\tAbove; not ascending...\n") ); break; case cFCOName::REL_EQUAL: // // we need to do nothing else here... // d.TraceDetail( _T("\tEqual; doing nothing...\n") ); SeekBegin(); return true; case cFCOName::REL_UNRELATED: // // we have to go all the way to the root... // d.TraceDetail( _T("\tUnrelated; seeking to root...\n") ); SeekToRoot(); break; default: // unreachable ASSERT( false ); return false; } curParent = GetParentName(); if( parentName.GetSize() == curParent.GetSize() ) return true; // // now we will descend to the parent directory we are interested in... // cFCOName::iterator i(parentName); i.SeekTo( curParent.GetSize() ); for(; (! i.Done()); i.Next() ) { if( ! mDbIter.SeekTo( i.GetName() ) ) { // this needs to be created! if( bCreate ) mDbIter.CreateEntry( i.GetName() ); else return false; } // // create the child array and descend // if( ! mDbIter.CanDescend() ) { if( bCreate ) mDbIter.CreateChildArray(); else return false; } mDbIter.Descend(); } return true; }
int CWaveFile::UpdateHeader( void ) ///////////////////////////////////////////////////////////////////////////// { MMRESULT Result; // ascend out of the data subchunk Result = Ascend( &m_mmckinfoSubchunk ); if( Result ) DPF(("UpdateHeader: Ascend data subchunk failed!\n")); //DPF(("fccType [%08lx] %lu\n", m_mmckinfoSubchunk.fccType, m_mmckinfoSubchunk.cksize )); // ascend out of the WAVE chunk, which automaticlly updates the cksize field Result = Ascend( &m_mmckinfoParent ); if( Result ) DPF(("UpdateHeader: Ascend WAVE chunk failed %ld!\n", Result )); //DPF(("fccType [%08lx] %lu\n", m_mmckinfoParent.fccType, m_mmckinfoParent.cksize )); //MMSYSERR_INVALPARAM // force write to disk Result = Flush( MMIO_EMPTYBUF ); if( Result ) DPF(("UpdateHeader: Flush failed!\n")); // if a compressed format, then update the fact chunk if( m_FormatEx.wFormatTag != WAVE_FORMAT_PCM ) { DWORD dwSampleLength; MMCKINFO mmckinfoFact; // move to start of file SeekBegin( 0 ); // find the WAVE chunk m_mmckinfoParent.fccType = mmioFOURCC('W','A','V','E'); if( Descend( (LPMMCKINFO)&m_mmckinfoParent, NULL, MMIO_FINDRIFF ) ) { Close(); return( FALSE ); } // Now, find the fact chunk mmckinfoFact.ckid = mmioFOURCC('f','a','c','t'); if( Descend( &mmckinfoFact, &m_mmckinfoParent, MMIO_FINDCHUNK ) ) { Close(); return( FALSE ); } // compute out the number of samples dwSampleLength = GetSampleCount(); // write the fact chunk if( Write( (HPSTR)&dwSampleLength, sizeof( DWORD )) != (LONG)sizeof( DWORD ) ) { Close(); return( FALSE ); } // Ascend out of the fact subchunk. if( Ascend( &mmckinfoFact ) ) DPF(("Ascend Failed\n")); // Ascend out of the WAVE chunk. if( Ascend( &m_mmckinfoParent ) ) DPF(("Ascend Failed\n")); } return( TRUE ); }
int CWaveFile::WriteHeader( void ) ///////////////////////////////////////////////////////////////////////////// { m_mmckinfoParent.fccType = mmioFOURCC('W','A','V','E'); m_mmckinfoParent.dwFlags = MMIO_DIRTY; if( CreateChunk( (LPMMCKINFO)&m_mmckinfoParent, MMIO_CREATERIFF ) ) { DPF(( "Could not create WAVE chunk.\n" )); Close(); return( FALSE ); } m_mmckinfoSubchunk.ckid = mmioFOURCC('f','m','t',' '); m_mmckinfoSubchunk.cksize = sizeof( PCMWAVEFORMAT ); if( CreateChunk( (LPMMCKINFO)&m_mmckinfoSubchunk, (UINT)NULL ) ) { DPF(( "Could not create fmt subchunk.\n" )); Close(); return( FALSE ); } //DPF(("FormatSize %ld\n", m_lFormatSize )); if( Write( (HPSTR)&m_FormatEx, m_lFormatSize ) != m_lFormatSize ) { DPF(("Write format Failed!\n")); Close(); return( FALSE ); } // Ascend out of the format subchunk. if( Ascend( &m_mmckinfoSubchunk ) ) { DPF(("WriteHeader: Ascend format subchunk Failed\n")); } if( m_FormatEx.wFormatTag != WAVE_FORMAT_PCM ) { DWORD dwSampleLength = 0; MMCKINFO mmckinfoFact; // create the fact chunk mmckinfoFact.ckid = mmioFOURCC('f','a','c','t'); mmckinfoFact.cksize = sizeof( DWORD ); if( CreateChunk( (LPMMCKINFO)&mmckinfoFact, (UINT)NULL ) ) { DPF(("CreateChunk Fact subchunk Failed!\n")); Close(); return( FALSE ); } // write a dummy value for the fact chunk if( Write( (HPSTR)&dwSampleLength, sizeof( DWORD ) ) != (LONG)sizeof( DWORD ) ) { DPF(("Write Fact subchunk Failed!\n")); Close(); return( FALSE ); } // Ascend out of the fact subchunk. if( Ascend( &mmckinfoFact ) ) { DPF(("Ascend Fact subchunk Failed!\n")); Close(); return( FALSE ); } } // create the 'data' sub-chunk m_mmckinfoSubchunk.ckid = mmioFOURCC('d','a','t','a'); m_mmckinfoSubchunk.dwFlags = MMIO_DIRTY; if( CreateChunk( (LPMMCKINFO)&m_mmckinfoSubchunk, (UINT)NULL ) ) { DPF(("CreateChunk data Failed!\n")); Close(); return( FALSE ); } //DPF(("fccType [%08lx] %lu\n", m_mmckinfoSubchunk.fccType, m_mmckinfoSubchunk.cksize )); return( TRUE ); }
int CWaveFile::ReadHeader( void ) ///////////////////////////////////////////////////////////////////////////// { // Locate a 'RIFF' chunk with a 'WAVE' form type to make sure it's a WAVE file. m_mmckinfoParent.fccType = mmioFOURCC('W','A','V','E'); if( Descend( &m_mmckinfoParent, NULL, MMIO_FINDRIFF ) ) { DPF(("Cannot Descend into WAVE chunk!\n")); Close(); return( FALSE ); } // Now, find the format chunk (form type 'fmt '). It should be a subchunk of the 'RIFF' parent chunk. m_mmckinfoSubchunk.ckid = mmioFOURCC('f','m','t',' '); if( Descend( &m_mmckinfoSubchunk, &m_mmckinfoParent, MMIO_FINDCHUNK ) ) { DPF(("Cannot find format chunk!\n")); Close(); return( FALSE ); } // Get the size of the format chunk m_lFormatSize = m_mmckinfoSubchunk.cksize; // read the format chunk if( Read( (HPSTR)&m_FormatEx, m_lFormatSize ) != (LONG)m_lFormatSize ) { DPF(("Cannot read format chunk!\n")); Close(); return( FALSE ); } // Ascend out of the format subchunk. if( Ascend( &m_mmckinfoSubchunk ) ) { DPF(("Ascend format subchunk failed!\n")); } // Find the data subchunk. m_mmckinfoSubchunk.ckid = mmioFOURCC('d','a','t','a'); if( Descend( &m_mmckinfoSubchunk, &m_mmckinfoParent, MMIO_FINDCHUNK ) ) { DPF(("Cannot Descend into data subchunk!\n")); Close(); return( FALSE ); } // Get the size of the data subchunk. m_dwDataSize = m_mmckinfoSubchunk.cksize; //DPF(("Data Size is %ld\n", m_dwDataSize )); // round file to integral number of audio blocks if( m_FormatEx.nBlockAlign ) m_dwDataSize = (m_dwDataSize / m_FormatEx.nBlockAlign ) * m_FormatEx.nBlockAlign; //DPF(("Computed Data Size is %ld\n", m_dwDataSize )); if( m_dwDataSize == 0L ) { DPF(("DataSize is zero!\n")); Close(); return( FALSE ); } m_dwBytesRead = 0; return( TRUE ); }