title: uwp AudioGraph audio processing
body: <p>I am working on a winodws IoT project that controls a led strip based on an audio input. Now do I have some code that gets the audio in and writes it to a buffer with the AudioGraph API, but I don't know how I can process the audio to some usefull data. </p>
  
  <p>my code so far:</p>
  
  <pre><code>private async void MainPage_Loaded(object sender, RoutedEventArgs eventArgs)
  {
          try
          {
              // Initialize the led strip
              //await this.pixelStrip.Begin();
  
              sampleAggregator.FftCalculated += new EventHandler&lt;FftEventArgs&gt;(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;
  
  
          }
      }
  </code></pre>
  
  <p>So I end with my buffer as a float. But how can i change this to usefull data that makes it possible to create something like a spectrum analyzer?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Maybe I have to make this question less specific for the audiograph. I use an API to get my audio input. The data I get from the API is a byte* and I can cast it to a float* How can I change it from the byte* or the float* to some other data that I can use to create some color codes.</p>
  
  <p>I thaught about doing some FFT analysis on the float* to get 164 leds*3(rgb) = 492 bins. And process this data further to get some values between 0 and 255.</p>
  
  <p>So how can I process this float* or byte* to get this usefull data? Or how do I start?</p>