查找UWP音频输出的数据

时间:2018-03-07 09:38:47

标签: c# audio uwp

有一天,当我在UWP中测试AudioGraph时,我发现了一个不稳定的数据......但是我认为这是频率的振荡或类似的振荡,现在我找不到了,我不记得它是不是:AudioGraph,AudioFileInputNode或AudioDeviceOutputNode(我认为AudioDeviceOutputNode,但我不确定)。

这是一个振荡的值,大约在250000左右(类似的东西)。

我有兴趣找到这个值,然后计算各种频率...

(该值以graph.LatencyInSamples振荡但更高..(timer_tick方法))

MainPage.xaml中:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
        <Button x:Name="btnChooseFile" Content="Choose File" Click="btnChooseFile_Click" Height="32" Width="250" />
        <Button x:Name="btnStop" Content="Play - Stop" Click="btnStop_Click" Height="32" Width="250" />
        <TextBlock x:Name="txbLevel" HorizontalAlignment="Left" TextWrapping="Wrap" Margin="0,10"/>
    </StackPanel>
</Grid>

MainPage.xaml.cs中:

public sealed partial class MainPage : Page
{
    private AudioGraph graph;
    private AudioFileInputNode fileInputNode;
    private AudioDeviceOutputNode deviceOutputNode;
    DispatcherTimer timer = new DispatcherTimer();
    bool playing = false;

    public MainPage()
    {
        this.InitializeComponent();
        timer.Interval = new TimeSpan(0,0,0,0,1);
        timer.Tick += timer_tick;
    }

    private void timer_tick(object sender, object e)
    {
        txbLevel.Text = graph.LatencyInSamples.ToString();
    }

    private async void btnChooseFile_Click(object sender, RoutedEventArgs e)
    {
        await CreateAudioGraph();
        FileOpenPicker filePicker = new FileOpenPicker();
        filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
        filePicker.FileTypeFilter.Add(".mp3");
        filePicker.FileTypeFilter.Add(".wma");
        filePicker.FileTypeFilter.Add(".wav");
        filePicker.ViewMode = PickerViewMode.Thumbnail;
        StorageFile file = await filePicker.PickSingleFileAsync();
        if (file == null)
        {
            return;
        }
        CreateAudioFileInputNodeResult fileInputResult = await graph.CreateFileInputNodeAsync(file);
        fileInputNode = fileInputResult.FileInputNode;
        fileInputNode.AddOutgoingConnection(deviceOutputNode);
        graph.Start();
        timer.Start();
        playing = true;
    }

    private async Task CreateAudioGraph()
    {
        AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Media);
        CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);
        graph = result.Graph;
        CreateAudioDeviceOutputNodeResult outputDeviceNodeResult = await graph.CreateDeviceOutputNodeAsync();
        deviceOutputNode = outputDeviceNodeResult.DeviceOutputNode;
    }

    private void btnStop_Click(object sender, RoutedEventArgs e)
    {
        if (playing)
        {
            graph.Stop();
            playing = false;
        }
        else
        {
            graph.Start();
            playing = true;
        }
    }
}

帮助?

非常感谢..!

0 个答案:

没有答案