-1

I'm currently trying to make my Android application based on frequencies work but I encounter some issues with speakers. In fact, I obtained three different results, depending of the method I use. Here are the methods, and the result for a 440 Hz sound (A for audiophiles) :

  • Method 1 : I use my voice directly in the application.

Result : Method 1 Result

Average Frequency : 443 Hz. Good result.

  • Method 2 : I record my voice through the default Android recording application, add this file in my application Firebase database and play it with my application.

Result : Method 2 Result

Average Frequency : 224 Hz. Frequencies are divided by 2 ?!

  • Method 3 : I play a 440 Hz sound found on Youtube with my laptop and record it directly with my application.

Result : Method 3 Result

Average Frequency : 886 Hz. Frequencies are multiplied by 2 now ?!

  • Method 4 : Same method as the second one but I don't use the default Android recording application. I use EasyVoiceRecorder where I can configure the sample rate (I put 44 kHz) and the encoding (I put .wav).

Result : Method 4 Result

Average Frequency : 431 Hz. Good result.

Additional informations :

  • To save the files in Firebase database as WAV files, I use AndroidAudioConverter library in order to not manipulate different audio formats and take advantage of WAV headers informations.
  • I use AudioTrack and AudioRecord classes and then Fast Fourier Transform to get the main frequencies every 128 ms. AudioRecord is configured with 44.1 kHz sample rate, AudioFormat.CHANNEL_IN_MONO and AudioFormat.ENCODING_PCM_16BIT. AudioTrack is configured according to WAV header file information.
  • When I play sounds located in raw application folder, frequencies result is perfect.

I don't really see the point in sharing the code of my application because as I showed you, it doesn't work only if I use third-party devices (default recording application, laptop, ...), so it must be a hardware issue. But if you need some code pieces, ask me and I will give them to you.

Thanks for reading, thanks in advance for your help and... happy coding ! :D

Kogani
  • 7
  • 3
  • The sound you record will almost never be a pure sine wave but a mixture of several sine waves with different frequencies. It seems your program has some difficulties to identify the strongest sine in the signal. – Henry Sep 08 '19 at 09:20
  • Hmm.. are you sure ? I'm documented on frequencies, so I know sound is combination of several sine waves. However, in order to get the main frequency of the signal, I use FFT (amplitude/frequency) and get the frequency with the highest amplitude. It works everytime for raw folder audio files and with my voice recorded directly in the application. Why wouldn't it work only when I use a phone playing the same sound as my voice ? I don't get how it could be a code issue here... – Kogani Sep 08 '19 at 11:20
  • You are mistaken to think this is a hardware issue; if it is not one of deciding which component is strongest, then almost certainly, what you are seeing is mono/stereo or sample width misinterpretations. But without *actual details* others can compare, this reduces to a prohibited "usage" question. Hint: try *playing back the sound from your own code* to see if you have mixed up its interpretation, your ears will tell you right away, especially if you record voice. – Chris Stratton Sep 08 '19 at 11:41
  • Sorry for the late answer, I was trying to debugging according what you said. I think I get it. For the method 2, it's certainly because of the conversion because wav header from m4a converted file indicates that the file is stereo, instead of easyvoicerecorder which tells that the file is mono and gives the correct frequencies. Furthermore, I don't hear any differencies between the two files in term of tone. For method 3, I think laptop emits a stereo sound but my AudioRecord is configured in mono, because when I configure it in stereo, I get the correct frequencies. – Kogani Sep 08 '19 at 12:40
  • However, how can I fix these problems ? How can I replace the AndroidAudioConverter system ? And for method 3, how can I know if sound is emitted by a computer or simply by voice ? – Kogani Sep 08 '19 at 12:41
  • We generally expect to see some code in questions like this - it's hard to provide an answer otherwise – marko Sep 08 '19 at 18:38

1 Answers1

0

If you use an FFT for spectral frequency magnitude peak picking, then any harmonics or intermodulation products that are stronger than the fundamental pitch frequency will confuse the result.

Youtube and many recording applications compress audio. One of the affects of lower quality compression is the distortion of frequency spectrum. Also, playing audio out of a laptop's small speakers, which have poor low frequency response, will also distort the frequency spectrum.

Solutions include not using compressed audio formats, using much larger speakers with a lower flatter frequency response, and using a better pitch detection/estimation algorithm instead of just picking an FFT magnitude peak.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153