示例#1
0
        //private static void Reader_FrameArrived(object sender, AudioBeamFrameArrivedEventArgs e) {
        //}

        private static void UpdateAudio()
        {
            audioFrameAvailable = false;
            if (audioReader != null)
            {
                IList <AudioBeamFrame> frames = audioReader.AcquireLatestBeamFrames();
                for (int i = 0; i < frames.Count; i++)
                {
                    AudioBeamFrame frame = frames[i];
                    if (frame != null)
                    {
                        audioFrameAvailable = true;
                        IList <AudioBeamSubFrame> subframes = frame.SubFrames;

                        for (int j = 0; j < subframes.Count; j++)
                        {
                            AudioBeamSubFrame subframe = subframes[j];
                            if (subframe != null)
                            {
                                beamAngle = subframe.BeamAngle;
                                ProcessAudio(subframe);
                                subframe.Dispose();
                            }
                        }
                        frame.Dispose();
                    }
                }
            }
        }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        var l_frames = i_reader.AcquireLatestBeamFrames();

        print(l_frames.Count);
        if (l_frames != null)
        {
            //using (l_frames)
            {
                foreach (AudioBeamFrame l_frame in l_frames)
                {
                    if (l_frame == null)
                    {
                        print("null");
                        continue;
                    }
                    print(l_frame.SubFrames.Count);
                    foreach (var l_subframe in l_frame.SubFrames)
                    {
                        l_subframe.Dispose();
                    }
                    l_frame.Dispose();
                }
            }
        }
        //((IDisposable)l_frames).Dispose();
        ++i;
    }
    private void ProcessAudioFrame()
    {
        IList <AudioBeamFrame> frameList = audioReader.AcquireLatestBeamFrames();

        //AudioBeamFrameList frameList = (AudioBeamFrameList)reader.AcquireLatestBeamFrames();

        if (frameList != null)
        {
            if (frameList[0] != null)
            {
                if (frameList[0].SubFrames != null && frameList[0].SubFrames.Count > 0)
                {
                    // Only one audio beam is supported. Get the sub frame list for this beam
                    List <AudioBeamSubFrame> subFrameList = frameList[0].SubFrames.ToList();

                    // Loop over all sub frames, extract audio buffer and beam information
                    foreach (AudioBeamSubFrame subFrame in subFrameList)
                    {
                        // Check if beam angle and/or confidence have changed
                        bool updateBeam = false;

                        if (subFrame.BeamAngle != this.beamAngleRad)
                        {
                            this.beamAngleRad = subFrame.BeamAngle;
                            this.beamAngleDeg = this.beamAngleRad * 180.0f / Mathf.PI;
                            updateBeam        = true;

                            //Debug.Log("beam angle: " + beamAngleDegrees);
                        }

                        if (subFrame.BeamAngleConfidence != this.beamAngleConfidence)
                        {
                            this.beamAngleConfidence = subFrame.BeamAngleConfidence;
                            updateBeam = true;

                            //Debug.Log("beam angle confidence: " + beamAngleRadians);
                        }

                        if (updateBeam)
                        {
                            // Refresh display of audio beam
                            if (statusText)
                            {
                                statusText.text = string.Format("Audio beam angle: {0:F0} deg., Confidence: {1:F0}%", beamAngleDeg, beamAngleConfidence * 100f);
                            }
                        }
                    }
                }
//                else
//                {
//                    this.beamAngle = frameList[0].AudioBeam.BeamAngle;
//                    Debug.Log("No SubFrame: "+ frameList[0].AudioBeam.BeamAngle);
//                }
            }
//            else
//            {
//                Debug.Log("Empty Audio Frame: "+ audioSource.AudioBeams.Count());
//                if (audioSource.AudioBeams.Count() > 0)
//                    Debug.Log(audioSource.AudioBeams[0].BeamAngle);
//
//            }
        }
//        else
//        {
//            Debug.Log("Empty Audio Frame");
//        }

        // clean up
        for (int i = frameList.Count - 1; i >= 0; i--)
        {
            AudioBeamFrame frame = frameList[i];

            if (frame != null)
            {
                frame.Dispose();
            }
        }

        //frameList.Clear();
    }
示例#4
0
 public AudioBeamFrameList PollAudio()
 {
     return(_audioReader.AcquireLatestBeamFrames());
 }