0001 function sound = urbiGetSound(con,duration, deviceName)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if (nargin==2)
0013 deviceName='micro.val';
0014 end
0015
0016
0017
0018
0019 soundUnit = urbiGetSoundUnit(con,deviceName);
0020 nb_to_get = floor(duration / (soundUnit.duration));
0021
0022
0023
0024 ref_tag = 'gsnd_tag';
0025 urbiClearConnection(con,0);
0026 urbiSend(con, [ 'for(i=0;i<' num2str(nb_to_get) ';i++) gsnd_tag:' deviceName ';' ]);
0027
0028
0029 length = 0;
0030 samples = [];
0031
0032 for i=1:(nb_to_get)
0033
0034 o_tag = '';
0035 while ~strcmp (o_tag, ref_tag)
0036 r = pnet(con, 'readline', 'noblock');
0037 while isempty(r)
0038 r = pnet(con, 'readline', 'noblock');
0039 end;
0040 ans_string = strread (r, '%s');
0041 [timeStamp, o_tag] = strread(ans_string{1}, '[%u:%s]', 'whitespace', ']');
0042 o_tag = char(o_tag);
0043 end;
0044
0045
0046 length = length + str2num ( ans_string{3} );
0047
0048
0049 samples = [samples pnet(con, 'read', soundUnit.length) ];
0050
0051 end;
0052
0053
0054 duration = length/(soundUnit.Fs*soundUnit.channel*(soundUnit.nbits/8))*1000;
0055
0056
0057
0058 sound = struct('samples',samples,'Fs',soundUnit.Fs,'nbits', soundUnit.nbits, 'length', length, 'channel', soundUnit.channel, 'duration', duration);
0059
0060