private bool _ReadV4(BinaryReader r) { wavpack_header4 wvh4 = new wavpack_header4(); byte[] EncBuf = new byte[4096]; int tempo; byte encoderbyte; bool result = false; wvh4.Reset(); wvh4.ckID = r.ReadChars(4); wvh4.ckSize = r.ReadUInt32(); wvh4.version = r.ReadUInt16(); wvh4.track_no = r.ReadByte(); wvh4.index_no = r.ReadByte(); wvh4.total_samples = r.ReadUInt32(); wvh4.block_index = r.ReadUInt32(); wvh4.block_samples = r.ReadUInt32(); wvh4.flags = r.ReadUInt32(); wvh4.crc = r.ReadUInt32(); if (StreamUtils.StringEqualsArr("wvpk", wvh4.ckID)) // wavpack header found -- TODO handle exceptions better { result = true; version = (wvh4.version >> 8); channels = (int)(2 - (wvh4.flags & 4)); // mono flag bits = (int)((wvh4.flags & 3) * 16); // bytes stored flag samples = wvh4.total_samples; bSamples = wvh4.block_samples; sampleRate = (int)((wvh4.flags & (0x1F << 23)) >> 23); if ((sampleRate > 14) || (sampleRate < 0)) { sampleRate = 44100; } else { sampleRate = sample_rates[sampleRate]; } if (8 == (wvh4.flags & 8)) // hybrid flag { encoder = "hybrid lossy"; codecFamily = AudioDataIOFactory.CF_LOSSY; } else { //if (2 == (wvh4.flags & 2) ) { // lossless flag encoder = "lossless"; codecFamily = AudioDataIOFactory.CF_LOSSLESS; } /* * if ((wvh4.flags & 0x20) > 0) // MODE_HIGH * { * FEncoder = FEncoder + " (high)"; * end * else if ((wvh4.flags & 0x40) > 0) // MODE_FAST * { * FEncoder = FEncoder + " (fast)"; * } */ duration = (double)wvh4.total_samples / sampleRate; if (duration > 0) { bitrate = (sizeInfo.FileSize - tagSize) * 8 / (double)(samples / (double)sampleRate); } Array.Clear(EncBuf, 0, 4096); EncBuf = r.ReadBytes(4096); for (tempo = 0; tempo < 4096; tempo++) { if (0x65 == EncBuf[tempo]) { if (0x02 == EncBuf[tempo + 1]) { encoderbyte = EncBuf[tempo + 2]; switch (encoderbyte) { case 8: encoder = encoder + " (high)"; break; case 0: encoder = encoder + " (normal)"; break; case 2: encoder = encoder + " (fast)"; break; case 6: encoder = encoder + " (very fast)"; break; } break; } } } } return(result); }
// --------------------------------------------------------------------------- private bool _ReadV4(BinaryReader r) { wavpack_header4 wvh4 = new wavpack_header4(); byte[] EncBuf = new byte[4096]; int tempo; byte encoderbyte; bool result = false; wvh4.Reset(); wvh4.ckID = r.ReadChars(4); wvh4.ckSize = r.ReadUInt32(); wvh4.version = r.ReadUInt16(); wvh4.track_no = r.ReadByte(); wvh4.index_no = r.ReadByte(); wvh4.total_samples = r.ReadUInt32(); wvh4.block_index = r.ReadUInt32(); wvh4.block_samples = r.ReadUInt32(); wvh4.flags = r.ReadUInt32(); wvh4.crc = r.ReadUInt32(); if (Utils.StringEqualsArr("wvpk", wvh4.ckID)) // wavpack header found { result = true; FValid = true; FVersion = (wvh4.version >> 8); FChannels = (int)(2 - (wvh4.flags & 4)); // mono flag FBits = (int)((wvh4.flags & 3) * 16); // bytes stored flag FSamples = wvh4.total_samples; FBSamples = wvh4.block_samples; FSampleRate = (int)((wvh4.flags & (0x1F << 23)) >> 23); if ((FSampleRate > 14) || (FSampleRate < 0)) { FSampleRate = 44100; } else { FSampleRate = sample_rates[FSampleRate]; } if (8 == (wvh4.flags & 8)) // hybrid flag { FEncoder = "hybrid lossy"; } else { //if (2 == (wvh4.flags & 2) ) { // lossless flag FEncoder = "lossless"; } /* * if ((wvh4.flags & 0x20) > 0) // MODE_HIGH * { * FEncoder = FEncoder + " (high)"; * end * else if ((wvh4.flags & 0x40) > 0) // MODE_FAST * { * FEncoder = FEncoder + " (fast)"; * } */ FDuration = (double)wvh4.total_samples / FSampleRate; if (FDuration > 0) { FBitrate = (FFileSize - FTagSize) * 8 / (double)(FSamples / (double)FSampleRate) / 1000; } Array.Clear(EncBuf, 0, 4096); EncBuf = r.ReadBytes(4096); for (tempo = 0; tempo < 4096; tempo++) { if (0x65 == EncBuf[tempo]) { if (0x02 == EncBuf[tempo + 1]) { encoderbyte = EncBuf[tempo + 2]; switch (encoderbyte) { case 8: FEncoder = FEncoder + " (high)"; break; case 0: FEncoder = FEncoder + " (normal)"; break; case 2: FEncoder = FEncoder + " (fast)"; break; case 6: FEncoder = FEncoder + " (very fast)"; break; } break; } } } } return(result); }
// --------------------------------------------------------------------------- private bool _ReadV4( BinaryReader r ) { wavpack_header4 wvh4 = new wavpack_header4(); byte[] EncBuf = new byte[4096]; int tempo; byte encoderbyte; bool result = false; wvh4.Reset(); wvh4.ckID = r.ReadChars(4); wvh4.ckSize = r.ReadUInt32(); wvh4.version = r.ReadUInt16(); wvh4.track_no = r.ReadByte(); wvh4.index_no = r.ReadByte(); wvh4.total_samples = r.ReadUInt32(); wvh4.block_index = r.ReadUInt32(); wvh4.block_samples = r.ReadUInt32(); wvh4.flags = r.ReadUInt32(); wvh4.crc = r.ReadUInt32(); if ( Utils.StringEqualsArr("wvpk",wvh4.ckID) ) // wavpack header found { result = true; FValid = true; FVersion = (wvh4.version >> 8); FChannels = (int)(2 - (wvh4.flags & 4)); // mono flag FBits = (int)((wvh4.flags & 3) * 16); // bytes stored flag FSamples = wvh4.total_samples; FBSamples = wvh4.block_samples; FSampleRate = (int)((wvh4.flags & (0x1F << 23)) >> 23); if ( (FSampleRate > 14) || (FSampleRate < 0) ) { FSampleRate = 44100; } else { FSampleRate = sample_rates[ FSampleRate ]; } if (8 == (wvh4.flags & 8) ) // hybrid flag { FEncoder = "hybrid lossy"; } else { //if (2 == (wvh4.flags & 2) ) { // lossless flag FEncoder = "lossless"; } /* if ((wvh4.flags & 0x20) > 0) // MODE_HIGH { FEncoder = FEncoder + " (high)"; end else if ((wvh4.flags & 0x40) > 0) // MODE_FAST { FEncoder = FEncoder + " (fast)"; } */ FDuration = (double)wvh4.total_samples / FSampleRate; if ( FDuration > 0 ) FBitrate = (FFileSize - FTagSize) * 8 / (double)(FSamples / (double)FSampleRate) / 1000; Array.Clear(EncBuf,0,4096); EncBuf = r.ReadBytes(4096); for (tempo=0; tempo<4096; tempo++) { if (0x65 == EncBuf[tempo] ) { if (0x02 == EncBuf[tempo + 1] ) { encoderbyte = EncBuf[tempo + 2]; switch (encoderbyte) { case 8: FEncoder = FEncoder + " (high)"; break; case 0: FEncoder = FEncoder + " (normal)"; break; case 2: FEncoder = FEncoder + " (fast)"; break; case 6: FEncoder = FEncoder + " (very fast)"; break; } break; } } } } return result; }