* Bug 15978 fixed [sound]: wavwrite (en) page. savewave: + mclose() < errors 98/20898/5
Samuel GOUGEON [Sun, 10 Mar 2019 04:19:13 +0000 (05:19 +0100)]
  http://bugzilla.scilab.org/15978

Change-Id: I553eb9c190dfc74dfe09613f0e6c1ac018486b6b

scilab/CHANGES.md
scilab/modules/sound/help/en_US/wavwrite.xml
scilab/modules/sound/help/ja_JP/wavwrite.xml
scilab/modules/sound/macros/savewave.sci

index d92b9d5..5c42877 100644 (file)
@@ -269,6 +269,7 @@ Bug Fixes
 * [#15964](http://bugzilla.scilab.org/show_bug.cgi?id=15954): A complex empty sparse matrix could be obtained after insertion.
 * [#15969](http://bugzilla.scilab.org/show_bug.cgi?id=15969): Fix spelling
 * [#15974](http://bugzilla.scilab.org/show_bug.cgi?id=15974): `msprintf("%d", %nan)` did not return Nan
+* [#15978](http://bugzilla.scilab.org/show_bug.cgi?id=15978): The `writewav()` page in english said that input data are one column per channel, instead of one row per channel. In addition, in case of writing error, `savewave()` kept the output file open and locked.
 * [#15983](http://bugzilla.scilab.org/show_bug.cgi?id=15983): `group` regressed in 5.5.2 due to a too intrusive fix.
 * [#15984](http://bugzilla.scilab.org/show_bug.cgi?id=15984): display scale was wrong with Retina dispplays on OSX..
 * [#15995](http://bugzilla.scilab.org/show_bug.cgi?id=15995): patch was missing in surface plot (regression)
index 203918e..325fa98 100644 (file)
@@ -1,8 +1,8 @@
 <?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
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * 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:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="wavwrite" xml:lang="en">
+ *
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="wavwrite" xml:lang="en">
     <refnamediv>
         <refname>wavwrite</refname>
         <refpurpose>writes .wav sound file</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>wavwrite(y, wavfile)
+        <synopsis>
+            wavwrite(y, wavfile)
             wavwrite(y, Fs, wavfile)
             wavwrite(y, Fs, nbits, wavfile)
         </synopsis>
             <varlistentry>
                 <term>y</term>
                 <listitem>
-                    <para>real vector or matrix with entries in [-1,1].</para>
+                    <para>row vector or matrix: Sound amplitudes = real values in [-1,1].
+                        One row per channel. Values out of [-1,+1] are ignored.
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>wavfile</term>
                 <listitem>
-                    <para>string (The .wav extension is appended if no extension is
-                        given)
+                    <para>string (The .wav extension is appended if no extension is given)
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>Fs</term>
                 <listitem>
-                    <para>integer, frequency sampling in Hz. 22500 is the default value.</para>
+                    <para>integer: Sampling frequency, in Hz. 22500 is the default value.</para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>nbits</term>
                 <listitem>
-                    <para>bit-depth 8, 16, 24, 32 bits. it describes the number of bits of information recorded for each sample.
-                        16 is the default value.
+                    <para>bit-depth 8, 16, 24, 32 bits. it describes the number of bits of
+                          information recorded for each sample. 16 is the default value.
                     </para>
                 </listitem>
             </varlistentry>
         <para>
             Utility function to save <literal>.wav</literal> sound file.
             <literal>wavwrite(y,wavfile)</literal> writes a sound file specified by
-            the string wavfile. The data should be arranged with one channel per
-            column. Amplitude values outside the range [-1,+1] are ignored.
+            the string <literal>wavfile</literal>.
         </para>
         <para>
             <literal>wavwrite(y,Fs,wavfile)</literal> specifies in
-            <literal>Fs</literal> the sample rate of the data in Hertz.
+            <literal>Fs</literal> the sampling rate of the data in Hertz.
         </para>
     </refsection>
     <refsection>
         <title>Examples</title>
         <programlisting role="example"><![CDATA[
-A=matrix(1:6,2,3);
+A = matrix(1:6,2,3);
 wavwrite(A/6,TMPDIR+'/foo.wav');
-B=wavread(TMPDIR+'/foo.wav');
+B = wavread(TMPDIR+'/foo.wav');
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
index 72d0517..7fe794d 100644 (file)
@@ -1,8 +1,8 @@
 <?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
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * 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:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="wavwrite" xml:lang="ja">
+ *
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
+          xmlns:scilab="http://www.scilab.org" xml:id="wavwrite" xml:lang="ja">
     <refnamediv>
         <refname>wavwrite</refname>
         <refpurpose>.wavサウンドファイルに書き込む</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>呼び出し手順</title>
-        <synopsis>wavwrite(y, wavfile)
+        <synopsis>
+            wavwrite(y, wavfile)
             wavwrite(y, Fs, wavfile)
             wavwrite(y, Fs, nbits, wavfile)
         </synopsis>
             <varlistentry>
                 <term>y</term>
                 <listitem>
-                    <para>実数ベクトルまたは行列,エントリは [-1,1]の範囲.</para>
+                    <para>
+                        実数ベクトルまたは行列,エントリは [-1,1]の範囲.
+                        デーはは1チャネル毎に1列に並べられている必要があります.
+                        範囲[-1,+1]を超える大きさは無視されます.
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
@@ -53,7 +61,6 @@
                     <para>ビット長8, 16, 24, 32 ビット.
                         各サンプルに記録される情報のビット数を示します.
                         16がデフォルト値です.
-                        k
                     </para>
                 </listitem>
             </varlistentry>
@@ -65,8 +72,6 @@
             <literal>.wav</literal> サウンドファイルを保存するためのユーティリティ関数.
             <literal>wavwrite(y,wavfile)</literal>は文字列wavfileで指定された
             サウンドファイルを書き込みます.
-            デーはは1チャネル毎に1列に並べられている必要があります.
-            範囲[-1,+1]を超える大きさは無視されます.
         </para>
         <para>
             <literal>wavwrite(y,Fs,wavfile)</literal> は,
@@ -77,9 +82,9 @@
     <refsection>
         <title>例</title>
         <programlisting role="example"><![CDATA[
-A=matrix(1:6,2,3);
+A = matrix(1:6,2,3);
 wavwrite(A/6,TMPDIR+'/foo.wav');
-B=wavread(TMPDIR+'/foo.wav');
+B = wavread(TMPDIR+'/foo.wav');
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
index a83c5f4..bba2230 100644 (file)
@@ -1,7 +1,8 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2008 - DIGITEO
-//
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
+// Copyright (C) 2018 - Stéphane MOTTELET
+// 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.
@@ -12,8 +13,7 @@
 
 // =============================================================================
 // WAVE Audio File Format
-// http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
-// http://www.digitalpreservation.gov/formats/fdd/fdd000001.shtml
+// https://www.loc.gov/preservation/digital/formats/fdd/fdd000001.shtml
 // =============================================================================
 function savewave(filename,x,rate,nbits)
 
@@ -98,6 +98,7 @@ function savewave(filename,x,rate,nbits)
         //   and a chunk structure.
         //   ck.fid, ck.ID, ck.Size, ck.Data
         if length(ck("ID"))<>4 then
+            mclose(ck("fid"));
             error(msprintf(gettext("%s: Wrong size for input argument #%d.\n"),"write_ckinfo",1));
         end
 
@@ -146,6 +147,7 @@ function savewave(filename,x,rate,nbits)
                 data = round((data+1)*(2^32-1)/2)-(2^31);
 
             else
+                mclose(fid)
                 error(msprintf(gettext("%s: An error occurred: %s\n"),"savewave",gettext("only 8/16/24/32 bits for the encoding.")));
             end
 
@@ -170,7 +172,6 @@ function savewave(filename,x,rate,nbits)
                 data_line = data;
             end
 
-
             try
                 mput(data_line,dtype,fid);
             catch
@@ -185,9 +186,9 @@ function savewave(filename,x,rate,nbits)
             end
         else
             // Unknown wave-format for data.
+            mclose(fid)
             error(msprintf(gettext("%s: An error occurred: %s\n"),"write_wavedat",gettext("Unknown data format.")));
         end
-        return
     endfunction
     // =============================================================================
     function [status]=write_wavefmt(fid,fmt)
@@ -210,6 +211,7 @@ function savewave(filename,x,rate,nbits)
             // Write standard <PCM-format-specific> info:
             mput(fmt("nBitsPerSample"),"us",fid)
         else
+            mclose(fid)
             error("Unknown data format.");
         end
     endfunction
@@ -237,11 +239,7 @@ function savewave(filename,x,rate,nbits)
 
     [fid,%v] = mopen(filename,"wb",1);
 
-    if (%v < 0) then
-        fid = -1;
-    end
-
-    if ( fid == (-1) ) then
+    if fid==-1 | %v < 0 then
         error(msprintf(gettext("%s: Cannot open file %s.\n"),"savewave",filename));
     end