bewantbe / audio-analyzer-for-android

A fork of audio-analyzer-for-android in Google code, with a lot of enhancement.
Apache License 2.0
284 stars 116 forks source link

Audio Spectrum Analyzer for Android

A fork of Audio spectrum Analyzer for Android (See README.old for its original readme)

This software shows the frequency components' magnitude distribution (called spectrum) of the sound heard by your cell phone. Can be used to help tuning musical instrument or tone in singing, (tentative) measure environmental noise and sound revent education or experiments.

You can install this app through Google Play Store: Audio Spectrum Analyzer. Comments are welcome.

This software, Audio Spectrum Analyzer for Android, is released under the Apache License, Version 2.0.

Features

Installation Requirements

Permissions:

Development

git clone then open it use Android Studio. Install the SDK platform if requested (e.g. rev 116 needs API level 20), or tune the compileSdkVersion to the value that fits your needs.

(Notes on project import for old revision (rev <= 115))

Code structure

The whole program structure is roughly follows the MVC model:

AnalyzerActivity.java is the controler, as the main activity, it receives user inputs and system events, then sent corresponding commands to views or sampling and analyzing procedures.

AnalyzerViews.java is the view in MVC. It is used to manage (initialization, display, refresh) UI texts, buttons, dialogs and graphics. AnalyzerGraphic.java is a main sub-view which manage display of spectrum(SpectrumPlot.java) and spectrogram(SpectrogramPlot.java).

SamplingLoop.java is more or less the "model" part. It performs the sampling and FFT analysis, and inform the graphics update.

Processing of audio samples

The data process loop is located in run() in SamplingLoop.java (after commit c9e430b (Feb 06, 2017), but basicly this process didn't change since the initial commit), as well as the trigger of graphics refresh.

In every loop of while (isRunning), it reads a chunk of audio samples by

record.read(audioSamples, 0, readChunkSize);

, then "stream" it to STFT.java by

stft.feedData(audioSamples, numOfReadShort);

which calculates RMS and FFT whenever enough data is collected. The view is then informed through

activity.analyzerViews.update(spectrumDBcopy);

which ultimately calls invalidate() of the graphic view to request an update, then the AnalyzerGraphic.onDraw(Canvas c) will be called automatically.

Thanks

The code Audio spectrum Analyzer for Android gives me a good starting point, for learning Java and write this software (that I desired long ago).