When developing, how can I control a USB DAC without preventing other apps from playing sound on it? - General Questions and Answers

Basically, I have a USB DAC with PCM2912A from Ti. It has a function called sidetone, and that is useful to my usecase.
It can be simply enabled on Windows, but Android seems to have no way to enable that hardware sidetone.
So I am trying to develop an App to achieve that: Enable the sidetone function of PCM2912A.
I just open that device, then sending control requests via UsbDeviceConnection.controlTransfer(...).
Like this: (Just for better understanding of what am I doing)
Java:
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
PendingIntent permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(usbReceiver, filter);
usbManager.requestPermission(theDevice,permissionIntent);
UsbInterface usbInterface = theDevice.getInterface(0);
UsbDeviceConnection connection = usbManager.openDevice(theDevice);
connection.claimInterface(usbInterface, true);
byte[] buffer = intTo2Bytes(volume);
connection.controlTransfer(0x21,0x01,0x0100,0x0200,new byte[]{0x00},1,100);
connection.controlTransfer(0x21,0x01,0x0200,0x0200,buffer,2,100);
It works. I can hear my voice from the headset with almost no delay.
But this prevents other applications from playing any sound on my headset. How can I achieve the same result and still let the sound play properly?
Any protential help appreciated.

Related

Orbit 2 and Gear4 stereo bluetooth headset

Hi,
When I switch on both devices they connect fine, and I'm able to make calls etc, but the stereo connection doesn't appear to be established. I then have to go to Comm manager>Settings>Bluetooth, tap and hold my bluetooth headphone in the list, then choose 'Set as Wireless Stereo' from the list that appears.
As soon as I do this, the stereo connection is achieved and indicated by the headphone icon appearing in the top bar.
Is anybody else having this issue with stereo bluetooth headphones?
Is there a solution to this?
Aleemz,
I've just bumped in to this post - I have solved this on mine by writing a mortscript to automate the manual steps above.
It works pretty well, switching on the BT, waiting for the headset to connect, and then switching off the BT when the headset disconnects.
Here's the script (with thanks to another poster who gave me the starting block for this):
#power up bluetooth
Run ("\program files\vijay555\vjvolubilis\vjvolubilis.exe","-blueon")
#wait for something to connect, but only for 30 secs
SleepMessage( 30,"Connect Headset", "waiting for headset" , True ,RegRead("HKLM", "System\State\Hardware", "Handsfree") = 1 )
If (RegRead("HKLM", "System\State\Hardware", "Handsfree") = 0 )
#headset isn't connected, so switch off bt & give up
Run ("\program files\vijay555\vjvolubilis\vjvolubilis.exe","-blueoff")
exit
endif
#if we get here, then bt is on & the headset (or something) is connected
#may want to add logic here to decide what to do based on what device has connected
#run up the settings page
Run "\Program Files\MortScript\bluetoothcpl.lnk"
#wait for the settings page to load
WaitForActive ( "Settings",20 )
If (WndActive("Settings"))
#Great - it opened
#set the device
#may well have to add some logic here later to detect which BT device has connected
#This works if the BLuPhones are the 1st in the list
MouseDown Settings,60,125
Sleep 1000
MouseUp Settings,60,125
Sleep 500
SendDown
SendDown
SendDown
SendCR
Close "Settings"
#now we're all set up
#Now just wait for it to disconnect
#loop watching for bt headset disconnect for 4 hours, checking every minute
timcount = 0
while (timcount < 60*4)
timcount = timcount + 1
If (RegRead("HKLM", "System\State\Hardware", "Handsfree") = 0 )
#headset has dis-connected, so switch off bt & exit the apps
Call CloseAppsAndExit
Exit
endif
sleep 60000
EndWhile
#timeout after 4 hours of waiting, and shutdown media player & bt anyway
#do this in case it's been left on accidentally
Endif
Message("Closing down bluetooth now","Bye")
Call CloseAppsAndExit
Sleep 2000
Exit
Sub CloseAppsAndExit
#Close all apps we ran & exit
#close BT
Run ("\program files\vijay555\vjvolubilis\vjvolubilis.exe","-blueoff")
#close all apps -
Call ("CloseApp","GSPlayer")
Call ("CloseApp","Windows Media")
#this is the name of AVRCP I think
Call ("CloseApp","TCPMP")
Call ("CloseApp","S2P")
#and this is my guess at S2P
EndSub
Sub CloseApp
if (WndExists(argv[1]))
close(argv[1])
Endif
EndSub

[Q] [QUESITON] How to route audio (Not BT or A2DP) from 14 and higher API?

I will quickly summarize.
Samsung Galaxy S3, when I run some app with the headphones plugged and for some reason, if the app freezes or any other issue. The phone thinks that it have the headphones plugged yet. Although it's been unplugged.
I am developing an app to fix this samsung firmware problem.
AudioManager returns me "true" with the function isWiredHeadsetOn, with or without the plugged headphones. My question is that since old api of android, setRouting or setWiredHeadset are deprecated, and I don't know can I change the value of isWiredHeadsetOn to returns me false.
I don't know if I explains me well.
Code:
AudioManager manager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
manager.setMode(AudioManager.MODE_NORMAL);
This setMode don't change the wiredheadset value.
Thanks for your advices.

USB audio

When I heard about USB audio in Android 5.x.x, I was really excited, I could finally use my G930 headset with my phone! ...then I tried it and I found out that the volume is ridiculously low. So I thought it was the headset and naturally I decided to try a different one, but as it turns out, the other one was just as quiet. Am I missing something here?
Even trying other players doesn't seem to work, with the exception being USB Audio Player, which I was able to play with the pre-amp and boost the volume to the proper levels, but the equalizer on it is horrible.
Any thoughts on this? Is USB audio even a thing in Android or it's just "there"?
CrisR82 said:
When I heard about USB audio in Android 5.x.x, I was really excited, I could finally use my G930 headset with my phone! ...then I tried it and I found out that the volume is ridiculously low. So I thought it was the headset and naturally I decided to try a different one, but as it turns out, the other one was just as quiet. Am I missing something here?
Even trying other players doesn't seem to work, with the exception being USB Audio Player, which I was able to play with the pre-amp and boost the volume to the proper levels, but the equalizer on it is horrible.
Any thoughts on this? Is USB audio even a thing in Android or it's just "there"?
Click to expand...
Click to collapse
The issue could be a million things since it's new. and since headsets aren't guaranteed support outside of a PC trial and error is your best friend.
Try different ROMs, stock ROM's, stock based, etc. you get the point.
CrisR82 said:
When I heard about USB audio in Android 5.x.x, I was really excited, I could finally use my G930 headset with my phone! ...then I tried it and I found out that the volume is ridiculously low. So I thought it was the headset and naturally I decided to try a different one, but as it turns out, the other one was just as quiet. Am I missing something here?
Even trying other players doesn't seem to work, with the exception being USB Audio Player, which I was able to play with the pre-amp and boost the volume to the proper levels, but the equalizer on it is horrible.
Any thoughts on this? Is USB audio even a thing in Android or it's just "there"?
Click to expand...
Click to collapse
Sounds like the USB mixer is set to a low volume by default.
Are you rooted? If so, you can download a binary called "tinymix" from here to view and modify the mixer.
(tinymix is part of AOSP, but does not ship with Google's Android. It may with custom ROMs.)
Copy the binary to, e.g. /system/xbin, make it executable (744), and run the following command as root in an adb shell, after you connected your USB audio device:
Code:
tinymix -D 1
For example, I have an external DAC (FiiO E18, which works fine on my N5 running stock Android 5.1) and the output is
Code:
Mixer name: 'FiiO USB DAC-E18'
Number of controls: 2
ctl type num name value
0 BOOL 1 PCM Playback Switch On
1 INT 2 PCM Playback Volume 110 110
Knowing this output you can run
Code:
tinymix -D 1 "PCM Playback Volume"
which in my case returns
Code:
PCM Playback Volume: 110 110 (range 0->110)
This means that the playback volume on my device, which can range from 0 to 110, is set to max.
What does tinymix return on your device?
chdloc said:
Sounds like the USB mixer is set to a low volume by default.
Are you rooted? If so, you can download a binary called "tinymix" from here to view and modify the mixer.
(tinymix is part of AOSP, but does not ship with Google's Android. It may with custom ROMs.)
Copy the binary to, e.g. /system/xbin, make it executable (744), and run the following command as root in an adb shell, after you connected your USB audio device:
Code:
tinymix -D 1
For example, I have an external DAC (FiiO E18, which works fine on my N5 running stock Android 5.1) and the output is
Code:
Mixer name: 'FiiO USB DAC-E18'
Number of controls: 2
ctl type num name value
0 BOOL 1 PCM Playback Switch On
1 INT 2 PCM Playback Volume 110 110
Knowing this output you can run
Code:
tinymix -D 1 "PCM Playback Volume"
which in my case returns
Code:
PCM Playback Volume: 110 110 (range 0->110)
This means that the playback volume on my device, which can range from 0 to 110, is set to max.
What does tinymix return on your device?
Click to expand...
Click to collapse
Does that affect USB volume only, or it will affect global audio output?
CrisR82 said:
Does that affect USB volume only, or it will affect global audio output?
Click to expand...
Click to collapse
USB volume only.
Note that modifying the USB audio playback gain via the mixer may not be permanent. You may have to re-adjust the playback gain every time after you have plugged in your USB audio device. If this is the case, an automation app like Tasker can be very useful.
The USB Audio Player seems to have this built-in and works pretty well...wish it's equalizer wasn't lacking even basic presets...
Will give it a go I guess

Listen to System Bluetooth Socket

Hi,
I want to use Wii Blaance Board with my Android Device. I already paired it, but i can not find a mehtod to listen to the system Bluetooth Socket
to receive the incoming Bluetooth Packages. Is there any way to sniff it?
The Device is registred as an Input Device, but also the MotionEvent is useless for me, because there is no Object Containing the Raw Data.
Any Help?
Best Regards,
Dirk
I'm not sure I understand the problem. If you need to listen an incoming bluetooth connection, you can use:
listenUsingInsecureRfcommWithServiceRecord(name, uuid), or listenUsingRfcommWithServiceRecord(name,uuid)
eg.
Code:
BluetoothAdapter mBtAdapter = BluetoothAdapter.getDefaultAdapter();
btsSocket = mBtAdapter.listenUsingRfcommWithServiceRecord("Name", MY_UUID);
Mh , i don't know if it works, my problem:
I have the wii balance board, it connects to the system automatically as a bluetooth input device. After it's connected i want to capture the bluetooth packages it sends.

Listen to the Mic

No, not spying on the user. I want to create a service that listens to the mic, all the time, waiting for a tone (specifically a DTMF tone). On hearing a specific tone (DTMF typically has 16) it triggers a broadcast intent. That intent might be configured to be specific to some other app, or mimic a keyboard button press.
It's just a way to get a simple external gadget to send messages to any app that cares to listen. And, no, BT, BLE, USB are not an option. Direct input to the mic line is possible.
Really simple in theory but I suspect fraught with permissions and always on problems.
I'm not smart enough to write real code for Android but I can appreciate an overview of what's needed.
Any help gratefully received.

Categories

Resources