Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linux(and windows) sound output as aplay does not work, swap for something else #239

Closed
jestarray opened this issue Aug 24, 2021 · 11 comments

Comments

@jestarray
Copy link

jestarray commented Aug 24, 2021

so this does not work on both Arch Linux with prebuilt racket binaries and Debian with built from source binaries(according to a user JSGRANT on the racket discord server https://discord.com/channels/571040468092321801/618895179343986688/879797867903057921):

#lang racket

(require 2htdp/image
         (only-in racket/gui/base play-sound))
         
; this fixes it if i set playcmd to mpv or sndfile-play
; (put-preferences '(GRacket:playcmd) '("mpv --no-audio-display ~a"))

; https://upload.wikimedia.org/wikipedia/commons/5/5d/Nl-honk.ogg
 (play-sound "./Nl-honk.ogg" #t)

because of this:

'("aplay" "play" "esdplay" "sndfile-play"

It uses aplay first to try and play the sound but according to this:
https://unix.stackexchange.com/questions/363176/ogg-audio-file-and-aplay-white-noise

You cannot decode ogg files with aplay. According to the man page, the only formats aplay understands are voc, wav, raw and au. My guess is that aplay interprets the ogg file as raw data, hence the white noise.

so I suggest swapping the order to sndfile-play or whichever command line audioplayer is available on most linux installations.
A second issue that crops up is when i try to re-run the file and play the sound again I get the following and it wont go away until i restart racket:

invalid memory reference.  Some debugging context lost

UPDATE: Playing sound also doesn't work on more recent versions of windows, see comments below

A side issue is that we should probably provide an easier way to import play-sound because I want to use it with 2htdp/image with students.

@sorawee
Copy link
Contributor

sorawee commented Aug 24, 2021

That doesn't sound right (pun not intended).

[cmd (or cmd

says that if cmd (which was obtained from GRacket:playcmd) is set already, then it will use the command. Are you sure it really fails because it tries to use aplay?

@jestarray
Copy link
Author

jestarray commented Aug 24, 2021

@sorawee yes, I am sure, for both .ogg and .wav files(it should support wav files but not the one i have apparently)

aplay_sound_error.mp4

@sorawee
Copy link
Contributor

sorawee commented Aug 24, 2021

That's not what I meant. I understand that aplay doesn't work. What I asked is, is it really the case that Racket tries to use aplay, despite the fact that you have already set GRacket:playcmd to invoke mpv instead?

@jestarray
Copy link
Author

jestarray commented Aug 24, 2021

OHH i forgot to remove that line ! thought I did.... yeah, if i set it to mpv or sndfile-play it works fine, nonetheless we should fix this not using aplay out of the box

@samdphillips
Copy link

FWIW my (mostly) default Ubuntu and Xubuntu desktop systems do not have sndfile-play

@samdphillips
Copy link

paplay may be a better cross Linux choice.

@jestarray
Copy link
Author

On a fresh reinstall of Windows 10 May Update 2021, even sounds on Windows do not work:
image

mciSendStringW: The specified device is not open or is not recognized by MCI.

@jestarray jestarray changed the title Fix linux sound output as aplay does not work, swap for something else Fix linux(and windows) sound output as aplay does not work, swap for something else Aug 24, 2021
mflatt added a commit to racket/racket that referenced this issue Aug 25, 2021
mflatt added a commit that referenced this issue Aug 25, 2021
Try `paplay` before other defaults, and fix problems with ports and closing.

Related to #239
@mflatt
Copy link
Member

mflatt commented Aug 25, 2021

I've pushed some repairs, including making paplay the first tried program on Unix-like systems.

As far as I can tell, ".ogg" files just aren't supported (without installing something extra?) on Windows, and that's the error that the MCI layer reports for a ".ogg" file.

@jestarray
Copy link
Author

As far as I can tell, ".ogg" files just aren't supported (without installing something extra?) on Windows, and that's the error that the MCI layer reports for a ".ogg" file.

So I tried playing a .wav file and I'm getting:

mciSendStringW: All wave devices that can play files in the current format are in use.  Wait until a wave device is free, and then try again.

Which is strange because I have nothing thats playing audio atm nor did I open any audio applications. I tried a fresh reboot and still no luck. It's probably unrelated to the .wav file but in case you want try it: https://opengameart.org/sites/default/files/vgmenuselect.wav

#lang racket

(require 2htdp/image
         (only-in racket/gui/base play-sound))

;https://opengameart.org/sites/default/files/vgmenuselect.wav
(play-sound "./vgmenuselect.wav" #t)

Can anyone else produce on Windows 10 on the May 2021 update(21h1) ?

@jestarray
Copy link
Author

jestarray commented Aug 25, 2021

After a few years, the MCI interface has been phased out in favor of the DirectX APIs first released in 1995.

According to: https://en.wikipedia.org/wiki/Media_Control_Interface

so it might come up again, let's just hope windows 11 doesn't phase it out completely. I think microsoft is generally ok at backwards compatibility though.

I might look into writing bindings to https://github.com/mackron/miniaudio , single file C header library that's crossplatform

EDIT: Someone said MCI really only works with 16bit wav files and not 32bit, among a few other formats.

@jestarray
Copy link
Author

alright closing, MCI works with mp3 but some wav files don't work. for those using gui/play-sound on windows may need to be updated to use direct sound or something in the future.. re-open if you'd like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants