Exemple #1
0
        public static AudioClip DncodeAdpcmData(byte[] adpcmData)
        {
            if (adpcmData == null || adpcmData.Length < 8)
            {
                return(null);
            }

            try {
                //channels
                byte[] bytes = new byte[4];
                Buffer.BlockCopy(adpcmData, 0, bytes, 0, bytes.Length);
                int channels = (int)BitConverter.ToUInt32(bytes, 0);
                //frequency
                bytes = new byte[4];
                Buffer.BlockCopy(adpcmData, 4, bytes, 0, bytes.Length);
                int frequency = (int)BitConverter.ToUInt32(bytes, 0);
                //adpcmData
                bytes = new byte[adpcmData.Length - 8];
                Buffer.BlockCopy(adpcmData, 8, bytes, 0, bytes.Length);
                short[] data = adpcm.Decode(bytes);
                return(RTMAudioManager.ShortsToAudioClip(data, channels, frequency, false, 1.0f));
            } catch (Exception ex) {
                Debug.LogWarning(ex);
            }
            return(null);
        }
        private AudioClip GetAudioClip()
        {
            lock (self_locker) {
                if (this._clipRecord == null)
                {
                    return(null);
                }

                short[] data = RTMAudioManager.AudioClipToShorts(this._clipRecord, 1.0f);
                return(RTMAudioManager.ShortsToAudioClip(data, this._clipRecord.channels, this._clipRecord.frequency, false, 1.0f));
            }
        }
Exemple #3
0
        public static byte[] EncodeAudioClip(AudioClip clip)
        {
            byte[]  bytes;
            short[] data;
            int     channels  = 1;
            int     frequency = RTMMicrophone.SAMPLE_RATE;

            if (clip == null)
            {
                return(null);
            }

            channels  = clip.channels;
            frequency = clip.frequency;

            try {
                data = RTMAudioManager.AudioClipToShorts(clip, 1.0f);

                if (data == null)
                {
                    return(null);
                }

                byte[] adpcmData = adpcm.Encode(data);

                if (adpcmData == null || adpcmData.Length == 0)
                {
                    return(null);
                }

                using (MemoryStream stream = new MemoryStream()) {
                    //channels
                    bytes = BitConverter.GetBytes(channels);
                    stream.Write(bytes, 0, bytes.Length);
                    //frequency
                    bytes = BitConverter.GetBytes(frequency);
                    stream.Write(bytes, 0, bytes.Length);
                    //adpcmData
                    stream.Write(adpcmData, 0, adpcmData.Length);
                    bytes = stream.ToArray();
                }
                return(bytes);
            } catch (Exception ex) {
                Debug.LogWarning(ex);
            }
            return(null);
        }