private void Dispose(bool disposing)
        {
            isRunning = false;

            if (audioCaptureThread != null &&
                audioCaptureThread.IsAlive)
            {
                audioCaptureThread.Join(200);

                if (audioCaptureThread.IsAlive)
                {
                    audioCaptureThread.Abort();
                }
                audioCaptureThread = null;
            }

            if (kinectStream != null)
            {
                kinectStream.Dispose();
                kinectStream = null;
            }
            if (kinectSource != null)
            {
                kinectSource.Stop();
                kinectSource = null;
            }
            if (energyStream != null)
            {
                energyStream.Dispose();
                energyStream = null;
            }
        }
        public void Start()
        {
            isRunning = true;
            kinectSource.BeamAngleMode = BeamAngleMode.Adaptive;
            kinectSource.AutomaticGainControlEnabled = false;
            recordingLength = 0;

            kinectStream                = kinectSource.Start();
            energyStream                = new AudioStreamEnergy(kinectStream);
            audioCaptureThread          = new Thread(CaptureAudio);
            audioCaptureThread.Priority = ThreadPriority.Highest;
            audioCaptureThread.Name     = "Kinect audio capture";
            audioCaptureThread.Start();
        }