b@0: function playSound(snd) b@0: b@0: global soundID; b@0: b@0: if isempty(snd) % play no sound (= stop) by calling playSound([]) b@0: if ~isempty(soundID) b@0: stop(soundID); b@0: end b@0: b@0: else b@0: if isempty(snd.vect) % read sound (if ~DOWNLOAD) b@0: if isempty(snd.path) b@0: snd.path=cd; b@0: end b@0: b@0: [svect,sFs] = audioread([snd.path snd.name '.wav']); b@0: curSample = get(soundID,'CurrentSample'); b@0: if length(curSample)<1 % if empty vector (first time) b@0: curSample = 1; b@0: else if curSample > length(svect)-0.5*sFs % if near end b@0: curSample = 1; b@0: end b@0: end b@0: soundID = audioplayer(svect,sFs, 24); % 24 bit, default device b@0: stop(soundID); b@0: play(soundID, curSample); b@0: b@0: b@0: % CLEAN UP b@0: else b@0: curSample = get(soundID,'CurrentSample'); b@0: if length(curSample)<1 % if empty vector (first time) b@0: curSample = 1; b@0: else if curSample > length(snd.vect)-25000 % if near end b@0: curSample = 1; b@0: end b@0: end b@0: soundID = audioplayer(snd.vect,snd.fs, 24); % 24 bit, default device b@0: stop(soundID); b@0: play(soundID, curSample); b@0: end b@0: b@0: % TODO after this: button back to green? b@0: b@0: end