0

I am trying to get the audio spectrum from the microphone stream on an Android. I am using TarsosDSP to do the heavy lifting. But cannot seem to get results that make any sense in the process event. I am trying to get 8 frequencies and show their magnitudes real time. I am using the SpectrumPeakAnalyser class but I dont know if thats the right one to use. Here is the relevant code on the process event:

    public static int SAMPLE_RATE = 22050;
    public static int BUFFER_SIZE = 1024;
    public static int OVERLAP = 0; 

AudioDispatcher dispatcher = AudioDispatcherFactory.FromDefaultMicrophone(SAMPLE_RATE, BUFFER_SIZE, OVERLAP); spectralPeakFollower = new SpectralPeakProcessor(BUFFER_SIZE, OVERLAP, SAMPLE_RATE); dispatcher.AddAudioProcessor(spectralPeakFollower);

And in the process event

        var magnitudes = spectralPeakFollower.GetMagnitudes();
        var freqencies = spectralPeakFollower.GetFrequencyEstimates();

        float[] noiseFloor = SpectralPeakProcessor.CalculateNoiseFloor(magnitudes, BUFFER_SIZE / 2, 1f);
        var localMaximaIndexes = SpectralPeakProcessor.FindLocalMaxima(magnitudes, noiseFloor);
        var peaks = SpectralPeakProcessor.FindPeaks(magnitudes, freqencies, localMaximaIndexes, 8, 80);

I cannot seem to find any examples that fit this scenario as I do not care about peaks, I just want the real time magnitudes. Thank you for any help you can offer.

vbisbest
  • 241
  • 1
  • 14
  • be aware of the relationship between number of samples in your window of data you feed into the Fourier Transform api call ... especially your desired frequency resolution in the output of that call ... get tight with notion of the Nyquist Limit ... take notice of the possibility the api result may hand you its answer as a set of complex points ... lookup the formula to determine frequency magnitude given one such complex point in api result ... bonus points if you have already layed out a set of toy input samples in time domain and confirm each is good once it gets transformed to freq domain – Scott Stensland Aug 29 '18 at 03:48
  • I am thinking that you are correct that the issue revolves around the number of samples. But I dont know what to use. The api gives everything broken out: magnitude and freqency, not complex points, so thats good. – vbisbest Aug 29 '18 at 07:32
  • buffer size should be a power of 2 ... make it 16383 ... too high incurs compute costs too low you loose frequency granularity ... to have high frequency granularity you may entertain possibility of a sliding window of samples where each overlaps – Scott Stensland Aug 29 '18 at 11:26

0 Answers0