-
Notifications
You must be signed in to change notification settings - Fork 1
/
SoundServ.m
105 lines (93 loc) · 3.16 KB
/
SoundServ.m
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
classdef (Abstract) SoundServ < dynamicprops
%UNTITLED Summary of this class goes here
% Detailed explanation goes here
properties
SoundStruct = struct();
SF = 48000
end
properties (Access = protected)
latency = 'high';
sound_list = {};
num_sounds = 0;
synced = 0;
end
methods
function id = load(obj, name ,wav, varargin)
% to load sounds
obj.num_sounds = obj.num_sounds + 1;
[loop, varargin] = utils.inputordefault('loop',0,varargin);
[vol, varargin] = utils.inputordefault('volume',0.5,varargin);
[rep, varargin] = utils.inputordefault('repeation',1,varargin);
[bal, varargin] = utils.inputordefault('balance',0,varargin);
%soundid, sound wave, loop in a struct named sound name
%obj.SoundStruct = setfield(obj.SoundStruct,name,struct());
if size(wav,1)==1
wav = [wav;wav];
end
obj.SoundStruct.(name).soundid = obj.num_sounds-1;
obj.SoundStruct.(name).name = name;
obj.SoundStruct.(name).wave = wav;
obj.SoundStruct.(name).loop = loop;
obj.SoundStruct.(name).vol = vol;
obj.SoundStruct.(name).rep = rep;
obj.SoundStruct.(name).bal = bal;
obj.sound_list{1,obj.num_sounds} = name;
id = obj.num_sounds;
obj.synced = 0;
end
function id = GetSoundid(soundname,playORstop)
id = nan;
end
function ok = setLatency(obj,latency)
ok = true;
end
function isSuss = sync(obj)
% sync the sound between local and server
isSuss = 1;
end
function OK = startServ(obj)
% RPi start listening on the serial port
% leave this empty
OK = 1;
end
function OK = closeServ(obj)
% RPi start listening on the serial port
% leave this empty
OK = 1;
end
function closeConn(obj)
% close socket connection
% leave this empty
end
function SF = getSF(obj,val)
% get SF
global BpodSystem
if strcmp(BpodSystem.PluginObjects.SoundServerInfo,'PiSound')
SF = val;
obj.SF = val;
else
PsychToolboxSoundServer('init_ifnot');
SF = PsychToolboxSoundServer('getSF');
end
end
function SF = setSF(obj,val)
end
end
methods (Static = true)
function str = trigger(PlayorStop)
if nargin == 0
PlayorStop=[];
end
global BpodSystem
if strcmp(BpodSystem.PluginObjects.SoundServerInfo,'Rpi')
str = 'Serial1Code';
else
if strcmp(PlayorStop,'stop') || strcmp(PlayorStop,'Stop')
str = 'StopSound';
else
str = 'PlaySound';
end
end
end
end
end