Cross-platform sound playing
- tperry2x
- Posts: 2763
- Joined: Tue Dec 21, 2021 9:10 pm
- Location: Somewhere in deepest darkest Norfolk, England
- Contact:
Cross-platform sound playing
Because the play sound command doesn't work in Linux, here's an example of how a cross-platform version can work.
- richmond62
- Posts: 4185
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Cross-platform sound playing
That works on MacOS.
As you can see from my screenshot, it looks a bit different to yours (presumably on some type of Linux), so NOT cross-platform in terms of appearance.
The thing that surprised me was this:
- -
None of the headache with relative paths that has always been the incentive to embed sound files in a stack.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4185
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Cross-platform sound playing
I assume xPlaySound(1,2) is your invention.
Is that a custom something in your stack, or will that be integrated into 1.10?
Is that a custom something in your stack, or will that be integrated into 1.10?
https://richmondmathewson.owlstown.net/
- tperry2x
- Posts: 2763
- Joined: Tue Dec 21, 2021 9:10 pm
- Location: Somewhere in deepest darkest Norfolk, England
- Contact:
Re: Cross-platform sound playing
Yes, ignore the difference in UI. That would be the case in Windows too, where it looks different again. Not to worry about that though (within this topic ) - it's just to give you a method to vary the sound volume.richmond62 wrote: ↑Sun Nov 24, 2024 2:08 pm As you can see from my screenshot, it looks a bit different to yours (presumably on some type of Linux), so NOT cross-platform in terms of appearance.
A bit of both. The xPlaySound function is in the stack script.richmond62 wrote: ↑Sun Nov 24, 2024 2:12 pm I assume xPlaySound(1,2) is your invention.
Is that a custom something in your stack, or will that be integrated into 1.10?
It could be implemented in a standard shared Library for OXT, as myself and Paul have talked about. Just so we have a reliable way of doing things on all platforms.
You'll find the path stuff happens in that function, and it looks for a subfolder called "audio".
But this takes some of the guess work out of playing sounds.
* you do need mplayer installed on linux for this to work though.
Any of that, if it becomes a welcome addition, I can easily add to the custom dictionary.
- richmond62
- Posts: 4185
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Cross-platform sound playing
DEos that mean that as long as the subfolder called 'audio' is in the same relationship to the stack/standalone it should work?
I assume so, as I decompressed your thing inside a folder on my desktop called 'Hax 23 November'.
I assume so, as I decompressed your thing inside a folder on my desktop called 'Hax 23 November'.
https://richmondmathewson.owlstown.net/
- tperry2x
- Posts: 2763
- Joined: Tue Dec 21, 2021 9:10 pm
- Location: Somewhere in deepest darkest Norfolk, England
- Contact:
Re: Cross-platform sound playing
Yes, absolutely. Anywhere the stack is, as long as that audio folder is in the same location, it'll look in there.
Okay Not that these are 'Hacks' though.richmond62 wrote: ↑Sun Nov 24, 2024 2:23 pm ...I decompressed your thing inside a folder on my desktop called 'Hax 23 November'.
- OpenXTalkPaul
- Posts: 2379
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Cross-platform sound playing
The Play [soundFile] command built-into the engine only 'sort-of' works on macOS, it will play basic .wav, .aif, and probably .au (common on old Unix) sound files, but once it starts playing there's no way to stop it, 'play Stop' doesn't work, and if you pass it an mp3 it will try to play it but you get horrible noises instead. I've used command line 'afplay' that comes with macOS to play sounds in the background before, but with Extension Builder I've tapped into NSSound & AVAudio frameworks directly, that includes sound recording, which is a feature I'd personally like to have available on all platforms.
BTW, OXT 'Heavy' includes libsndfile as part of the dependencies for FluidSynth, that cross-platform library can do various sound format conversions.
I'm eventually going to try to get deeper into Linux sound stuff ALSA, PuseAudio, etc. Linux has come a long way on the sound & music front in the past 10-15 years or so.
Of course if going the xTalk over HTML5/JS piggyback route we get all the media support that's built into web browsers these days for free.
I was thinking of adding some 'unifying' handlers for play/record to the OXT General Music (and Sound) Library.
In OXT engine the 'play' command is a reserved keyword so can't use that (without modifying / recompiling the engines), so I was looking to maybe reuse commands from some other xTalk, maybe Oracle Media Object's (which began as 'Plus' on DOS/Win) 'MediaTalk' dialect ( https://hypercard.org/mediatalkreferenc ... rence.html ). That had` some extra sound playing capabilities like fadein/fadeout https://hypercard.org/mediatalkreferenc ... e-265.html
https://hypercard.org/mediatalkreferenc ... e-263.html
https://hypercard.org/mediatalkreferenc ... e-261.html
https://hypercard.org/mediatalkreferenc ... e-272.html
https://hypercard.org/mediatalkreferenc ... e-276.html
https://hypercard.org/mediatalkreferenc ... e-125.html
https://hypercard.org/mediatalkreferenc ... e-359.html
Not sure what SuperCard used, I can't find it's syntax dictionary anywhere online Maybe I can reinstall SC (I have a license for 4.5.something and an old Mac to run it on)
Probably use 'playSound' and 'recordSound'?
'Answer Record' only ever worked on macOS & Windows with now-defunct Quicktime installed, so I'd like to change that, I think we might be able to reuse 'Answer Record'.
- OpenXTalkPaul
- Posts: 2379
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Cross-platform sound playing
I'm going to post this related link so that I can reference it later:
https://www.systutorials.com/docs/linux ... li-syntax/
ICYDK: PulseAudio is the sound server system most commonly used by default on many popular Linuxes (Ubuntu, Debian, Fedora, etc.) so that's the one to tap directly. Although it seems like the alternative PipeWire (which I'd assumed based its name on 'ReWire' https://en.wikipedia.org/wiki/ReWire_(s ... _protocol) ) have gained some traction, so maybe that could also be supported, as well as JACK connection kit (which has been around for decades now).
Here's an article about PipeWire:
https://hackaday.com/2024/11/26/linux-f ... ork-pipes/
EsounD. was that an Linux Engine dependency in the past?
Maybe why playing stack embedded sounds may not work on Linux?
https://en.wikipedia.org/wiki/Enlightened_Sound_Daemon
https://www.systutorials.com/docs/linux ... li-syntax/
ICYDK: PulseAudio is the sound server system most commonly used by default on many popular Linuxes (Ubuntu, Debian, Fedora, etc.) so that's the one to tap directly. Although it seems like the alternative PipeWire (which I'd assumed based its name on 'ReWire' https://en.wikipedia.org/wiki/ReWire_(s ... _protocol) ) have gained some traction, so maybe that could also be supported, as well as JACK connection kit (which has been around for decades now).
Here's an article about PipeWire:
https://hackaday.com/2024/11/26/linux-f ... ork-pipes/
EsounD. was that an Linux Engine dependency in the past?
Maybe why playing stack embedded sounds may not work on Linux?
https://en.wikipedia.org/wiki/Enlightened_Sound_Daemon
- OpenXTalkPaul
- Posts: 2379
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Cross-platform sound playing
Rigfht, soLinux
The minimal requirements for LiveCode to run on Linux are:
32-bit installation, or a 64-bit linux distribution that has a 32-bit compatibility layer
2.4.x or later kernel
glibc 2.3.2 or later X11R5 capable Xserver running locally on a 24-bit display
compositing window manager (optional – required for alpha-blended window shapes)
gtk/gdk/glib (optional – required for native theme support)
pango/xft (optional – required for pdf printing, anti-aliased text and unicode font support)
lcms (optional – required for color profile support in JPEGs and PNGs)
gksu (optional – required for elevate process support)
mplayer (optional – required for video playback)
esd (optional – required for audio playback)
Although impossible to test every existing Linux distribution, we are aiming to ensure that LiveCode runs on as wide a variety of systems as possible. To achieve this, the engine has been implemented to have minimal direct dependencies on system software, and will gracefully degrade in feature set if it cannot find the libraries it needs. Generally any recent linux distribution including Gnome/GTK support will have the required libraries for full feature support ñ for example, Ubuntu 7 supports all these features (although alpha blended window shape support requires you to be running with ‘Advance Desktop Effects’ turned on).
ESD = Enlightenment Sound Daemon = EsounD
Which iwas already installed on my system.
Previous docs called for xanim to be installed, which is a really old X11 video player, but
I was able to find a 64bit build of it as an OpenSUSE .rpm which is ABI compatible with Debian so i installed it.
Code: Select all
$ xanim '/home/Paul/Desktop/Ocean.mp3'
XAnim Rev 2.80.0 by Mark Podlipec Copyright (C) 1991-1999. All Rights Reserved
Unknown or unsupported animation type: /home/Paul/Desktop/Ocean.mp3
Usage:
XAnim [options] anim [ [options] anim ... ]
-h lists some common options, but may be out of date.
See xanim.readme or the man page for detailed help.
Paul@6430sMX:~
$ xanim '/home/Paul/Desktop/Stream.wav'
XAnim Rev 2.80.0 by Mark Podlipec Copyright (C) 1991-1999. All Rights Reserved
Can't Open /dev/dsp device
From terminal it will play a .wav file.
With both installed, and including first setting videoClipPlayer engine property, the play [file], play sc [file], play vc [file] will play an mp3 or wav , AND strangely 'prepare [movieFile] PLAYs either sounds instead of caching the file into ram like it's supposed to do.
As soon as sound completes playing the IDE exits. I think the Exit signal from the player is getting passed along to the parent process that launched it (the IDE Engine).
The built-in sound playing is very broken on Linux. I needed to see for myself just how broken.it is.
Anyway I'm all in on creating an xTalk library that can use a variety of commonly available APIs and/or command line tools to handle multimedia things for our xTalk(s). You can't really have a 'HyperMedia' thing without multimedia capabilities can you.
So here's a list of some goals to start out:
0) enumerate sound hardware (ins/outs), get system default device,
1) playSound [File] <,blockingOrNonBlocking>
2) recordSound [toFile] for x millisecs
3) playVideo [File] fullscreen or in rectangle
4) system Default Sound Out Volume get/set
5) get set recording Input Level
6) scrub forward/backward position in playing file
Currently playing files list would need to be temporarily stored in some sort of globally available list, in either a global variable or something else like a custom property created by the library stack, that gets populated as files are played or queued.
- OpenXTalkPaul
- Posts: 2379
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Cross-platform sound playing
Nice! This works well if mPlayer is installed
I would add a check to make sure mPlayer is installed before trying to use it.
or
Code: Select all
function xplaySound tSound, tLoud
-- calculate path to sound file
set the itemdelimiter to slash
put the long name of this stack into tPath
if word 1 of tPath is "stack" then delete word 1 of tPath
replace QUOTE with "" in tPath
delete last item of tPath
put QUOTE & tPath & slash & "audio" & slash & tSound & QUOTE into tAudioFile
-- conditional play command
if the platform contains "lin" then
put "mplayer -really-quiet -volume " & tLoud & " " & tAudioFile into tCmd
put tCmd & " > /dev/null 2>/dev/null &" into tNoWaitShellCommand
get shell(tNoWaitShellCommand)
else
set the playLoudness to tLoud -- does not work for linux, but "should" work for windows and macOs
do "play " & tAudioFile
end if
end xplaySound
Code: Select all
if shell("which mplayer") is not empty
Code: Select all
if shell("command -v mplayer") is not empty
- tperry2x
- Posts: 2763
- Joined: Tue Dec 21, 2021 9:10 pm
- Location: Somewhere in deepest darkest Norfolk, England
- Contact:
Re: Cross-platform sound playing
Yes, that's a good point - although, that's especially true for any of the linux-type libraries we are adding.
You could use the same method I use to check dependencies in this stack if you like (which is essentially the method I use for Linux in the 'compatibility' card of the Preferences)
Short version: I'm using:
So, dpkg -s "flex" where "flex" is the name of what I'm checking for of course.
You could use the same method I use to check dependencies in this stack if you like (which is essentially the method I use for Linux in the 'compatibility' card of the Preferences)
Short version: I'm using:
Code: Select all
dpkg -s "[thing]"
- Attachments
-
- browser-test-2-deps-only.oxtstack
- (8.57 KiB) Downloaded 9 times
- OpenXTalkPaul
- Posts: 2379
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Cross-platform sound playing
This method assumes user is running a Debian based Linux Disto or otherwise has .deb package manager, some distros like Fedora or Arch Linux use different package managers.tperry2x wrote: ↑Fri Nov 29, 2024 10:43 am Yes, that's a good point - although, that's especially true for any of the linux-type libraries we are adding.
You could use the same method I use to check dependencies in this stack if you like (which is essentially the method I use for Linux in the 'compatibility' card of the Preferences)
Short version: I'm using:So, dpkg -s "flex" where "flex" is the name of what I'm checking for of course.Code: Select all
dpkg -s "[thing]"
While 'which' and "command -v" work on even macOS
- OpenXTalkPaul
- Posts: 2379
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Cross-platform sound playing
ALSA (Advanced Linux Sound Architecture) is the default sound framework built into Linux kernels since v2.6, so I was thinking for Linux it may be better to skip mPlayer and even Pulse Audio and instead go more direct using ALSA.
ALSA is a bit more complicated than using something more abstracted from the hardware like mPlayer. That's because it provides more options, such as recording smaller size files by using lower sample rates, or playing back sound on a specific output device like the headphones jack (as opposed to speaker or line-level out jack)
Prior to ALSA, OSS (Open Sound System) was typically built into Linux Kernel, more simple to use than ALSA. ALSA can emulate OSS, but for that a build flag needs to be set when the kernel is built, and I have no idea how commonly that is set with various builds of the kernel in the many different Linux distros out there. It's also a much older architecture, so I think best to avoid using OSS.
ALSA has a CLI interface aplay and arecord
Here's example command lines:
Play sound with defaults:
This would play an audio file mysound.wav using (-D) the audio device hw:0,0 and with (-c) 2 channels.
List audio hardware devices:
List all connections (PCM i/o):
ALSA is a bit more complicated than using something more abstracted from the hardware like mPlayer. That's because it provides more options, such as recording smaller size files by using lower sample rates, or playing back sound on a specific output device like the headphones jack (as opposed to speaker or line-level out jack)
Prior to ALSA, OSS (Open Sound System) was typically built into Linux Kernel, more simple to use than ALSA. ALSA can emulate OSS, but for that a build flag needs to be set when the kernel is built, and I have no idea how commonly that is set with various builds of the kernel in the many different Linux distros out there. It's also a much older architecture, so I think best to avoid using OSS.
ALSA has a CLI interface aplay and arecord
Here's example command lines:
Play sound with defaults:
Code: Select all
aplay mysound.wav
Code: Select all
aplay -D hw:0,0 -c 2 mysound.wav
Code: Select all
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: 92HD93BXX Analog [92HD93BXX Analog]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
Subdevices: 0/1
Subdevice #0: subdevice #0
Code: Select all
aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
lavrate
Rate Converter Plugin Using Libav/FFmpeg Library
samplerate
Rate Converter Plugin Using Samplerate Library
speexrate
Rate Converter Plugin Using Speex Resampler
jack
JACK Audio Connection Kit
oss
Open Sound System
pipewire
PipeWire Sound Server
pulse
PulseAudio Sound Server
speex
Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
Plugin for channel upmix (4,6,8)
vdownmix
Plugin for channel downmix (stereo) with a simple spacialization
default
Default ALSA Output (currently PipeWire Media Server)
hw:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
Direct hardware device without any conversions
hw:CARD=PCH,DEV=3
HDA Intel PCH, HDMI 0
Direct hardware device without any conversions
hw:CARD=PCH,DEV=7
HDA Intel PCH, HDMI 1
Direct hardware device without any conversions
hw:CARD=PCH,DEV=8
HDA Intel PCH, HDMI 2
Direct hardware device without any conversions
plughw:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
Hardware device with all software conversions
plughw:CARD=PCH,DEV=3
HDA Intel PCH, HDMI 0
Hardware device with all software conversions
plughw:CARD=PCH,DEV=7
HDA Intel PCH, HDMI 1
Hardware device with all software conversions
plughw:CARD=PCH,DEV=8
HDA Intel PCH, HDMI 2
Hardware device with all software conversions
sysdefault:CARD=PCH
HDA Intel PCH, 92HD93BXX Analog
Default Audio Device
front:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
Front output / input
surround21:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
hdmi:CARD=PCH,DEV=0
HDA Intel PCH, HDMI 0
HDMI Audio Output
hdmi:CARD=PCH,DEV=1
HDA Intel PCH, HDMI 1
HDMI Audio Output
hdmi:CARD=PCH,DEV=2
HDA Intel PCH, HDMI 2
HDMI Audio Output
dmix:CARD=PCH,DEV=0
HDA Intel PCH, 92HD93BXX Analog
Direct sample mixing device
dmix:CARD=PCH,DEV=3
HDA Intel PCH, HDMI 0
Direct sample mixing device
dmix:CARD=PCH,DEV=7
HDA Intel PCH, HDMI 1
Direct sample mixing device
dmix:CARD=PCH,DEV=8
HDA Intel PCH, HDMI 2
Direct sample mixing device
usbstream:CARD=PCH
HDA Intel PCH
USB Stream Output
- tperry2x
- Posts: 2763
- Joined: Tue Dec 21, 2021 9:10 pm
- Location: Somewhere in deepest darkest Norfolk, England
- Contact:
Re: Cross-platform sound playing
It is true that I focussed on debian-based distros (not necessarily Ubuntu - or any of the 'buntus) because much of the other engine dependencies (not only the video ones), but the player dependencies and the web dependencies - some of those are only available as debian packages. So I haven't worried about other non-debian ones. At a quick count, this gives us at least over 120 different linux distros, so I'm not too worried about supporting things without debian underpinnings.
Plus, I'm not too sure how / if standalones created with LCC / OXT actually run on non-debian Linuxes
If you attempt to launch a linux LCC-created (or OXT-created) standalone on a non-debian system via the terminal, you are greeted with endless errors.
Plus, I'm not too sure how / if standalones created with LCC / OXT actually run on non-debian Linuxes
If you attempt to launch a linux LCC-created (or OXT-created) standalone on a non-debian system via the terminal, you are greeted with endless errors.
- richmond62
- Posts: 4185
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Cross-platform sound playing
I suspect Mark Weider can tell you about that.
https://richmondmathewson.owlstown.net/
Who is online
Users browsing this forum: No registered users and 0 guests