* Bugs 16137 16138 16140 fixed: playsnd() fixed & upgraded 44/21044/11
Samuel GOUGEON [Fri, 19 Jul 2019 21:56:05 +0000 (23:56 +0200)]
  http://bugzilla.scilab.org/16137
  http://bugzilla.scilab.org/16138
  http://bugzilla.scilab.org/16140

  Overhauled playsnd() page (PDF):
  http://bugzilla.scilab.org/attachment.cgi?id=4982
  (see the History)

Change-Id: I9f7c9af0a0f1f713a0030260889fe3d060436688

scilab/CHANGES.md
scilab/modules/sound/help/en_US/playsnd.xml
scilab/modules/sound/help/ja_JP/playsnd.xml [deleted file]
scilab/modules/sound/macros/playsnd.sci

index b922a1d..e3562cc 100644 (file)
@@ -137,6 +137,10 @@ Feature changes and additions
   - Handles of the grids and labels are returned. Post-processing them become easy.
   - Named colors accepted ; better default colors.
   - Improved placement of labels.
+* `playsnd()` is upgraded:
+  - the name of a wav file can now be specified (instead of the sound data).
+  - the input sound can now be repeated a given number of times.
+  - the modal/non-modal processing is improved.
 * `nicholschart` is improved: more neutral default frame color; improved labels positionning; colors can now be specified by their predefined name or "#RRGGBB" hexa code; a structure of handles is now returned to easily postprocess both subframes and the set of labels.
 * `sciargs()` returns a column instead of formerly a row.
 * Booleans and encoded integers can now be concatenated together, as in `[%f int8(-5)]`.
@@ -148,6 +152,7 @@ Feature changes and additions
 * `repmat()` has been rewritten. It is 7 times faster now.
 
 
+
 Help pages:
 -----------
 
@@ -232,7 +237,7 @@ Bug Fixes
 * [#10723](http://bugzilla.scilab.org/show_bug.cgi?id=10723): `subplot`'s action was unclearly described in its help page. Page improved.
 * [#11852](http://bugzilla.scilab.org/show_bug.cgi?id=11852): File browser didn't update after file creation or remove.
 * [#11363](http://bugzilla.scilab.org/show_bug.cgi?id=11363): show_window() did not raise the current graphics window.
-* [#13738](http://bugzilla.scilab.org/show_bug.cgi?id=13738): `get_figure_handle` was a specific duplicate of the more powerful `findobj('figure_id',n)` feature. It is now obsolete. 
+* [#13738](http://bugzilla.scilab.org/show_bug.cgi?id=13738): `get_figure_handle` was a specific duplicate of the more powerful `findobj('figure_id',n)` feature. It is now obsolete.
 * [#12520](http://bugzilla.scilab.org/show_bug.cgi?id=12520): Vriable browser did not display the size of the variables.
 * [#12534](http://bugzilla.scilab.org/show_bug.cgi?id=12534): Variable browser did not display the size of the variables.
 * [#12837](http://bugzilla.scilab.org/show_bug.cgi?id=12837): `strcmpi` was an obsolete duplicate of `strcmp(,'i')`. It is removed.
@@ -343,7 +348,10 @@ Bug Fixes
 * [#16111](http://bugzilla.scilab.org/show_bug.cgi?id=16111): `isglobal` was not supporting non-scalar array of strings as input.
 * [#16118](http://bugzilla.scilab.org/show_bug.cgi?id=16118): `%s <> (1+%s)` returned %F.
 * [#16135](http://bugzilla.scilab.org/show_bug.cgi?id=16135): base2dec did not detect invalid numbers.
+* [#16137](http://bugzilla.scilab.org/show_bug.cgi?id=16137): After running `playsnd(..)` on Windows for a long sound, it was not possible to stop it.
+* [#16138](http://bugzilla.scilab.org/show_bug.cgi?id=16138): `playsnd(..)` could not be run in a non-modal (asynchronous) way on Linux and MacOS.
 * [#16139](http://bugzilla.scilab.org/show_bug.cgi?id=16139): `auread()` and `auwrite()` kept the sound file open and locked when returning on errors. They poorly handled the default .au sound file extension.
+* [#16140](http://bugzilla.scilab.org/show_bug.cgi?id=16140): `playsnd(..)` could not directly accept an audio file and could not repeat the input sound.
 * [#16143](http://bugzilla.scilab.org/show_bug.cgi?id=16143): `clc(n)` cleared n+1 lines instead of n>0. Thus, it was not possible to clear only one line.
 * [#16144](http://bugzilla.scilab.org/show_bug.cgi?id=16144): Addition of sparse matrices gave incorrect results.
 * [#16148](http://bugzilla.scilab.org/show_bug.cgi?id=16148): `setPreferencesValue` is a general usage function and deserved to be renamed `xmlSetValues`.
@@ -394,4 +402,3 @@ Bug Fixes
 * [#16307](http://bugzilla.scilab.org/show_bug.cgi?id=16307): `dockable="off"` and `closerequestfcn` on figures crached Scilab.
 * [#16320](http://bugzilla.scilab.org/show_bug.cgi?id=16320): There were unsupported UTF-8 characters in some gettext id messages.
 * [#16321](http://bugzilla.scilab.org/show_bug.cgi?id=16321): There were typo errors in the documentation.
-
index 3f678bf..4bbd0b4 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-    * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-    * Copyright (C) ????-2006 - INRIA - Scilab
-    *
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) ????-2006 - INRIA - Scilab
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2019 - Samuel GOUGEON
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
  * and continues to be available under such terms.
  * For more information, see the COPYING file which you should have received
  * along with this program.
-    *
-    -->
+ *
+-->
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
           xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
           xml:lang="en" xml:id="playsnd">
     <refnamediv>
         <refname>playsnd</refname>
-        <refpurpose>sound player facility</refpurpose>
+        <refpurpose>command-line sound player facility</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
         <synopsis>
-          playsnd(y)
-          playsnd(y, rate, bits)
-          playsnd(y, rate, bits, command)
+            playsnd(filename)
+            playsnd(filename, speed)
+            playsnd(filename, speed, nbiter)
+            playsnd(filename, speed, nbiter, playerCmd)
+            playsnd(filename, speed, playerCmd)
+
+            playsnd(y)
+            playsnd(y, rate)
+            playsnd(y, rate, nbiter)
+            playsnd(y, rate, nbiter, playerCmd)
+            playsnd(y, rate, playerCmd)
+
+            playsnd([])
         </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
         <variablelist>
             <varlistentry>
+                <term>filename</term>
+                <listitem>
+                    single string: the path and name of the sound file to play.
+                    <para/>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>speed</term>
+                <listitem>
+                    real positive number: relative playing speed.
+                    <varname>speed</varname> &lt; 1 plays slower,
+                    while <varname>speed</varname> > 1 plays faster. (1.0 by default).
+                    <para/>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
                 <term>y</term>
                 <listitem>
-                    <para>A matrix. Each line describes a channel</para>
+                    matrix of normalized linear sound data, in [-1,1]. Each row feeds a channel.
+                    <para/>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>rate</term>
                 <listitem>
-                    <para>real number, sampling frequency (default value is 22050).</para>
+                    real positive number: sampling frequency in Hz (default value is 22050).
+                    <para/>
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>bits</term>
+                <term>nb_iter</term>
                 <listitem>
-                    <para>real number, number of bits (usually 8 or 16). Unused yet.</para>
+                    positive decimal integer: number of consecutive times (iterations) that
+                    the sound must be played.
+                    <para/>
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>command</term>
+                <term>playerCmd</term>
                 <listitem>
-                    <para>Only used on Unix systems it gives the name of the command to use for playing sound
-                        (wav) files. The default value is <literal>play</literal>. If set <literal>/dev/audio</literal> then
-                        a 8 bits mu-law raw sound file is created and send to <literal>/dev/audio</literal>
-                    </para>
+                    Only used on Unix and MacOS systems. Single string giving the OS command
+                    to use for playing sound (wav) files. The default value is
+                    <literal>"aplay"</literal> on Linux and <literal>"afplay"</literal> on MacOS.
+                    <para/>
+                    If <varname>playerCmd</varname> is set to <literal>/dev/audio</literal>,
+                    then a 8 bits mu-law raw sound file is created and send to
+                    <literal>/dev/audio</literal>.
+                    <para/>
                 </listitem>
             </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
         <title>Description</title>
-        <para>Plays a multi channel signal given by a Scilab matrix were sound is sampled at rate given by
-            <literal>rate</literal>.
+        <para>
+            <emphasis role="bold">playsnd(filename,..)</emphasis> or
+            <emphasis role="bold">playsnd(y,..)</emphasis>
+            cancels any running sound and then starts playing a single or multi channel signal.
+        </para>
+        <para>
+            When <varname>nb_iter</varname> is not used, the sound is played only once, and
+            <literal>playsnd(…)</literal> behaves in a non-modal way: Scilab returns to the prompt
+            or to the next instruction just after starting playing, without waiting for the end of
+            the sound.
+        </para>
+        <para>
+            Otherwise, the sound is played <varname>nb_iter</varname> consecutive times,
+            and <literal>playsnd(…)</literal> becomes modal (even for
+            <varname>nb_iter</varname>=1): Scilab returns to the prompt
+            or to the next instruction only after the end of the last time the sound is played.
+            <note>
+                The repetition is interruptible with CTRL-C or any <literal>pause</literal> or
+                <literal>abort</literal> callback instruction.
+            </note>
+        </para>
+        <para>
+            <emphasis role="bold">playsnd([])</emphasis> cancels any sound running without
+            <varname>nb_iter</varname> and not through /dev/audio.
         </para>
     </refsection>
     <refsection>
         <title>Examples</title>
+        <para>
+            Playing a sound from its audio file:
+        </para>
         <programlisting role="example"><![CDATA[
 // A two channel signal
+File = "SCI/modules/sound/demos/chimes.wav";
+playsnd(File)           // Play it once at normal speed
+sleep(5)
+playsnd(File, 2)        // Play it once at speed x 2
+sleep(5)
+playsnd(File,, 3)       // Play it 3 times at normal speed
+sleep(5)
+playsnd(File, 1.5, 3)   // Play it 3 times at speed x 1.5
+sleep(5)
+playsnd(File, 0.2)      // Play it once and slowly.
+                        // Note that Scilab returns as soon as the player starts.
+// Plays a longer sound. Interrupts it 1.0 s after it started:
+playsnd(File, 0.2), sleep(1,'s'), playsnd([])
+ ]]></programlisting>
+        <para/>
+        <para>
+            Playing a sound from its data in a matrix:
+        </para>
+        <programlisting role="example"><![CDATA[
 y = loadwave("SCI/modules/sound/demos/chimes.wav");
-playsnd(y)
+playsnd(y)              // Play it once at the default 22050 Hz sampling rate
+sleep(5)
+playsnd(y, 3e4)         // Play it once at 30 kHz sampling rate
+sleep(5)
+playsnd(y,, 3)          // Play it 3 times at the default sampling rate
+sleep(5)
+playsnd(y, 44100, 3)    // Play it 3 times at 44.1 kHZ sampling rate
+ ]]></programlisting>
+        <para/>
+        <para>
+            Interrupting  with CTRL + C a repeated sound:
+        </para>
+        <programlisting role="example"><![CDATA[
+playsnd("SCI/modules/sound/demos/chimes.wav",, 20);
+// Now enter CTRL-C to interrupt the repetition
+// Then type "resume" or "abort"
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
         <simplelist type="inline">
             <member>
+                <link linkend="beep">beep</link>
+            </member>
+            <member>
+                <link linkend="realtime">realtime</link>
+            </member>
+            <member>
                 <link linkend="lin2mu">lin2mu</link>
             </member>
             <member>
                 <link linkend="wavread">wavread</link>
             </member>
+            <member>
+                <link linkend="auread">auread</link>
+            </member>
+            <member>
+                <link linkend="mcisendstring">mcisendstring</link>
+            </member>
+            <member>
+                <link linkend="winopen">winopen</link>
+            </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.1.0</revnumber>
+                <revdescription>
+                    <itemizedlist>
+                        <listitem>
+                            playsnd(filename,..) can now be used. The relative speed wrt the native
+                            one in the file can be specified.
+                        </listitem>
+                        <listitem>
+                            nb_iter option introduced.
+                        </listitem>
+                        <listitem>
+                            playsnd([]) is introduced to stop a sound run without repetition.
+                        </listitem>
+                        <listitem>
+                            playsnd(…) is now by default not-modal on Linux and MacOS, like on Windows.
+                        </listitem>
+                        <listitem>
+                            playsnd(…) can now be modal on any OS, through any explicit nb_iter value.
+                        </listitem>
+                        <listitem>
+                            Input argument bits removed.
+                        </listitem>
+                    </itemizedlist>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
diff --git a/scilab/modules/sound/help/ja_JP/playsnd.xml b/scilab/modules/sound/help/ja_JP/playsnd.xml
deleted file mode 100644 (file)
index c0b42e3..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-    * Copyright (C) ????-2006 - INRIA - Scilab
-    *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
-    *
-    -->
-<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
-          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
-          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
-          xml:lang="ja" xml:id="playsnd">
-    <refnamediv>
-        <refname>playsnd</refname>
-        <refpurpose>サウンドプレイヤー機能</refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title>呼び出し手順</title>
-        <synopsis>
-          playsnd(y)
-          playsnd(y, rate, bits)
-          playsnd(y, rate, bits, command)
-        </synopsis>
-    </refsynopsisdiv>
-    <refsection>
-        <title>引数</title>
-        <variablelist>
-            <varlistentry>
-                <term>y</term>
-                <listitem>
-                    <para>行列. 各行は1チャネルを記述</para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>rate</term>
-                <listitem>
-                    <para>実数, サンプリング周波数 (デフォルト値は22050).</para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>bits</term>
-                <listitem>
-                    <para>実数, ビット長 (通常 8 または 16). 未使用.</para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>command</term>
-                <listitem>
-                    <para>
-                        Unixシステムのみで使用され,
-                        サウンド(wav)ファイルを演奏する際に使用されるコマンド名を指定します.
-                        デフォルト値は<literal>play</literal>です.
-                        <literal>/dev/audio</literal>が指定された場合,
-                        8ビットmu-law rawサウンドが生成され,
-                        <literal>/dev/audio</literal>に送信されます.
-                    </para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
-    <refsection>
-        <title>説明</title>
-        <para>
-            Scilab行列で指定されたマルチチャネル信号を演奏します.
-            ただし, サウンドのサンプリングレートは<literal>rate</literal>です.
-        </para>
-    </refsection>
-    <refsection>
-        <title>例</title>
-        <programlisting role="example"><![CDATA[
-// A two channel signal
-y = loadwave("SCI/modules/sound/demos/chimes.wav");
-playsnd(y)
- ]]></programlisting>
-    </refsection>
-    <refsection role="see also">
-        <title>参照</title>
-        <simplelist type="inline">
-            <member>
-                <link linkend="lin2mu">lin2mu</link>
-            </member>
-            <member>
-                <link linkend="wavread">wavread</link>
-            </member>
-        </simplelist>
-    </refsection>
-</refentry>
index 6cad7cd..3b51ed9 100644 (file)
@@ -2,8 +2,8 @@
 // Copyright (C) ???? - INRIA - Scilab
 // Copyright (C) ???? - ENPC
 // Copyright (C) 2009 - DIGITEO - Allan CORNET
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2019 - Samuel GOUGEON
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // pursuant to article 5.3.4 of the CeCILL v.2.1.
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-function [] = playsnd(y, rate, bits, aplay)
-    // play signal y at sample rate rate
-    // bits is unused
-    [lhs,rhs] = argn(0);
+function playsnd(y, rate, nbiter, playerCmd)
 
-    // default values
-    if (rhs <= 2) then
-        bits = 16;
+    [lhs,rhs] = argn(0);
+    fname = "playsnd"
+    File = ""
+    if argn(2) < 1 | argn(2) > 4
+        msg = _("%s: Wrong number of input arguments: %d or %d expected.\n")
+        error(msprintf(msg, fname, 1, 4))
     end
 
-    if (rhs <= 1) then
-        rate = 22050;
+    // PARSING INPUT ARGUMENTS and SETTING DEFAULT VALUES
+    // ==================================================
+    // rate / speed
+    // ------------
+    if ~isdef("rate","l") then
+        if type(y)==1
+            rate = 22050;
+        else
+            rate = 1
+        end
     end
 
-    if rhs > 2 then
+    // nbiter
+    // ------
+    iPlayerCmd = 4    // index of playerCmd (if any)
+    if ~isdef("nbiter","l")
+        nbiter = -1
+        iPlayerCmd = 3
+    else
+        if and(type(nbiter)<>[1 10])
+            msg = _("%s: Argument #%d: %s expected.\n")
+            error(msprintf(msg, fname, 3, "Decimal numbers or Text"))
+        end
+        nbiter = nbiter(1)
+        if type(nbiter)==10
+            playerCmd = nbiter
+            iPlayerCmd = 3
+            nbiter = -1
+        elseif nbiter < 1
+            msg = _("%s: Argument #%d: Must be >= %d.\n")
+            error(msprintf(msg, fname, 3, 1))
+        else
+            nbiter = int(nbiter)
+        end
+    end
 
-        if type(aplay) <> 10 then
-            error(msprintf(_("%s: Wrong type for input argument #%d: string expected.\n"),"playsnd",3));
+    // playerCmd
+    // ---------
+    if ~isdef("playerCmd","l") then
+        if getos() == "Darwin" then
+            playerCmd = "afplay"
+        else
+            playerCmd = "aplay";
+        end
+    else
+        if type(playerCmd) <> 10 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: string expected.\n"), fname, iPlayerCmd));
         end
+        if size(playerCmd,"*") <> 1 then
+            error(msprintf(_("%s: Wrong size for input argument #%d: string expected.\n"), fname, iPlayerCmd));
+        end
+    end
 
-        if size(aplay,"*") <> 1 then
-            error(msprintf(_("%s: Wrong size for input argument #%d: string expected.\n"),"playsnd",3));
+    // Input sound data
+    // ----------------
+    if and(type(y) <> [1 10]) then
+        msg = _("%s: Argument #%d: %s expected.\n")
+        error(msprintf(msg, fname, 1, "Decimal numbers or Text"))
+    end
+    if type(y)==10 then
+        File = pathconvert(y(1),%f)
+        if isdir(File)
+            msg = _("%s: Argument #%d: ''%s'' is a directory. File expected.\n")
+            error(msprintf(msg, fname, 1, File))
+        end
+        if ~isfile(File)
+            msg = _("%s: Argument #%d: The file ''%s'' does not exist.\n")
+            error(msprintf(msg, fname, 1, File))
         end
+        if type(rate) <> 1
+            msg = _("%s: Argument #%d: Decimal number expected.\n")
+            error(msprintf(msg, fname, 2))
+        end
+        rate = rate(1)
+        if rate <= 0
+            msg = _("%s: Argument #%d: Must be > %d.\n")
+            error(msprintf(msg, fname, 2, 0))
+        end
+        info = wavread(y,"info");
+        // The only case where the file can be used as is without being
+        // loaded is when the speed = 1 & OS = Linux | MacOS &
+        // playerCmd <> "dev/audio"
+        // Note : On linux and MacOS: aplay and afplay have a -r option
+        //    but it does not work
+        if getos()=="Windows" | rate <> 1 | grep(playerCmd,"/dev/audio")<>[]
+            y = wavread(y);
+        end
+        rate = rate * info(3);
+        duration = info(8) / rate   // [s]
+    end
 
-    else
-        if rhs <= 3 then
-            if getos() == "Darwin" then
-                aplay = "afplay"
-            else
-                aplay = "aplay";
-            end
+    // wav file
+    // ========
+    if type(y)==1 & y <> [] & grep(playerCmd,"/dev/audio")==[] then
+        File = pathconvert("TMPDIR/_playsnd_.wav", %f)
+        [fid, typ, names] = file();
+        tmp = find(names==File,1)
+        if tmp <> []
+            mclose(fid(tmp))
         end
+        savewave(File, y, rate);
+        duration = size(y,2)/rate
+    elseif y<>[] & isdef("File","l")
+        info = wavread(File,"info");
+        duration = info(8)/rate
     end
 
+    // Play
+    // ====
     if getos() == "Windows" then
-        savewave(TMPDIR+"/_playsnd_.wav", y, rate);
-        PlaySound(TMPDIR+"/_playsnd_.wav");
-        return
+        PlaySound("")
+        if y <> []
+            if nbiter==-1
+                PlaySound(File) // Asynchronous
+            else
+                realtimeinit(1)
+                realtime(0)
+                for i = 1:nbiter
+                    PlaySound(File);
+                    realtime(i*duration)
+                end
+            end
+        end
     else
-
         // We should use a external C library here
-        if aplay <> "/dev/audio" then
-            savewave(TMPDIR+"/_playsnd_.wav", y, rate);
-            cmd = msprintf("%s  %s > /dev/null 2>&1", aplay, TMPDIR + "/_playsnd_.wav");
-            [res, stat, stderr] = unix_g(cmd);
-            if (stat <> 0) then
-                error(msprintf(_("%s: Failed to play the sound with command: %s.\n"), "playsnd",  cmd));
+        if playerCmd <> "/dev/audio" then
+            player = strtok(playerCmd, " ")
+            options = strchr(playerCmd," ")
+            unix("killall -9 " + player + " 2> /dev/null")
+            //cmd = "%s --disable-resample -r %d %s ''%s'' > /dev/null 2>&1 &"
+            cmd = "%s %s ''%s'' > /dev/null 2>&1 &"
+            cmd = msprintf(cmd, player, options, File);
+            if y <> []
+                msg = msprintf(_("%s: Failed to play the sound with command: %s.\n"), fname,  cmd)
+                if nbiter==-1
+                    unix_g(cmd);
+                else
+                    realtimeinit(1)
+                    realtime(0)
+                    for i = 1:nbiter
+                        unix_g(cmd);
+                        realtime(i*duration)
+                    end
+                end
             end
-
         else
             [fp, www] = mopen("/dev/audio","wb", 0);
             if www < 0 then
                 fp = -1;
             end
-
-            if fp == (-1) then
-                warning(msprintf(_("%s: Audio capabilities not available.\n"),"playsnd"));
-                return
+            if fp == -1 then
+                warning(msprintf(_("%s: Audio capabilities not available.\n"), fname));
+            else
+                y = lin2mu(y)
+                // Here: Don't know how to interrupt a running audio stream
+                if nbiter==-1
+                    mput(y,"uc",fp);
+                else
+                    realtimeinit(1)
+                    realtime(0)
+                    for i = 1:nbiter
+                        mput(y,"uc",fp);
+                        realtime(i*duration)
+                    end
+                end
+                mclose(fp);
             end
-
-            mput(lin2mu(y),"uc",fp);
-            mclose(fp);
-
         end
     end
 
+    // Cleaning
+    // ========
+    sleep(100)
+    deletefile(TMPDIR+"/_playsnd_.wav")
 endfunction