1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ???? - INRIA - Scilab
// Copyright (C) ???? - ENPC
// Copyright (C) 2009 - DIGITEO - Allan CORNET
//
// 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 [] = playsnd(y, rate, bits, aplay)
// play signal y at sample rate rate
// bits is unused
[lhs,rhs] = argn(0);
// default values
if (rhs <= 2) then
bits = 16;
end
if (rhs <= 1) then
rate = 22050;
end
if rhs > 2 then
if type(aplay) <> 10 then
error(msprintf(_("%s: Wrong type for input argument #%d: A string expected.\n"),"playsnd",3));
end
if size(aplay,"*") <> 1 then
error(msprintf(_("%s: Wrong size for input argument #%d: A string expected.\n"),"playsnd",3));
end
else
if rhs <= 3 then
if getos() == "Darwin" then
aplay = "afplay"
else
aplay = "aplay";
end
end
end
if getos() == "Windows" then
savewave(TMPDIR+"/_playsnd_.wav", y, rate);
PlaySound(TMPDIR+"/_playsnd_.wav");
return
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));
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
end
mput(lin2mu(y),"uc",fp);
mclose(fp);
end
end
endfunction
|