Alternative to APLAY for Mac OS X bash

Anybody knows any Mac alternative for Linux's APLAY program? I would like to run this script:

echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay

Which makes great sound effect, but I don't know how, since Mac OS doesn't have aplay.

EDIT:

Link to Wikipedia, which describes the functionality of aplay.


I believe the sox utility stands in for aplay.


Here is the same program, as a perl one-liner, which works (tested) on Mac, Linux, and Windows

perl -e 'for($i=0;;$i++){
    print pack("n", ((($i*($i>>8|$i>>9)&46&$i>>8))^($i&$i>>13|$i>>6))); 
}' | ./play -c 1 -b 8 -e unsigned -t raw -r 8k -

the "./play" command is the "sox" utility already mentioned in this article. 



I know that this topic is old, but I've find a recent working solution. SOX doesn't support input from stdout anymore so now a working alternative is mplayer. You'll need to install it using Hombrew.sh with brew install mplayer.

You can then replace aplay by: mplayer -cache 1024 -quiet -rawaudio samplesize=1:channels=1:rate=8000 -demuxer rawaudio -

Just be sure to change rate=8000 with your custom frequency.

You can create an alias in ~/.bashrc for aplay to pipe your PCM chiptune in like this:

alias aplay="mplayer -cache 1024 -quiet -rawaudio samplesize=1:channels=1:rate=8000 -demuxer rawaudio -"

Hope this helped, tested on macOs Sierra 10.12.5 today.


aplay needs ALSA which is only available on Linux. You could try outputting that bytestream to a file and try to play with afplay on OS X. (You likely need to add proper AIFF headers for afplay to accept the file since it won't play a raw PCM dump (or however that bytestream coming out of that echo should be interpreted).)