gusmanb / PSVRFramework

GNU Affero General Public License v3.0
195 stars 37 forks source link

USB Audio - Linux/Alsa -> illegal device name #13

Open mungewell opened 7 years ago

mungewell commented 7 years ago

The PSVR presents a legitimate USB audio device, which has PCM for playback and capture. I think this is supposed to be the chat portal.

Unfortunately Sony put unicode in the device name 'PlayStation®VR' which freaks out Alsa... D'Oh! The mixer can be controlled with 'alsamixer -c 1', but playback fails with 'aplay -D "hw:CARD=PlayStation�VR,DEV=0" ...'.

ALSA lib pcm_hw.c:1700:(_snd_pcm_hw_open) Invalid value for card
aplay: main:722: audio open error: No such device

Fortunately you can re-map the device name as described here: http://www.alsa-project.org/main/index.php/Changing_card_IDs_with_udev 85-psvr-audio.rules.txt

And now we get playback... not that we can actually hear it though, need to find that flag.

$ aplay -D "dmix:CARD=PSVR,DEV=0" --dump-hw-params -V stereo -c 2 -f S16_LE -r 48000 test.raw 
Playing raw data 'test.raw' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
HW Params of device "dmix:CARD=PSVR,DEV=0":
--------------------
ACCESS:  MMAP_INTERLEAVED MMAP_NONINTERLEAVED RW_INTERLEAVED RW_NONINTERLEAVED
FORMAT:  S16_LE
SUBFORMAT:  STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 48000
PERIOD_TIME: (21333 21334)
PERIOD_SIZE: 1024
PERIOD_BYTES: 4096
PERIODS: [2 16]
BUFFER_TIME: (42666 341334)
BUFFER_SIZE: [2048 16384]
BUFFER_BYTES: [8192 65536]
TICK_TIME: ALL
--------------------
                 +################ 51%|57%###################+
mungewell commented 7 years ago

And if you want to record (but not actually hear anything, that damn flag must be somewhere):

$ arecord -D "hw:CARD=PSVR,DEV=0" -c 1 -f S16_LE -r 48000 -V mono  temp.raw
gusmanb commented 7 years ago

Thats really nice. Under Windows it gets installed automatically by the system and the sound works. Did you tested it in cinematic or vr? In cinematic 2d audio is enabled, in vr is the 3d audio system, so in windows at least if you enter vr mode audio stops playing.

If the toolbox runs under linux I can add some controls to automatize this.

El 4 nov. 2016 6:37, "mungewell" notifications@github.com escribió:

And if you want to record (but not actually hear anything, that damn flag must be somewhere): $ arecord -D "hw:CARD=PSVR,DEV=0" -c 1 -f S16_LE -r 48000 -V mono temp.raw

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gusmanb/PSVRFramework/issues/13#issuecomment-258349008, or mute the thread https://github.com/notifications/unsubscribe-auth/AD5cgcqqKwO6F8Vo0LzYLEse_yhAJ3tdks5q6sSxgaJpZM4KpNKE .

mungewell commented 7 years ago

USB sound has not been working for me Windows or Linux, but HDMI sound has. HDMI will stop when you enter VR Mode.

Got it.... print "Enable USB/Stereo Audio" ep.write('\x81\x00\xaa\x08\x84\x00\x00\x00\x00\x00\x00\x00') ep.write('\x23\x00\xaa\x04\x00\x00\x00\x00')

Tested up Windows, open 'playback devices' and double click 'PS VR Audio', advanced tab has 'Test'.

Man it's late... going to bed. PS. can't use the 'exe' installer on Linux.

gusmanb commented 7 years ago

Wow, nice.

It has worked for me on Windows since first day, the first what happened when I connected the usb (no HDMI connected) was losing the audio because the PS Audio device got activated and the earphones started to work, maybe because it had been connected to a ps4?

I will test the params today if I don't fall sleep, I have only slept 2 hours... this is going to kill me XD

gusmanb commented 7 years ago

@mungewell I remembered something extremely important. First time I connected the headset to the PS4 it downloaded a firmware upgrade for the PS VR, not for the PS4 itself. If you had not connected it to a PS4 you're with firmware 1.5 and the new version is 2.0, so for sure these are the differences we're seeing between our headsets.

You need to attach it to a PS4 and let it connect to internet and upgrade the device, else all tests you do can lead to different results, that may also be the root problem for the screen not getting locked. Do you have any friend with a PS4?

gusmanb commented 7 years ago

Ok, thanks to this I found something. To me the audio worked, that report does nothing and the screen lock is different in behavior to yours, so I decided to try with the PS4.

First I was testing the audio, when I select the PS VR Audio device as output it worked, but as I had the HDMI connected I feared it was some kind of loop between HDMI and the audio device, to verify it I decided to leave the USB connected to the PC and the HDMI to the PS4, if there were an audio loop through HDMI I should listen then the PS4 instead of the PC on the earphones. Well the result has been unexpected, the audio just stopped, I know the console is playing audio but it does not play on the earphones... and while I was doing the test I worn the headset and... the screen was locked whatever size it was...

I tried to change to any size/distance, it changed but the screen was locked at the center of my view...

Then I've reconnected to the PC HDMI, the audio started again but the screen was completely locked no matter which size/distance combination I set. Until I restarted the box the locking was set, and after restart it was released and began to act as usual, small locks large unlocks.

So what that means? Sony must be sending data also through the HDMI to the box. Before the PS VR launch Sony did a fw update, this firmware had the HDR enabled for HDMI, so it means it's an HDMI 2.0a at least after the firmware update. And the nice thing, since HDMI 1.4a it supports a layer of network streaming, so they must be using it to send data. Also, this makes sense with a problem I noticed and a problem an user had, if I leave the box on and the headset on and reboot my computer it doesn't boots, it keeps restarting, if I remove the HDMI then it boots. It also can be CEC 2.0, is another option. The biggest problem with this is we can't use any of these features as no desktop graphic card has support for it...

mungewell commented 7 years ago

Regarding FW update: I would have the opposite view. Whilst it's frustrating that my unit may be performing differently, it's actually representative of what other 'non-PS4 owning' users might have.

As your util (and other projects) get better, there will be more interest in buying PSVR solely for PC use. At some point Sony's production will catch up and the new (as bought) items will have the newer firmware.

I don't particularly like tasking people, but can you check your unit on Linux (bootable CD/USB is fine) to see if the sound card name is still 'PlayStation�VR'. Running, and typing 'aplay -L' will tell you this. If it does, I'm tempted to report this as a bug against the Linux kernel drivers.

Cheers, Simon

gusmanb commented 7 years ago

I will check it later, I forgot I have 3 raspberries with Raspbian and these will be enough for testing.

About the FW, I understand your point of view, but the problem is we would need a third unit to perform tests and then decide if the behavior is different because the fw or by another cause.

mungewell commented 7 years ago

Some more observations.... very late on Thurs and was tired. You may be correct that the command does not actually affect operation.

Linux can play and record to the device whilst in Cinematic mode, you can specify a card number rather than name (which causes errors). This audio is mixed together with the audio from the HDMI stream and output via the headset, but not to the 'Social Screen'.

$ aplay -D "hw:CARD=1,DEV=0" --dump-hw-params -V stereo -c 2 -f S16_LE -r 48000 test.raw
$ arecord -D "hw:1,0" -c 1 -f S16_LE -r 48000 -V mono temp.raw

The mixer (alsamixer -c1) shows adjustable sliders for pcm and mic, these not to affect the sound at all.

In VR Mode, the audio (both HDMI and USB) is muted to the headset. The social screen continues to play the HDMI audio. Mic recording from the headset (to USB) continues to function OK.

Normally in VR mode the PU will specially render sounds (as PS4 is not capable of this). It's probably unlikely that this will be supported on Linux as the format is propitiatory.

gusmanb commented 7 years ago

The volume settings act the same on Windows, I decided to test if there was a loopback because the volume sliders did nothing.

About the audio being mixed, on Windows I can't achieve it, I'm installing raspbian to test the CEC features so I will give it a try. If the audio comes to earphones but not to the social screen it looks to me something for chat, I mean, makes sense you ear with who are you talking but has not much sense to play it externally, it could cause to ear yourself twice. Maybe it can be worth to check the USB chat interface.

About the VR sound, I'm 100% sure it doesn't come from the PS VR Audio interface but the PS VR 3D Audio device, for that unless Sony gives us a driver we are totally lost as its not HID.

mungewell commented 7 years ago

Found another source of confusion. It seems my laptop does not like outputting HDMI audio (Linux with pulseaudio, Alienwear13 with Nividia960), when there is no HDMI audio it seems that USB audio does not work either.

IE. This doesn't work (no audio output at all, mic works in Cinematic):

PC ----> PSVR HDMI In
PC ----> PSVR USB
         PSVR HDMI Out ----> TV

However using another media source (Roku HDMI stick) it does work:

ROKU --> PSVR HDMI In
PC ----> PSVR USB
         PSVR HDMI Out ----> TV

By works I mean headset/headphone output a lowish level HDMI audio stream, mixed with a much louder USB audio stream.

I have no idea what audio format the Roku is outputing, if I unplug the TV (from PSVR) then the audio output from the headset stops => I assume that it is using the Audio Return Channel, not directly.

mungewell commented 7 years ago

Using a RaspberryPi I was able to confirm that the USB audio ONLY plays whilst HDMI audio is also playing. Maybe problem limited to my older f/w.

Using alsa to stream USB from laptop and RPi connected to HDMI, USB would cut in/out according to HDMI.

Work around was to stream '/dev/zero' from RPi, IIRC something like:

$ cat /dev/zero | aplay -c 2 -f S16_LE -r 48000
gusmanb commented 7 years ago

Confirmed, if no HDMI audio is output the USB audio device stops playing. It works the same on FW 2.0