internal void AddData(VitaIFDataPacket packet) { TotalCount++; #if DEBUG_STATS if (total_count % 1000 == 0) { PrintStats(); } #endif lock (this) { _byteSum += packet.Length; //Debug.WriteLine("packet.Length: " + packet.Length); } int packet_count = packet.header.packet_count; OnDataReady(this, packet.payload); // normal case -- this is the next packet we are looking for, or it is the first one if (packet_count == (last_packet_count + 1) % 16 || last_packet_count == NOT_INITIALIZED) { last_packet_count = packet_count; } else { error_count_out_of_order++; ErrorCount++; last_packet_count = packet_count; } }
public void AddTXData(float[] tx_data) { // skip this if we are not the DAX TX Client if (!_transmit) { return; } if (_txPacket == null) { _txPacket = new VitaIFDataPacket(); _txPacket.header.pkt_type = VitaPacketType.IFDataWithStream; _txPacket.header.c = true; _txPacket.header.t = false; _txPacket.header.tsi = VitaTimeStampIntegerType.Other; _txPacket.header.tsf = VitaTimeStampFractionalType.SampleCount; _txPacket.stream_id = _txStreamID; _txPacket.class_id.OUI = 0x001C2D; _txPacket.class_id.InformationClassCode = 0x543C; _txPacket.class_id.PacketClassCode = 0x03E3; } int samples_sent = 0; //Debug.WriteLine("<" + tx_data.Length+">"); while (samples_sent < tx_data.Length) { // how many samples should we send? int num_samples_to_send = Math.Min(256, tx_data.Length - samples_sent); _txPacket.payload = new float[num_samples_to_send]; // copy the incoming data into the packet payload Array.Copy(tx_data, samples_sent, _txPacket.payload, 0, num_samples_to_send); // set the length of the packet _txPacket.header.packet_size = (ushort)(num_samples_to_send + 7); // 7*4=28 bytes of Vita overhead // send the packet to the radio //Debug.WriteLine("sending from channel " + _daxChannel); try { _txSocket.SendTo(_txPacket.ToBytes(), _txDataEndPoint); } catch (Exception e) { Debug.WriteLine("TXAudioStream: AddTXData Exception (" + e.ToString() + ")"); } //Debug.Write("("+num_samples_to_send+")"); // bump the packet count _txPacket.header.packet_count = (byte)((_txPacket.header.packet_count + 1) % 16); // adjust the samples sent samples_sent += num_samples_to_send; } }