summaryrefslogtreecommitdiff
path: root/modules/sound/macros/lin2mu.sci
diff options
context:
space:
mode:
Diffstat (limited to 'modules/sound/macros/lin2mu.sci')
-rwxr-xr-xmodules/sound/macros/lin2mu.sci23
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/sound/macros/lin2mu.sci b/modules/sound/macros/lin2mu.sci
new file mode 100755
index 000000000..c0365d436
--- /dev/null
+++ b/modules/sound/macros/lin2mu.sci
@@ -0,0 +1,23 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) ???? - INRIA - Scilab
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+
+function [mu]=lin2mu(y)
+ //Utility fct: converts linear signal to mu-law encoding.
+ // mu = lin2mu(y) converts linear audio signal amplitudes
+ // in the range -1 <= y <= 1 to mu-law in the range 0 <= mu <= 255.
+ SCALE = 32768;
+ BIAS = 132;
+ CLIP = 32635;
+ OFFSET = 335;
+ y = SCALE*y;
+ sig = sign(y)+bool2s(y==0);
+ y = min(abs(y),CLIP);
+ [f,e] = frexp(y+BIAS);
+ mu = 64*sig-16*e-fix(32*f)+OFFSET;
+endfunction