コード例 #1
0
        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));
            }
        }
コード例 #2
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);
        }