forcing mic input in Android - android

I have a weird setup where I am trying to record audio from an external device using a TRRS male-male audio cable. The way it is supposed to work, I plug in the audio cable to the device, then to the phone then use AudioRecorder to record in audio. On my HTC One M8 everything works great and I can record audio from the device. On my Samsung Galaxy S2 it records audio but from the internal mic.
I confirmed the issue is with the impedance of the mic input. If I add a resistor to the audio cable to increase the mic impedance then the S2 will record from the device correctly.
So my question is: Is there anyway to force Android to use the external mic jack? I looked into sending the ACTION_HEADSET_PLUG intent with the microphone set to -1 for external, but fail due to permission errors. It seems this intent was moved into protected permissions (https://github.com/android/platform_frameworks_base/commit/8f014059d3084fcce9e82b4b1f8b8323744ac52d)
So is there any other way to force the phone to use the mic jack without external hardware?!
Thanks!
Also, for the actual audio recording, settings are:
44100kHz sample rate
16 bit samples
Mono channel
Buffer is set to AudioRecord.MinBufferSize()

Related

Multichannel Audio recording in Android

I have a multichannel microphone connected to an android phone (pixel 3) through usb. I'm trying to use MediaRecorder API for recording audio. However, there doesn't seem to be a way to setup multichannel recording with MediaRecorder even though Android USB audio documentation seems to say it allows multichannel input. I know recording multi channel audio is possible, as there are apps that already do that (see ntrack). I'm trying to figure out how to do this and hoping it doesn't involve writing usb driver (like these developers).
If you can see your microphones as separate input devices using audioService.getDevices(AudioManager.GET_DEVICES_INPUTS) then you can use the AAudio API (preferably using Oboe library) to access each of these microphones by opening stream for each.

Android 5 - Change default audio input route to use external USB card on Streaming

I'm trying to use a Samsung Galaxy S6 Edge Android 5.1.1 (rooted) as an basic audio/video live stream equipment but I can't route audio from an external USB card Behringer UCA202 Class Compliant 1.0 to default phone camera application.
Default camera app has the option to create a live event on Youtube and works great, but unfortunately only can get audio from internal speaker as I expected. The sound card is working and I can get sound using others audio record apps.
Any option to change default Audio Input from internal mic to USB Audio IN? Maybe AlsaMixer is the way to go? I look for some kind of virtual mixers on PlayStore but unsuccessfully.
The only post I see asking something similar is this one:
Change Android Audio Record Default Input Source
but it's from three years ago :(

Play music via android speakers

I want to make an app that makes it possible to connect an iPod or mp3 player to my Android device and let the Android speakers function as external speakers.
The ideal situation would be to actually read from speaker output so I can connect a stereo mini jack cable.
Is it possible to read from the headset output with the Android SDK?
A second option would be to use a mono mini jack instead. I could maybe directly read from microphone and output as a music player. Although, having to use a mono mini jack would be a huge disadvantage, because most people don't own such a cable.
UPDATE
For my second option I found this link that would let me take a special adapter onto a stereo cable so the iPod output can go into the mic input. It's a TRRS adapter. This works, but still isn't the ideal solution to me. http://www.techlife.net/2012/12/add-an-audio-input-to-android.html
ANOTHER UPDATE
I did a test with only a mono cable, but it seems that the mic is not recognized, so I really need the TRRS adapter to make sure that the mic is on. I found some apps that can help me with measuring input volume. I think I can achieve my goal for myself with the adapter, but reading from headset output would be nicer and could actually result in building an app.
You need to understand some basic things...
Audio output lets you "take audio out of your device".
It's not audio input that would let you "insert audio signal into your device".
So the concept that you've presented cannot work, because this socket is not able to receive audio signal through normal stereo jack cable (and connector).
You could try to make it work with a device that supports the headphones/mic set (it's a different kind of 3.5 mm jack connector). It's so called TRRS (four-conductor). But to use it in your project you probably would need some cable/socket soldering and maybe even some sort of microporcessor to help processing the signals.

Android: Forcing external microphone (jack input 3.5mm) to stay on

How do I force the Android system to select the 3.5mm Jack as my microphone source? I am using the AudioRecord class to do the recording.
I am using an external Microphone. When it is detected all works well, but sometimes the external microphone is not detected automatically. A TRRS splitter (cheap $3 thing) is used to split the 3.5mm Jack into separate Mic and Headphone jacks (I need simultaneous recording and playback).
The AudioManager.setWiredHeadsetOn() is deprecated and instructions say not to use it.
1) Do I maybe need additional external hardware to provide the correct microphone impedance?
2) Can I force the input in code?
3) Can a custom ROM archive audio control at this level - maybe this is the best option?
Thanks
It is very likely a hardware issue. Samsung phones seem to require a microphone with impedance of around 1.0k - 1.5k Ohm. Try modifying the input mic line by adding a series resistor to raise the impedance. Check out this link for details on how to do this: xdadevelopers - External mic on Galaxy devices

(Android) Get audio signal from the audio line-in instead of phone microphone

I'm working on an Android program whose purpose is to record a sound signal and then to analyse it.
To record this sound signal, I am using a special microphone I want to plug to my Android device directly via the audio line-in, so I won't use the mobile phone microphone.
Here is what I found on Android website :
" Defines the audio source. These constants are used with setAudioSource(int).
Summary
Constants
int CAMCORDER Microphone audio source with same orientation as camera if available, the main device microphone otherwise
int DEFAULT Default audio source
int MIC Microphone audio source
int VOICE_CALL Voice call uplink + downlink audio source
int VOICE_COMMUNICATION Microphone audio source tuned for voice communications such as VoIP.
int VOICE_DOWNLINK Voice call downlink (Rx) audio source
int VOICE_RECOGNITION Microphone audio source tuned for voice recognition if available, behaves like DEFAULT otherwise.
int VOICE_UPLINK Voice call uplink (Tx) audio source "
It seems that there is no way to define the line in as an audio source. I have tried to plug my own microphone to my mobile and then to record the sound, hoping that it will recognize my own microphone (as a handfree kit) but it keeps recording on the mobile phone microphone.
Does anyone know what to set as an audio source so I can use the line-in ?
Many thanks in advance !
You made some assumptions which might not be correct. Regular android phones have no Line Ins.They are not designed to be professional audio systems.
When you plug your headset, android automatically recognises your external MIC and you dont need to set it in your code.Just leave it in DEFAULT.
The problem is, you will need an special and compatible connector for your MIC. As you might notice the headset connector for your mobile is different from an streo Jack.So you will need an adapter or solder your own compatible Jack.If you connect your MIC with two parts, android will assume that its a headphone and not a MIC!
Here is the link to article: How do I use an external microphone with my Galaxy Nexus?

Categories

Resources