Update savewave function to work in mono in 24bits (in addition to bug #11860). 93/13393/2
Charlotte HECQUET [Fri, 3 Jan 2014 10:40:15 +0000 (11:40 +0100)]
Change-Id: Ibbbc056030f31ed70033574a401854ac0bd7fa8b

scilab/modules/sound/macros/savewave.sci
scilab/modules/sound/tests/nonreg_tests/bug_11860.dia.ref
scilab/modules/sound/tests/nonreg_tests/bug_11860.tst

index 355f322..ef951d3 100644 (file)
@@ -156,12 +156,19 @@ function savewave(filename,x,rate,nbits)
                 oct2 = (floor((data-(oct3*2^16))/(2^8)));
                 oct1 = (floor(data-(oct3*2^16)-(oct2*2^8)));//lsb
                 data_line = zeros(3*total_samples,1);
-                data_line(1:6:$) = oct1(1,:)';
-                data_line(2:6:$) = oct2(1,:)';
-                data_line(3:6:$) = oct3(1,:)';
-                data_line(4:6:$) = oct1(2,:)';
-                data_line(5:6:$) = oct2(2,:)';
-                data_line(6:6:$) = oct3(2,:)';
+                select channels
+                case 1
+                    data_line(1:3:$) = oct1(1,:)';
+                    data_line(2:3:$) = oct2(1,:)';
+                    data_line(3:3:$) = oct3(1,:)';
+                case 2
+                    data_line(1:6:$) = oct1(1,:)';
+                    data_line(2:6:$) = oct2(1,:)';
+                    data_line(3:6:$) = oct3(1,:)';
+                    data_line(4:6:$) = oct1(2,:)';
+                    data_line(5:6:$) = oct2(2,:)';
+                    data_line(6:6:$) = oct3(2,:)';
+                end
                 data_line = data_line';
             else
                 data_line = data;
index f65ae78..9f58fc3 100644 (file)
 // <-- Short Description -->
 // wavwrite failed for 24 bits files (error in savewave function)
 //
+// For two channels
 filename=SCI +'/modules/sound/tests/nonreg_tests/bug_11860.wav';
 [y_ref,Fs_ref,nbits_ref]=wavread(filename);
 wavwrite(y_ref,Fs_ref,nbits_ref,TMPDIR + '/bug_11860_written.wav');
 filename_written=TMPDIR + '/bug_11860_written.wav';
+// Check
 [y,Fs,nbits]=wavread(filename_written);
 assert_checktrue(abs(y_ref-y)<1e-6);
 assert_checkalmostequal(Fs,Fs_ref);
 assert_checkalmostequal(nbits,nbits_ref);
 mdelete(filename_written);
+// For 1 channel
+filepath= TMPDIR + '/bug_11860_mono.wav';
+Fs_ref = 44100;
+nbits_ref = 24;
+recordLength=1;
+t= soundsec(recordLength,Fs_ref);
+// Signal
+frequency = 1000;
+y_ref = 0.5*sin(2*%pi* frequency *t);
+// Output
+wavwrite(y_ref, Fs_ref, nbits_ref, filepath);
+// Check
+[y,Fs,nbits]=wavread(filepath);
+assert_checktrue(abs(y_ref-y)<1e-6);
+assert_checkalmostequal(Fs,Fs_ref);
+assert_checkalmostequal(nbits,nbits_ref);
+mdelete(filepath);
index f65ae78..ced3e38 100644 (file)
 // <-- Short Description -->
 // wavwrite failed for 24 bits files (error in savewave function)
 //
+// For two channels
 filename=SCI +'/modules/sound/tests/nonreg_tests/bug_11860.wav';
 [y_ref,Fs_ref,nbits_ref]=wavread(filename);
 wavwrite(y_ref,Fs_ref,nbits_ref,TMPDIR + '/bug_11860_written.wav');
 filename_written=TMPDIR + '/bug_11860_written.wav';
+// Check
 [y,Fs,nbits]=wavread(filename_written);
 assert_checktrue(abs(y_ref-y)<1e-6);
 assert_checkalmostequal(Fs,Fs_ref);
 assert_checkalmostequal(nbits,nbits_ref);
 mdelete(filename_written);
+
+// For 1 channel
+filepath= TMPDIR + '/bug_11860_mono.wav';
+Fs_ref = 44100;
+nbits_ref = 24;
+recordLength=1;
+t= soundsec(recordLength,Fs_ref);
+// Signal
+frequency = 1000;
+y_ref = 0.5*sin(2*%pi* frequency *t);
+// Output
+wavwrite(y_ref, Fs_ref, nbits_ref, filepath);
+// Check
+[y,Fs,nbits]=wavread(filepath);
+assert_checktrue(abs(y_ref-y)<1e-6);
+assert_checkalmostequal(Fs,Fs_ref);
+assert_checkalmostequal(nbits,nbits_ref);
+mdelete(filepath);