Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
What does aplay do? –  Mark Dec 12 '12 at 11:34
    
See edit, linked url. –  Michal Dec 12 '12 at 12:17
add comment

3 Answers

up vote 3 down vote accepted

I believe the sox utility stands in for aplay.

share|improve this answer
add comment

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).)

share|improve this answer
    
The fun part about the aplay and this little C algorithm is that it changes and generates different sounds over time, so outputting it would take that away :( –  Michal Dec 12 '12 at 14:02
    
See it as a longer time delay for buffering playback. :-) how is that data to be interpreted? That might help to find a suitable command line utility that works on OS X to play the data generated by the utility. (For example that might work with mpg123 though I haven't tried that yet.) –  MacLemon Dec 12 '12 at 14:32
    
So what would you suggest? –  Michal Dec 12 '12 at 16:08
add comment

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 2 -b 8 -e unsigned -t raw -r 48k -

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.