# Using FFT to Unit Test a Music Player

I'd like to validate changes to our app music player in our Continuous Integration unit tests (more like integration tests, really). My thoughts were to start with an audio file that contains only a pure tone, or a series of pure tones. Our automated test would stream this file over the internet and play it through our player. We would capture the output using MTAudioProcessingTap. This output would go through and FFT and the pass/fail test would be check for the existence of only the original frequencies.

Would this work? I'm thinking this would catch pops and glitches, but not necessarily discontinuities in the output.

The phase vocoder algorithm used with overlapped FFT frames might easily catch certain kinds of discontinuities in pure sine waves.

If the audio file is compressed, note that this process itself may add certain kinds of distortion. So you would need to find an experimental threshold.

Recently I did similar thing and I can suggest you some solutions:

• Play $1kHz$ sinusoid at a given level of some arbitrary length (mostly bit longer = better), then you can tell what is the gain of your system, and calculate its THD. Additionally if you signal is long enough then you might also notice any disruptions in it. For that you can use energy envelope of the received signal. In your case you might want to calculate variation of THD where ratio between fundamental ($1kHz$) and rest of frequencies is calculated.

• Record silence only to check for the level of noise.

• For measuring of the frequency response you can either play white/pink noise and compare the spectral envelope or use the sweep sine measurement technique to obatin impulse reponse and, from it, frequency reponse. You can also use the technique from good old times, when short sinusoids with increasing frequencies were played, but that's up to you. I am using sweeps all the time (what's more you can calculate the THD at each frequency).

• You might also want to play the stereo signal with two sinusoids at different frequencies and same amplitude(i.e. $1kHz$ & $2kHz$) to check for any problems with stereo.

Obviously there is plenty more different tests I did, but they are always application dependent.