static void Main(string[] args) { String input_path = "F:\\work\\tmp\\capturedPCM_ffmpeg_stdout_converted_8000Hz_u8bit_1ch_120sec.raw"; String output_path = "F:\\work\\tmp\\capturedPCM_ffmpeg_stdout_converted_8000Hz_u8bit_1ch_120sec_encoded_my_DPCM_codec.raw"; MemoryStream ms = new MemoryStream(); byte[] buf = new byte[1024]; var reader = new FileStream(input_path, FileMode.Open); int readBytes; try { while ((readBytes = reader.Read(buf, 0, buf.Length)) > 0) { ms.Write(buf, 0, readBytes); } } finally { ms.Flush(); reader.Close(); } var encoder = new MyDpcmCodec(); var decoder = new MyDpcmCodec(); //Utils.saveByteArrayToFile(decoder.Decode(encoder.Encode(ms.ToArray())), output_path); Utils.saveByteArrayToFile(decoder.Decode(encoder.Encode(ms.ToArray())), output_path); }
private void Socket_EndDataRecievedCallback() { if (GlobalConfiguration.isUseLossySoundDecoder) { //var data = mp3data_ms.ToArray(); encoded_frame_ms.Position = 0; if (m_Player.Opened == false) { if (GlobalConfiguration.isEncodeWithOpus) { m_Player.Open("hoge", GlobalConfiguration.SamplesPerSecond, config.BitsPerSample, config.Channels, config.BufferCount); m_Player.Play(); //concentusOpusDecoder = OpusDecoder.Create(GlobalConfiguration.SamplesPerSecond, config.Channels); concentusOpusDecoder = OpusDecoder.Create(GlobalConfiguration.SampleRateDummyForSoundEnDecoder, config.Channels); //m_DPlayer.setup(RTPConfiguration.SamplesPerSecond, config.Channels, -1, csd_0, "opus"); } else { throw new Exception("illigal flag setting on RTPConfiguration."); } } byte[] data_buf = new byte[encoded_frame_ms.Length - encoded_frame_ms.Position]; encoded_frame_ms.Read(data_buf, 0, data_buf.Length); int frameSize = GlobalConfiguration.samplesPerPacket; // must be same as framesize used in input, you can use OpusPacketInfo.GetNumSamples() to determine this dynamically short[] outputBuffer = new short[frameSize]; int thisFrameSize = concentusOpusDecoder.Decode(data_buf, 0, data_buf.Length, outputBuffer, 0, frameSize, false); m_Player.WriteData(Utils.convertShortArrToBytes(outputBuffer), false); return; } else { Byte[] justSound_buf = encoded_frame_ms.ToArray(); Byte[] linearBytes = justSound_buf; //if (!RTPConfiguration.isUseSoundDecoder && m_Player.Opened == false) //{ // m_Player.Open("hoge", RTPConfiguration.SamplesPerSecond, config.BitsPerSample, config.Channels, config.BufferCount); //} if (config.isConvertMulaw) { linearBytes = SoundUtils.MuLawToLinear(justSound_buf, config.BitsPerSample, config.Channels); } if (GlobalConfiguration.isUseDPCM) { if (dpcmDecoder == null) { dpcmDecoder = new MyDpcmCodec(); } linearBytes = dpcmDecoder.Decode(linearBytes); } if (!GlobalConfiguration.isUseLossySoundDecoder && m_Player.Opened == false) { m_Player.Open("hoge", GlobalConfiguration.SamplesPerSecond, config.BitsPerSample, config.Channels, config.BufferCount); m_Player.Play(); } m_Player.WriteData(linearBytes, false); //totalWroteSoundData += linearBytes.Length; //if(totalWroteSoundData > config.BufferCount && m_Player.isPlayingStarted == false) //{ // m_Player.Play(); //} } }