androidaudiobluetooth

Create tones from Integer Values


I have an app that analyses some sensor data and then outputs integer values ranging from -1 to 5, that correlate to the strength of the sensor signals. The sensor data has no upper or lower bound.

I want the user to be able to recognize the signal strength by hearing a tone. How can I use these integer values to produce tones depending on the value?


Solution

  • A simple and effective way to achieve this in an Android app is to create a map that has the Integer values as keys and the sound files as values. Each time you receive data from the sensor you query the map and find out which sound to play. You can look at this example of how to play the files using a SoundPool. SoundPool allows you to pre-load all the required sounds and hence there won't be any delay in the playback. As for the Bluetooth device, a similar approach can be utilized, but the playback method would be different