Mauro Bilotti
Mauro Bilotti

Reputation: 6232

How to play PCM-24 audio?

I'm working on my engineering thesis which consists on a electronic esthetoscope. The audio is taken with an I2S microphone (Adafruit SPH0645) whose output consist of 18 bits of valid data on each sample. Because of this, I decided to use a PCM-24 format and I was able to play and view graphics (phonocardiogram) by using a .NET library NAudio.

The scope of the project has to consider mainly mobile devices with Android, and these has to be connected through TCP socket created by the hardware (server) over which streams continously the audio in PCM-24 format. The following image will clarify the functioning exposed:

auriculares: headphones|conexión inalámbrica: wireless connection

I've been researching that Android provides AudioTrack as a native library for playing PCM files, but seems to be that only has support for PCM-8, PCM-16 and PCM-float which as I understand requires higher API level.

I was unable to find any other library that would help me with this task, but seems strange since PCM-24 is another standard commonly used. Is there any way to play PCM-24 audio in Android?

On other hand, if there's no way to do it, what are the issues that I should consider on decreasing to PCM-16 or increasing to PCM-32-FP in despite of processing and padding values necessary?

Upvotes: 1

Views: 993

Answers (1)

Eddie Lopez
Eddie Lopez

Reputation: 1139

I think you're pretty much on the right track. As you can see here https://source.android.com/devices/audio/data_formats Android supports a wide range of formats internally, yet only a subset is exposed, probably for compatibility; see here: https://developer.android.com/guide/topics/media/media-formats.

I would convert to 16bit PCM as you are proposing. Heartbeat or pulse is a slow process, compared with the frequency response and resolution of your sensor, so you'll be safe and without losing any information for the purposes of playing the sound or showing the echocardiogram.

Be careful with translating to 16bits, make sure your PCM24 is not using any weird positioning for the words, as it is sometimes the case. Beyond that, right shifting your samples will be enough.

For any further processing on data such as detecting arrhythmia or anything alike, use your original 24bit based samples. Good luck!

Upvotes: 1

Related Questions