Click here to Skip to main content
12,243,058 members (46,117 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

20.9K views
1.4K downloads
22 bookmarked
Posted

Using OpenTK/OpenAL to Develop Cross Platform DIS VOIP Application

, 15 Mar 2010 BSD
Application allows voice communications (VOIP) utilizing the Distributed Interactive Simulation protocol (IEEE 1278.1)
MonoDISRadioTransmitter
AudioIN
bin
Properties
StyleCop.Cache
AudioOUT
bin
Properties
DISNET
bin
DataStreams
DISPDU
Enumerations
Properties
Utilities
OpenDISRadioTransmitterExample
AudioCodecs
bin
OpenDISRadioTransmitter.csproj.user
OpenTK
OpenTK.Compatibility.dll
OpenTK.dll
OpenTK.GLControl.dll
Properties
StyleCop.Cache
OpenDISRadioTransmitterSolution.suo
RadioFeatureSelection
bin
Properties
Sockets
bin
Properties
namespace DISnet.DataStreamUtilities
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Runtime.Serialization;
    using System.Text;

    /* Author Peter Smith (Naval Air Warfare Center - Training Systems Division) 01/23/2009
    * Modifications: none
    * Notes:
    */
    /// <summary>
    /// Class used to export PDU information from a DataStream
    /// </summary>
    public class DataOutputStream
    {
        #region Fields

        //Instatiate a new DataStream for outputting data
        DISnet.DataStreamUtilities.DataStream dsPDU = new DataStream();

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor to create the DataOutputStream
        /// </summary>
        public DataOutputStream(DISnet.DataStreamUtilities.EndianTypes.Endian endian)
        {
            dsPDU = new DataStream();
            Endian = endian;
        }

        /// <summary>
        /// Constructor to create a DataOutputStream from an existing DataStream and setting the type of Endian to use
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="endian"></param>
        public DataOutputStream(DISnet.DataStreamUtilities.DataStream ds, DISnet.DataStreamUtilities.EndianTypes.Endian endian)
        {
            dsPDU = ds;
            Endian = endian;
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Get the underlining DataStream
        /// </summary>
        public DataStream DS
        {
            get
            {
                return this.dsPDU;
            }
        }

        /// <summary>
        /// Gets or Sets the Endian type
        /// </summary>
        public DISnet.DataStreamUtilities.EndianTypes.Endian Endian
        {
            get
            {
                return this.DS.Endian;
            }

            set
            {
                this.DS.Endian = value;
            }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Converts the DataStream to a byte array
        /// </summary>
        /// <returns>byte array</returns>
        public byte[] ConvertToBytes()
        {
            return DS.ConvertToBytes();
        }

        /// <summary>
        /// Write a byte value to the DataStream
        /// </summary>
        /// <param name="data">byte</param>
        public void writeByte(byte data)
        {
            WriteData(data);
        }

        /// <summary>
        /// Write a byte array value to the DataStream
        /// </summary>
        /// <param name="data">byte</param>
        public void writeByte(byte[] data)
        {
            WriteData(data);
        }

        /// <summary>
        /// Write a double value to the DataStream
        /// </summary>
        /// <param name="data">double</param>
        public void writeDouble(double data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a float value to the DataStream
        /// </summary>
        /// <param name="data">float</param>
        public void writeFloat(float data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a int value to the DataStream
        /// </summary>
        /// <param name="data">int32</param>
        public void writeInt(int data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a long value to the DataStream
        /// </summary>
        /// <param name="data">long</param>
        public void writeLong(long data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a short value to the DataStream
        /// </summary>
        /// <param name="data">short value</param>
        public void writeShort(short data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a unsigned int value to the DataStream
        /// </summary>
        /// <param name="data">unsigned int</param>
        public void writeUint(uint data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a unsigned long value to the DataStream
        /// </summary>
        /// <param name="data">long</param>
        public void writeUlong(ulong data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Write a unsigned short value to the DataStream
        /// </summary>
        /// <param name="data">unsigned short</param>
        public void writeUshort(ushort data)
        {
            byte[] serializedData = System.BitConverter.GetBytes(data);

            if (this.Endian == DISnet.DataStreamUtilities.EndianTypes.Endian.BIG)
            {
                Array.Reverse(serializedData);
            }

            WriteData(serializedData);
        }

        /// <summary>
        /// Base method to write a byte value to the DataStream
        /// </summary>
        /// <param name="data">byte</param>
        private void WriteData(byte data)
        {
            dsPDU.Append(data);
            dsPDU.streamCounter += 1;
        }

        /// <summary>
        /// Base method to write an array of bytes to the DataStream
        /// </summary>
        /// <param name="data">byte array</param>
        private void WriteData(byte [] data)
        {
            dsPDU.Append(data);
            dsPDU.streamCounter += data.Length;
        }

        #endregion Methods
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

pesmith
Software Developer
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160426.1 | Last Updated 15 Mar 2010
Article Copyright 2010 by pesmith
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid