///////////////////////////// executable code //////////////////////////////// // Read the median log2 values from the specifed metadata structure, convert // them back to 32-bit unsigned values and store them. If length is not // exactly correct then we flag and return an error. internal static int read_entropy_vars(WavpackStream wps, WavpackMetadata wpmd) { byte[] byteptr = wpmd.data; int[] b_array = new int[12]; int i = 0; words_data w = new words_data(); for (i = 0; i < 6; i++) { b_array[i] = (int)(byteptr[i] & 0xff); } w.holding_one = 0; w.holding_zero = 0; if (wpmd.byte_length != 12) { if ((wps.wphdr.flags & (Defines.MONO_FLAG | Defines.FALSE_STEREO)) == 0) { return(Defines.FALSE); } } w.c[0].median[0] = exp2s(b_array[0] + (b_array[1] << 8)); w.c[0].median[1] = exp2s(b_array[2] + (b_array[3] << 8)); w.c[0].median[2] = exp2s(b_array[4] + (b_array[5] << 8)); if ((wps.wphdr.flags & (Defines.MONO_FLAG | Defines.FALSE_STEREO)) == 0) { for (i = 6; i < 12; i++) { b_array[i] = (int)(byteptr[i] & 0xff); } w.c[1].median[0] = exp2s(b_array[6] + (b_array[7] << 8)); w.c[1].median[1] = exp2s(b_array[8] + (b_array[9] << 8)); w.c[1].median[2] = exp2s(b_array[10] + (b_array[11] << 8)); } wps.w = w; return(Defines.TRUE); }
internal static int read_float_info(WavpackStream wps, WavpackMetadata wpmd) { int bytecnt = wpmd.byte_length; byte[] byteptr = wpmd.data; int counter = 0; if (bytecnt != 4) { return(Defines.FALSE); } wps.float_flags = byteptr[counter]; counter++; wps.float_shift = byteptr[counter]; counter++; wps.float_max_exp = byteptr[counter]; counter++; wps.float_norm_exp = byteptr[counter]; return(Defines.TRUE); }
// Read the hybrid related values from the specifed metadata structure, convert // them back to their internal formats and store them. The extended profile // stuff is not implemented yet, so return an error if we get more data than // we know what to do with. internal static int read_hybrid_profile(WavpackStream wps, WavpackMetadata wpmd) { byte[] byteptr = wpmd.data; int bytecnt = wpmd.byte_length; int buffer_counter = 0; int uns_buf = 0; int uns_buf_plusone = 0; if ((wps.wphdr.flags & Defines.HYBRID_BITRATE) != 0) { uns_buf = (int)(byteptr[buffer_counter] & 0xff); uns_buf_plusone = (int)(byteptr[buffer_counter + 1] & 0xff); wps.w.c[0].slow_level = exp2s(uns_buf + (uns_buf_plusone << 8)); buffer_counter = buffer_counter + 2; if ((wps.wphdr.flags & (Defines.MONO_FLAG | Defines.FALSE_STEREO)) == 0) { uns_buf = (int)(byteptr[buffer_counter] & 0xff); uns_buf_plusone = (int)(byteptr[buffer_counter + 1] & 0xff); wps.w.c[1].slow_level = exp2s(uns_buf + (uns_buf_plusone << 8)); buffer_counter = buffer_counter + 2; } } uns_buf = (int)(byteptr[buffer_counter] & 0xff); uns_buf_plusone = (int)(byteptr[buffer_counter + 1] & 0xff); wps.w.bitrate_acc[0] = (int)(uns_buf + (uns_buf_plusone << 8)) << 16; buffer_counter = buffer_counter + 2; if ((wps.wphdr.flags & (Defines.MONO_FLAG | Defines.FALSE_STEREO)) == 0) { uns_buf = (int)(byteptr[buffer_counter] & 0xff); uns_buf_plusone = (int)(byteptr[buffer_counter + 1] & 0xff); wps.w.bitrate_acc[1] = (int)(uns_buf + (uns_buf_plusone << 8)) << 16; buffer_counter = buffer_counter + 2; } if (buffer_counter < bytecnt) { uns_buf = (int)(byteptr[buffer_counter] & 0xff); uns_buf_plusone = (int)(byteptr[buffer_counter + 1] & 0xff); wps.w.bitrate_delta[0] = exp2s((short)(uns_buf + (uns_buf_plusone << 8))); buffer_counter = buffer_counter + 2; if ((wps.wphdr.flags & (Defines.MONO_FLAG | Defines.FALSE_STEREO)) == 0) { uns_buf = (int)(byteptr[buffer_counter] & 0xff); uns_buf_plusone = (int)(byteptr[buffer_counter + 1] & 0xff); wps.w.bitrate_delta[1] = exp2s((short)(uns_buf + (uns_buf_plusone << 8))); buffer_counter = buffer_counter + 2; } if (buffer_counter < bytecnt) { return(Defines.FALSE); } } else { wps.w.bitrate_delta[0] = wps.w.bitrate_delta[1] = 0; } return(Defines.TRUE); }
internal static int read_metadata_buff(WavpackContext wpc, WavpackMetadata wpmd) { long bytes_to_read; short tchar; if (wpmd.bytecount >= wpc.stream.wphdr.ckSize) { // we have read all the data in this block return(Defines.FALSE); } try { wpmd.id = (short)wpc.infile.ReadByte(); tchar = (short)wpc.infile.ReadByte(); } catch (System.Exception) { wpmd.status = 1; return(Defines.FALSE); } wpmd.bytecount += 2; wpmd.byte_length = tchar << 1; if ((wpmd.id & Defines.ID_LARGE) != 0) { wpmd.id &= (short)~Defines.ID_LARGE; try { tchar = (short)wpc.infile.ReadByte(); } catch (System.Exception) { wpmd.status = 1; return(Defines.FALSE); } wpmd.byte_length += ((int)tchar << 9); try { tchar = (short)wpc.infile.ReadByte(); } catch (System.Exception) { wpmd.status = 1; return(Defines.FALSE); } wpmd.byte_length += ((int)tchar << 17); wpmd.bytecount += 2; } if ((wpmd.id & Defines.ID_ODD_SIZE) != 0) { wpmd.id &= (short)~Defines.ID_ODD_SIZE; wpmd.byte_length--; } if (wpmd.byte_length == 0 || wpmd.id == Defines.ID_WV_BITSTREAM) { wpmd.hasdata = Defines.FALSE; return(Defines.TRUE); } bytes_to_read = wpmd.byte_length + (wpmd.byte_length & 1); wpmd.bytecount += bytes_to_read; if (bytes_to_read > wpc.read_buffer.Length) { int bytes_read; wpmd.hasdata = Defines.FALSE; while (bytes_to_read > wpc.read_buffer.Length) { try { bytes_read = wpc.infile.BaseStream.Read(wpc.read_buffer, 0, wpc.read_buffer.Length); if (bytes_read != wpc.read_buffer.Length) { return(Defines.FALSE); } } catch (System.Exception) { return(Defines.FALSE); } bytes_to_read -= wpc.read_buffer.Length; } } else { wpmd.hasdata = Defines.TRUE; wpmd.data = wpc.read_buffer; } if (bytes_to_read != 0) { int bytes_read; try { bytes_read = wpc.infile.BaseStream.Read(wpc.read_buffer, 0, (int)bytes_to_read); if (bytes_read != (int)bytes_to_read) { wpmd.hasdata = Defines.FALSE; return(Defines.FALSE); } } catch (System.Exception) { wpmd.hasdata = Defines.FALSE; return(Defines.FALSE); } } return(Defines.TRUE); }
internal static int process_metadata(WavpackContext wpc, WavpackMetadata wpmd) { WavpackStream wps = wpc.stream; switch (wpmd.id) { case Defines.ID_DUMMY: { return(Defines.TRUE); } case Defines.ID_DECORR_TERMS: { return(UnpackUtils.read_decorr_terms(wps, wpmd)); } case Defines.ID_DECORR_WEIGHTS: { return(UnpackUtils.read_decorr_weights(wps, wpmd)); } case Defines.ID_DECORR_SAMPLES: { return(UnpackUtils.read_decorr_samples(wps, wpmd)); } case Defines.ID_ENTROPY_VARS: { return(WordsUtils.read_entropy_vars(wps, wpmd)); } case Defines.ID_HYBRID_PROFILE: { return(WordsUtils.read_hybrid_profile(wps, wpmd)); } case Defines.ID_FLOAT_INFO: { return(FloatUtils.read_float_info(wps, wpmd)); } case Defines.ID_INT32_INFO: { return(UnpackUtils.read_int32_info(wps, wpmd)); } case Defines.ID_CHANNEL_INFO: { return(UnpackUtils.read_channel_info(wpc, wpmd)); } case Defines.ID_SAMPLE_RATE: { return(UnpackUtils.read_sample_rate(wpc, wpmd)); } case Defines.ID_CONFIG_BLOCK: { return(UnpackUtils.read_config_info(wpc, wpmd)); } case Defines.ID_WV_BITSTREAM: { return(UnpackUtils.init_wv_bitstream(wpc, wpmd)); } case Defines.ID_SHAPING_WEIGHTS: case Defines.ID_WVC_BITSTREAM: case Defines.ID_WVX_BITSTREAM: { return(Defines.TRUE); } default: { if ((wpmd.id & Defines.ID_OPTIONAL_DATA) != 0) { return(Defines.TRUE); } else { return(Defines.FALSE); } } break; } }