openstf / stf

Control and manage Android devices from your browser.
https://openstf.io
Other
13.38k stars 2.79k forks source link

Audio output, very little work needed #921

Open jonsmirl opened 6 years ago

jonsmirl commented 6 years ago

All Android phones made since 2011 are capable of sending system audio out over the USB connection. You just need to turn it on using Android AOA mode. adb is already running in AOA mode. https://source.android.com/devices/accessories/aoa2

This little app will trigger audio output mode. https://github.com/gibsson/linux-adk After you do this an Alsa device will appear corresponding to the phone. You need the usbsnd module loaded in the kernel.

You can also use AOA mode to startup the stf app instead of leaving it running. When you run the linux-adk app you'll get a popup on the phone looking for a DemoKit app that it can't find. You can use that to start the stf app.

USB ID of phone..

jonsmirl@ares:~/aosp/linux-adk$` ./linux-adk -d 0e8d:201c
Looking for device 0e8d:201c
Device supports AOA 2.0!
Sending identification to the device
sending manufacturer: Google, Inc.
sending model: DemoKit
sending description: Demo ABS2013
sending version: 2.0
sending url: https://github.com/gibsson
sending serial number: 0000000012345678
asking for audio support
Turning the device in Accessory mode
Found accessory 18d1:2d05
Device should now be recognized as valid ALSA card...
  => arecord -l
Unable to open usb device [0xfffffffd]
^CSIGINT: Closing accessory
----> Ctrl-C to kill the program
Closing USB device
----> now the device is in USB audio output mode ----
jonsmirl@ares:~/aosp/linux-adk$ ls /proc/asound
A1PRO  card0  card1  cards  devices  hwdep  modules  oss  PCH  pcm  seq  timers  version
jonsmirl@ares:~/aosp/linux-adk$ ls /proc/asound -l
total 0
lrwxrwxrwx 1 root root 5 Jul  6 09:18 A1PRO -> card1
dr-xr-xr-x 8 root root 0 Jul  6 09:18 card0
dr-xr-xr-x 3 root root 0 Jul  6 09:18 card1
-r--r--r-- 1 root root 0 Jul  6 09:18 cards
-r--r--r-- 1 root root 0 Jul  6 09:18 devices
-r--r--r-- 1 root root 0 Jul  6 09:18 hwdep
-r--r--r-- 1 root root 0 Jul  6 09:18 modules
dr-xr-xr-x 2 root root 0 Jul  6 09:18 oss
lrwxrwxrwx 1 root root 5 Jul  6 09:18 PCH -> card0
-r--r--r-- 1 root root 0 Jul  6 09:18 pcm
dr-xr-xr-x 2 root root 0 Jul  6 09:18 seq
-r--r--r-- 1 root root 0 Jul  6 09:18 timers
-r--r--r-- 1 root root 0 Jul  6 09:18 version
jonsmirl@ares:~/aosp/linux-adk$ arecord -D hw:1,0 -c 2 -r 44100 -f S16_LE ~/foo.wav
Recording WAVE '/home/jonsmirl/foo.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
arecord: set_params:1363: Unable to install hw params:
ACCESS:  RW_INTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 44100
PERIOD_TIME: (125011 125012)
PERIOD_SIZE: 5513
PERIOD_BYTES: 22052
PERIODS: (3 4)
BUFFER_TIME: 500000
BUFFER_SIZE: 22050
BUFFER_BYTES: 88200
TICK_TIME: 0
denis99999 commented 4 years ago

Hi @jonsmirl ,

With a S9+, I got the same message arecord: set_params:1403: Unable to install hw params:... without any data registered into the file, can you help me please ? In the other hand, using another device, a old SONY mobile it works fine! Thanks.