예제 #1
0
        /// <summary>
        /// Finds the converting method based on the specified formats.
        /// </summary>
        /// <param name="data">Reference to the buffer of audio data.</param>
        /// <param name="from">Audio format that the data will be converted from.</param>
        /// <param name="to">Audio format that the data will be converted to.</param>
        /// <returns>New array with the audio data in requested format.</returns>
        internal static short[] Convert(byte[] data, AudioCodec from, AudioCodec to)
        {
            ConvertByteShort cnvDlgt = null;

            switch (from)
            {
            case AudioCodec.PCM8:
                switch (to)
                {
                case AudioCodec.PCM16: cnvDlgt = new ConvertByteShort(ConvertLinear8LinearByteShort); break;
                }
                break;

            case AudioCodec.PCM16:
                switch (to)
                {
                case AudioCodec.PCM16: cnvDlgt = new ConvertByteShort(ConvertLinear2LinearByteShort); break;
                }
                break;

            case AudioCodec.G711U:
                switch (to)
                {
                case AudioCodec.PCM16: cnvDlgt = new ConvertByteShort(ConvertULaw2Linear); break;
                }
                break;

            case AudioCodec.G711A:
                switch (to)
                {
                case AudioCodec.PCM16: cnvDlgt = new ConvertByteShort(ConvertALaw2Linear); break;
                }
                break;

            default:
                throw new FormatException();
            }

            if (cnvDlgt == null)
            {
                throw new FormatException();
            }

            return(cnvDlgt(data, data.Length));
        }
예제 #2
0
        internal static short[] Convert(byte[] data, AudioCodec from, AudioCodec to)
        {
            ConvertByteShort convertByteShort = null;

            switch (from)
            {
            case AudioCodec.PCM8:
                if (to == AudioCodec.PCM16)
                {
                    convertByteShort = ConvertLinear8LinearByteShort;
                }
                break;

            case AudioCodec.PCM16:
                if (to == AudioCodec.PCM16)
                {
                    convertByteShort = ConvertLinear2LinearByteShort;
                }
                break;

            case AudioCodec.G711U:
                if (to == AudioCodec.PCM16)
                {
                    convertByteShort = ConvertULaw2Linear;
                }
                break;

            case AudioCodec.G711A:
                if (to == AudioCodec.PCM16)
                {
                    convertByteShort = ConvertALaw2Linear;
                }
                break;

            default:
                throw new FormatException();
            }
            if (convertByteShort == null)
            {
                throw new FormatException();
            }
            return(convertByteShort(data, data.Length));
        }