private Answer BuildAnswer() { Dictionary <Object, Object> payload = MsgUnpacker.Unpack(bodyBuffer, 4, requireLength - 4); bool isErrorAnswer = (headerBuffer[7] != 0); return(new Answer(FetchSeqNum(), isErrorAnswer, payload)); }
private Quest BuildQuest() { string method; UInt32 seqNum; Dictionary <Object, Object> payload; UTF8Encoding utf8Encoding = new UTF8Encoding(false, true); //-- NO BOM. if (isTwowayQuest) { seqNum = FetchSeqNum(); method = utf8Encoding.GetString(bodyBuffer, 4, headerBuffer[7]); payload = MsgUnpacker.Unpack(bodyBuffer, 4 + headerBuffer[7], requireLength - 4 - headerBuffer[7]); } else { seqNum = 0; method = utf8Encoding.GetString(bodyBuffer, 0, headerBuffer[7]); payload = MsgUnpacker.Unpack(bodyBuffer, headerBuffer[7], requireLength - headerBuffer[7]); } return(new Quest(method, !isTwowayQuest, seqNum, payload)); }
private void ParseAudioData(byte[] audio) { rtmAudioHeader = new RTMAudioHeader(); int offset = 0; if (audio.Length < 4) { return; } rtmAudioHeader.version = audio[0]; rtmAudioHeader.containerType = (RTMAudioHeader.ContainerType)audio[1]; rtmAudioHeader.codecType = (RTMAudioHeader.CodecType)audio[2]; byte infoDataCount = audio[3]; offset += 4; for (byte i = 0; i < infoDataCount; i++) { int sectionLength = BitConverter.ToInt32(audio, offset); offset += 4; Dictionary <Object, Object> infoData = MsgUnpacker.Unpack(audio, offset, sectionLength); object value; if (infoData.TryGetValue("lang", out value)) { rtmAudioHeader.lang = (string)value; } if (infoData.TryGetValue("dur", out value)) { rtmAudioHeader.duration = Convert.ToInt64(value); duration = rtmAudioHeader.duration; } if (infoData.TryGetValue("srate", out value)) { rtmAudioHeader.sampleRate = Convert.ToInt32(value); frequency = rtmAudioHeader.sampleRate; } offset += sectionLength; } if (offset >= audio.Length) { return; } byte[] amrBuffer = new byte[audio.Length - offset]; Array.Copy(audio, offset, amrBuffer, 0, audio.Length - offset); byte[] wavBuffer = AudioConvert.ConvertToWav(amrBuffer); int channelCount = wavBuffer[22]; int pos = 12; while (!(wavBuffer[pos] == 100 && wavBuffer[pos + 1] == 97 && wavBuffer[pos + 2] == 116 && wavBuffer[pos + 3] == 97)) { pos += 4; int chunkSize = wavBuffer[pos] + wavBuffer[pos + 1] * 256 + wavBuffer[pos + 2] * 65536 + wavBuffer[pos + 3] * 16777216; pos += 4 + chunkSize; } pos += 8; samples = (wavBuffer.Length - pos) / 2; pcmData = new float[samples]; int idx = 0; while (pos < wavBuffer.Length) { pcmData[idx] = BytesToFloat(wavBuffer[pos], wavBuffer[pos + 1]); pos += 2; idx++; } }