bool nuiAiffReader::ReadInfo() { ScanAllChunks(); //there are 8 unused bytes at the beginning of the "SSND" chunk in an AIFF file Chunk* pSSNDChunk = GetChunk("SSND"); if (!pSSNDChunk) return false; pSSNDChunk->mDataPosition += 8; bool res = false; res = GoToChunk("FORM"); if (!res) return false; std::vector<char> fileFormat(4); char* waveFormat = "AIFF"; for(uint32 i = 0; i < 4; i++) { if( 1 != mrStream.ReadUInt8((uint8*)&(fileFormat[i]), 1)) return false; if (fileFormat[i] != waveFormat[i]) return false; // this stream is not a wave stream } mInfo.SetFileFormat(eAudioWave); res = GoToChunk("COMM"); if (!res) return false; int16 Channels = 0; uint32 SampleFrames = 0; int16 SampleSize = 0; extended SampleRate; //Read all parameters given in "COMM" chunk if( 1 != mrStream.ReadInt16(&Channels,1)) return false; if( 1 != mrStream.ReadUInt32(&SampleFrames,1)) return false; if( 1 != mrStream.ReadInt16(&SampleSize,1)) return false; //read SampleRate exponent if( 1 != mrStream.ReadInt16(SampleRate.exp,1)) return false; //read Samplerate Mantisse if( 4 != mrStream.ReadInt16(SampleRate.man,4)) return false; mInfo.SetFormatTag(AIFF_FORMAT_TAG); mInfo.SetSampleRate(ExtendedToDouble(SampleRate)); mInfo.SetChannels(Channels); mInfo.SetBitsPerSample(SampleSize); mInfo.SetSampleFrames(SampleFrames); mInfo.SetStartFrame(0); mInfo.SetStopFrame(mInfo.GetSampleFrames()); return true; }
bool nuiWaveReader::ReadInfo() { ScanAllChunks(); uint16 Format = eWaveFormatUnknown; uint16 NbChannels = 0; uint32 SamplesPerSec = 0; uint32 AvgBytesPerSec = 0; uint16 BlockAlign = 0; uint16 BitsPerSample = 0; uint32 NbSamples = 0; bool res = false; res = GoToChunk("RIFF"); if (!res) return false; std::vector<char> fileFormat(4); char* waveFormat = "WAVE"; for (int32 i = 0; i < 4; i++) { if( 1 != mrStream.ReadUInt8((uint8*)&(fileFormat[i]), 1)) return false; if (fileFormat[i] != waveFormat[i]) return false; // this stream is not a wave stream } mInfo.SetFileFormat(eAudioWave); res = GoToChunk("fmt "); if (!res) return false; //Read all parameters given in "fmt" chunk if( 1 != mrStream.ReadUInt16(&Format,1)) return false; if( 1 != mrStream.ReadUInt16(&NbChannels,1)) return false; if( 1 != mrStream.ReadUInt32(&SamplesPerSec,1)) return false; if( 1 != mrStream.ReadUInt32(&AvgBytesPerSec,1)) return false; if( 1 != mrStream.ReadUInt16(&BlockAlign,1)) return false; if( 1 != mrStream.ReadUInt16(&BitsPerSample,1)) return false; mInfo.SetFormatTag(Format); mInfo.SetSampleRate(SamplesPerSec); mInfo.SetChannels(NbChannels); mInfo.SetBitsPerSample(BitsPerSample); //get number of sample frames for(int32 i = 0; i < mChunks.size(); i++) { if(mChunks[i]->CompareId("data")) //attempt to reach "data" Chunk { NbSamples = (int32)mChunks[i]->mDataSize; mInfo.SetSampleFrames(NbSamples * 8 / BitsPerSample / NbChannels); break; } } mInfo.SetStartFrame(0); mInfo.SetStopFrame(mInfo.GetSampleFrames()); return true; }