Android AudioRecord Configuration does not match recorded Audio - android

I am intending to record stereo audio on an Android 4.4.2 device. However the audio being recorded via a simple recording App (using AudioRecord) does not match the configuration supplied. I would hope to see error messages in logcat if the device is using default configuration values, but I can see that the supplied values appear to be accepted by AudioHardware, and AudioPolicyManagerBase.
The current configuration for:
recorder = new AudioRecord(Media.Recorder.MIC,
sampleRate,
AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT,
audioBufferSizeInBytes);
Changing the Media.Recorder.AudioSource has been raised an option for trying to resolve this issue; But this has not changed how the Android stack behaves- Except to (understandably) fail to load the recorder when the configuration is invalid.
Changing SampleRate has shown also produced no visible change in the output- both 44.1kHz, and 16kHz are valid options, however both produce 16kHz audio when examined. The output audio also appears to be one channel of audio upmixed to stereo.
TinyALSA/Tinycap is available to capture the audio, and this appears to behave as expected.
Could this be an issue within the Android Stack? Or is this more likely to be an issue with the code supplied by the OEM?

The reason for the downmixed audio in this case was that the Speex Codec was being used in the HAL to downmix and de-noise the stereo input.
This was configured under:
<android source tree>/hardware/<OEM>/audio/audiohardware.h
The alternatives to this problem would be to route the audio out of ALSA, and around the android stack via a unix domain stream socket. This would be accessible in the application layer with androids localSockets.

Related

Processing RAW audio data from Android

I’m struggling since days trying to obtain a raw audio stream from the microphone. I am trying different ways: the low-level JNI way with Oboe Library (either AAudio and OpenSL ES implementations) and the Android’s AudioRecord Java classes.
The problem I am facing is that I am not able to retrieve amplitudes near -/+1.0 while being sure of saturating the microphone input with a calibrated pure tone with such a high amplitude.
I think that the problem is that I am not able to effectively disable the signal preprocessing from AndroidOS (Automatic Gain Control or Noise Cancelling).
AutomaticGainControl.create(id).setEnabled(false)
(not working!)
Also, it seems that it is not possible also to disable any additional microphone rather than the one "selected" (done that as selecting the setPreferredDevice on AudioRecord instance). Used as audio source: unprocessed, mic, voice_recognition.
Is there anyway doing this or am I missing something?
Thank you
Which audio source are you using for your recording? VOICE_RECOGNITION or UNPROCESSED are mandated to not have any pre-processing enabled by default (i.e. see https://source.android.com/compatibility/10/android-10-cdd#5_11_capture_for_unprocessed) and therefore would allow you to check your signal path.

Android audio record external jack

I would like to record the sound of the jack entry of my android phone. I've been searching about the Audio Capture class in Android, and i've found this:
https://developer.android.com/guide/topics/media/audio-capture.html
In the settings of this class, there are many options to choose the rec default mic, as this:
Set the audio source using MediaRecorder.setAudioSource(). You will probably want to use MediaRecorder.AudioSource.MIC.
What should I use to get the sound of the jack entry? Is there any example?
Thank you!
The API you provided is the correct one.
Calling mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC) (assuming the correct initialization of MediaRecorder as described here https://developer.android.com/guide/topics/media/camera.html -> Capturing Videos) will behave like this:
When you launch your app and start recording without any Jacks connected, phone's default microphones will be used. As soon as Jack microphone pin has detected a microphone connected, the system will use the Jack mic pin as an audio imput. Hovewer, you need to know that even though the audio record will have two channels, they will be identical, as Jack microphone can only record mono stream.

Blank MP4 Video From Android Screen Capture in Emulator

I have been trying to capture the screen from Android Emulator and record it to a .mp4 file. I adopted the standard approach of creating a virtual display and routing the frames to an encoder, multiplexing the video channel and writing to the an external storage. However, the ouput .mp4 file is just a blank screen when played back. The same code works when run on a device.
One observation is that the BufferInfo.size from onOutputBufferAvailable() always has a constant value of 13 or 2718 which clearly indicates trouble with the MediaCodec encoder. Should I change some parameters when configuring the encoder?
Another observation is from Logcat that tells me that a SoftAVCEncoder is used when running in an emulator, which kinda indicates that some software encoding is used but still not sure why this does not work.

AudioSource value for USB microphone on Android

An audio capture application on rooted MK809/Android 4.1.1. There is no internal mic so I am trying to use a USB one which is correctly detected as "USB Audio Device" in Settings/Sound/Sound Devices Manager/Sound Input Devices when connected.
What is this device's AudioSource value to pass into AudioRecord constructor (first argument). I tried every one in MediaRecorder.AudioSource, none worked. I am only interested in reading the capture buffer, not saving into a file.
Answering my own question. The following values did work: DEFAULT, MIC, CAMCORDER, probably others too as it is the only input device.
I was trying to use sample rate of 48000 (works on Windows) and AudioRecord creation failed with:
ERROR/AudioRecord(1615): Could not get audio input for record source 1
ERROR/AudioRecord-JNI(1615): Error creating AudioRecord instance: initialization check failed.
ERROR/AudioRecord-Java(1615): [ android.media.AudioRecord ] Error code -20 when initializing native AudioRecord object.
Somewhat misleading info considering that a call to getMinBufferSize() with the same set of agruments does not return an error as it is supposed to. I assumed that it was a valid sample rate for the device. Setting it to 44100 (guranteed) fixed the problem.
USB audio input devices do work on Android, Jelly Bean at least. Hope this helps someone.
FWIW, this is implementation specific (it can differ between different platform vendors and OEMs).
On the devices I've worked on, the USB accessory's mic would be chosen if the AudioSource is DEFAULT, MIC or VOICE_RECOGNITION, and the only sample rates supported in the audio HAL for USB audio recording were 8, 16 and 48 kHz (although the AudioFlinger is able to resample to other rates within a certain range).

Android - Manually write()ing to AudioTrack, no appropriate MediaRecorder.AudioSource

I see that MediaRecorder allows you to record from the Microphone, or a phone call.
I'm using write() on an AudioTrack to produce sounds out of basic frequencies. Multiple AudioTracks actually.
I would have thought that there would be a MediaRecorder.AudioSource setting that captured whatever sounds the system was sending to the speakers.
I tried DEFAULT but it didn't work.
Unfortunately there is no loop back audio source for recording sounds generated by the device, just from external audio sources.

Categories

Resources