bool Init(const String& path) { File file; if(!file.OpenRead(path)) return false; FileReader stream = FileReader(file); WavHeader riff; stream << riff; if(riff != "RIFF") return false; char riffType[4]; stream.SerializeObject(riffType); if(strncmp(riffType, "WAVE", 4) != 0) return false; while(stream.Tell() < stream.GetSize()) { WavHeader chunkHdr; stream << chunkHdr; if(chunkHdr == "fmt ") { stream << m_format; //Logf("Sample format: %s", Logger::Info, (m_format.nFormat == 1) ? "PCM" : "Unknown"); //Logf("Channels: %d", Logger::Info, m_format.nChannels); //Logf("Sample rate: %d", Logger::Info, m_format.nSampleRate); //Logf("Bps: %d", Logger::Info, m_format.nBitsPerSample); } else if(chunkHdr == "data") // data Chunk { // validate header if(m_format.nFormat != 1) return false; if(m_format.nChannels > 2 || m_format.nChannels == 0) return false; if(m_format.nBitsPerSample != 16) return false; // Read data m_length = chunkHdr.nLength / sizeof(short); m_pcm.resize(chunkHdr.nLength); stream.Serialize(m_pcm.data(), chunkHdr.nLength); } else { stream.Skip(chunkHdr.nLength); } } // Calculate the sample step if the rate is not the same as the output rate double sampleStep = (double)m_format.nSampleRate / (double)m_audio->GetSampleRate(); m_sampleStepIncrement = (uint64)(sampleStep * (double)fp_sampleStep); return true; }