Tôi đang làm việc trên một dự án IoT winodws điều khiển dải dẫn dựa trên đầu vào âm thanh. Bây giờ tôi có một số mã được âm thanh trong và viết nó vào một bộ đệm với API AudioGraph, nhưng tôi không biết làm thế nào tôi có thể xử lý âm thanh cho một số dữ liệu hữu ích.xử lý âm thanh uwp âm thanh uwp
mã của tôi cho đến nay:
private async void MainPage_Loaded(object sender, RoutedEventArgs eventArgs)
{
try
{
// Initialize the led strip
//await this.pixelStrip.Begin();
sampleAggregator.FftCalculated += new EventHandler<FftEventArgs>(FftCalculated);
sampleAggregator.PerformFFT = true;
// Create graph
AudioGraphSettings settings = new AudioGraphSettings(AudioRenderCategory.Media);
settings.DesiredSamplesPerQuantum = fftLength;
settings.DesiredRenderDeviceAudioProcessing = Windows.Media.AudioProcessing.Default;
settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.ClosestToDesired;
CreateAudioGraphResult result = await AudioGraph.CreateAsync(settings);
if (result.Status != AudioGraphCreationStatus.Success)
{
// Cannot create graph
return;
}
graph = result.Graph;
// Create a device input node using the default audio input device
CreateAudioDeviceInputNodeResult deviceInputNodeResult = await graph.CreateDeviceInputNodeAsync(MediaCategory.Other);
if (deviceInputNodeResult.Status != AudioDeviceNodeCreationStatus.Success)
{
return;
}
deviceInputNode = deviceInputNodeResult.DeviceInputNode;
frameOutputNode = graph.CreateFrameOutputNode();
frameOutputNode.Start();
graph.QuantumProcessed += AudioGraph_QuantumProcessed;
// Because we are using lowest latency setting, we need to handle device disconnection errors
graph.UnrecoverableErrorOccurred += Graph_UnrecoverableErrorOccurred;
graph.Start();
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
private void AudioGraph_QuantumProcessed(AudioGraph sender, object args)
{
AudioFrame frame = frameOutputNode.GetFrame();
ProcessFrameOutput(frame);
}
unsafe private void ProcessFrameOutput(AudioFrame frame)
{
using (AudioBuffer buffer = frame.LockBuffer(AudioBufferAccessMode.Write))
using (IMemoryBufferReference reference = buffer.CreateReference())
{
byte* dataInBytes;
uint capacityInBytes;
float* dataInFloat;
// Get the buffer from the AudioFrame
((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacityInBytes);
dataInFloat = (float*)dataInBytes;
}
}
Vì vậy, tôi kết thúc với đệm của tôi như là một phao. Nhưng làm thế nào tôi có thể thay đổi điều này thành dữ liệu hữu ích mà làm cho nó có thể tạo ra một cái gì đó giống như một máy phân tích phổ?
Edit:
Có lẽ tôi phải đưa ra câu hỏi này ít cụ thể hơn cho các máy không ảnh. Tôi sử dụng một API để có được đầu vào âm thanh của tôi. Dữ liệu tôi nhận được từ API là một byte * và tôi có thể truyền nó thành một float * Làm thế nào tôi có thể thay đổi nó từ byte * hoặc float * sang một số dữ liệu khác mà tôi có thể sử dụng để tạo một số mã màu.
Tôi thaught về làm một số phân tích FFT trên phao * để có được 164 led * 3 (rgb) = 492 thùng. Và xử lý dữ liệu này xa hơn để nhận được một số giá trị từ 0 đến 255.
Vậy làm cách nào để xử lý phao * hoặc byte * này để nhận dữ liệu hữu ích này? Hoặc làm thế nào để tôi bắt đầu?
Bạn có thể xem https://github.com/filoe/cscore, có một mẫu được bao gồm (xem hình bên dưới) –