xbox 360 kinect光束角度问题与属性更改

时间:2015-04-02 15:02:55

标签: c# wpf audio kinect

尝试在C#wpf中获取光束角度,并且在If PropertyChange上抛出异常。有没有人有这个项目的例子,如果需要我可以提供更多信息。我试图让麦克风改变属性,但它正在抛出异常

        InitializeComponent();
        //Beam Angle Code
        this.DataContext = this.Rect;
        this.Loaded += delegate { ListenForBeamChanges(); };
    }

    private KinectAudioSource CreateAudioSource()
    {
        var source = KinectSensor.KinectSensors[0].AudioSource;
        source.NoiseSuppression = true;
        source.AutomaticGainControlEnabled = true;
        source.BeamAngleMode = BeamAngleMode.Adaptive;
        return source;
    }

    private KinectAudioSource audioSource;
    private void ListenForBeamChanges()
    {
        KinectSensor.KinectSensors[0].Start();
        audioSource = CreateAudioSource();
        audioSource.BeamAngleChanged += audioSource_BeamChanged;
        audioSource.Start();
    }

    public double _beamAngle;
    public double BeamAngle
    {
        get { return _beamAngle; }
        set
        {
            _beamAngle = value;
            OnPropertyChanged("BeamAngle");
        }
    }

    void audioSource_BeamChanged(object sender, BeamAngleChangedEventArgs e)
    {
        BeamAngle = e.Angle * -1;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged(string propName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }

  }
}

1 个答案:

答案 0 :(得分:0)

请参阅http://kinectaudioposition.codeplex.com

http://channel9.msdn.com/coding4fun/kinect/Kinect-Audio-Positioning

复制样本使用代码
/// <summary>
/// Event handler to care Window loaded
/// Construct KinectMicArray and draw contents
/// </summary>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    kinectMic = new KinectMicArray();
    kinectMic.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(kinectMic_PropertyChanged);
    DrawContents();
}
/// <summary>
/// Event handler to care KinectMicArray property changed
/// Showing angles as number for debug
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void kinectMic_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    KinectMicArray ka = sender as KinectMicArray;
    this.myLabel.Content = string.Format("Beam = {0:F}; Source = {1:F};  ", ka.BeamAngleProperty, ka.SourceAngleProperty); 
}