Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

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_SourceCode.zip
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
Settings.settings
StyleCop.Cache
OpenDISRadioTransmitterSolution.suo
RadioFeatureSelection
bin
Properties
Sockets
bin
Properties
#region Header

// Copyright (c) 1995-2009 held by the author(s).  All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
//  are met:
//
//  * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the names of the Naval Postgraduate School (NPS)
//  Modeling Virtual Environments and Simulation (MOVES) Institute
// (http://www.nps.edu and http://www.MovesInstitute.org)
// nor the names of its contributors may be used to endorse or
//  promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

#endregion Header

namespace DISnet.DataStreamUtilities
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;

    /* Author Peter Smith (Naval Air Warfare Center - Training Systems Division) 01/23/2009
    * Modifications: none
    * Notes:
    */
    /// <summary>
    /// Base class for storing PDU information
    /// </summary>
    public class DataStream
    {
        #region Fields

        //Location to store a byte representation of the PDU
        public byte[] byteStream;

        //Create the MemoryStream that will be used to hold the PDU data
        public MemoryStream msPDU;

        //Counter used to keep track of where pointer is for the stream
        public int streamCounter;

        //Test the machine to determine to see what it supports, this will be the default but can be overridden via constructor
        private DISnet.DataStreamUtilities.EndianTypes.Endian endianType = (BitConverter.IsLittleEndian ? DISnet.DataStreamUtilities.EndianTypes.Endian.LITTLE : DISnet.DataStreamUtilities.EndianTypes.Endian.BIG);

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create new DataStream.  This will store all PDU information for either an InputStream or OutputStream
        /// </summary>
        public DataStream()
        {
            //Set default counter value to 0
            streamCounter = 0;
            //Create a new MemoryStream
            msPDU = new MemoryStream();
        }

        #endregion Constructors

        #region Properties

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

            set
            {
                endianType = value;
            }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Appends the byte array data to the MemoryStream
        /// </summary>
        /// <param name="data">byte array</param>
        public void Append(byte[] data)
        {
            msPDU.Seek(msPDU.Length, SeekOrigin.Begin);
            msPDU.Write(data, 0, data.Length);
        }

        /// <summary>
        /// Appends a single byte to the MemoryStream
        /// </summary>
        /// <param name="data"></param>
        public void Append(byte data)
        {
            msPDU.Seek(msPDU.Length, SeekOrigin.Begin);
            msPDU.WriteByte(data);
        }

        /// <summary>
        /// Convert a MemoryStream to a byte array
        /// </summary>
        /// <returns>byte array</returns>
        public byte[] ConvertToBytes()
        {
            byte[] returnBytes;

            ReturnByteArray(msPDU.GetBuffer(), 0, (int)msPDU.Length, out returnBytes);  //PES 09082009

            return returnBytes;
        }

        /// <summary>
        /// Used primarily to return a portion of a byte array for Endian conversion
        /// </summary>
        /// <param name="byteStream">source bytearray</param>
        /// <param name="startIndex">A 32-bit integer that represents the start index at which the conversion should begin</param>
        /// <param name="sizeOfData">A 32-bit integer that represents the size of the value type</param>
        /// <param name="temp">A byte array that will hold the byte representation of the value</param>
        public void ReturnByteArray(byte[] byteStream, int startIndex, int sizeOfData, out byte[] temp)
        {
            temp = new byte[sizeOfData];
            Array.Copy(byteStream, startIndex, temp, 0, sizeOfData);
        }

        /// <summary>
        /// Re-Initializes the MemoryStream and streamCounter back to zero
        /// </summary>
        public void clear()
        {
            streamCounter = 0;
            msPDU = new MemoryStream();
        }

        #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

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 15 Mar 2010
Article Copyright 2010 by pesmith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid