[R-SIG-Mac] sound::setWavPlayer()

Hans-Jörg Bibiko bibiko at eva.mpg.de
Tue Sep 2 13:16:25 CEST 2008


On 28.08.2008, at 19:59, Hans-Jörg Bibiko wrote:
> On 28.08.2008, at 19:41, Simon Urbanek wrote:
>>> The only idea I have for now is to use a scripting language to  
>>> write a primitive audio player, and the only language which is  
>>> installed by default on all these platforms is Java. It shouldn't  
>>> be that problem to write such a JFrame jar.
>>>
>> ... But, yes, using Java would be one option except that Java is  
>> quite a heavy requirement for such task ...
> Now I only try to avoid a GUI. It looks different on each OS, thus I  
> try to write a simple command line tool

Well, I tried it out and I came up with a Java command line tool as a  
jar file (size with source code 4171 bytes).
I ran it on Win XP, Vista, Linux SuSe 9.0 and 10.2, Mac Tiger ppc, Mac  
Leopard i386 and it seems to work properly.

The Java tool simply plays back a given linear PCM sound file  
(supported formats: wav, aifc, aiff, au, snd). This tool can only run  
once on a machine, meaning if one invokes it and while playing back a  
sound file one invokes it with an other sound file, the currently  
running sound file will be stopped before the next one will be  
started. This is done by using a simple lock-file mechanism.

If playLinearAudioFile.jar detects a running process it will delete  
one lock file to interrupt the current process. Due to that fact that  
the Java script sends buffer by buffer to the audio stream (to  
minimize CPU and RAM resources) it could take some ticks (depending on  
the buffer size) before the current process will be interrupted.

To stop a running process one invokes playLinearAudioFile.jar without  
any arguments. If there's no running process it outputs the usage  
message.

Furthermore there's an option called '--deleteAfterPlay'. This option  
enables the user to say, please delete the given sound file after play- 
back (useful for playing back temporarily generated sound files).

Of course, as already mentioned Java takes some ticks to start that  
jar script but I've also tested it on slow machines and the time was  
always below 500ms.

I've also tested it with R. It seems to work, even with the system()'s  
argument wait=FALSE. While listing to the sound one can do other stuff  
with R.

To invoke it simply write:

java -jar playLinearAudio.jar SOUND_FILE

The Java script only makes usage of commands and packages which are  
available since Java 1.3.

Unfortunately I couldn't test it on Solaris, AIX, IRIX, ... but if  
Java 1.3 or up is installed it should work.

The source file and the manifest file 'mainClass.txt' are included in  
the jar archive.
To create a jar archive:
jar cmf mainClass.txt playLinearAudioFile.jar *.class *.java  
mainClass.txt


If there's an interest, please check it on other OS. I'd be  
appreciated for any critique.

Cheers,

Hans


-------------- next part --------------
A non-text attachment was scrubbed...
Name: playLinearAudioFile.jar
Type: application/java-archive
Size: 4171 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-mac/attachments/20080902/66ba7e2f/attachment.bin>
-------------- next part --------------



More information about the R-SIG-Mac mailing list