Mercurial > hg > ape
annotate listeningTest/playSound.m @ 15:24be5e9ce25b tip
Update README
author | Brecht De Man <brecht.deman@bcu.ac.uk> |
---|---|
date | Thu, 20 Sep 2018 12:23:20 +0200 |
parents | 4fd284285159 |
children |
rev | line source |
---|---|
b@0 | 1 function playSound(snd) |
b@0 | 2 |
b@0 | 3 global soundID; |
b@0 | 4 |
b@0 | 5 if isempty(snd) % play no sound (= stop) by calling playSound([]) |
b@0 | 6 if ~isempty(soundID) |
b@0 | 7 stop(soundID); |
b@0 | 8 end |
b@0 | 9 |
b@0 | 10 else |
b@0 | 11 if isempty(snd.vect) % read sound (if ~DOWNLOAD) |
b@0 | 12 if isempty(snd.path) |
b@0 | 13 snd.path=cd; |
b@0 | 14 end |
b@0 | 15 |
b@0 | 16 [svect,sFs] = audioread([snd.path snd.name '.wav']); |
b@0 | 17 curSample = get(soundID,'CurrentSample'); |
b@0 | 18 if length(curSample)<1 % if empty vector (first time) |
b@0 | 19 curSample = 1; |
b@0 | 20 else if curSample > length(svect)-0.5*sFs % if near end |
b@0 | 21 curSample = 1; |
b@0 | 22 end |
b@0 | 23 end |
b@0 | 24 soundID = audioplayer(svect,sFs, 24); % 24 bit, default device |
b@0 | 25 stop(soundID); |
b@0 | 26 play(soundID, curSample); |
b@0 | 27 |
b@0 | 28 |
b@0 | 29 % CLEAN UP |
b@0 | 30 else |
b@0 | 31 curSample = get(soundID,'CurrentSample'); |
b@0 | 32 if length(curSample)<1 % if empty vector (first time) |
b@0 | 33 curSample = 1; |
b@0 | 34 else if curSample > length(snd.vect)-25000 % if near end |
b@0 | 35 curSample = 1; |
b@0 | 36 end |
b@0 | 37 end |
b@0 | 38 soundID = audioplayer(snd.vect,snd.fs, 24); % 24 bit, default device |
b@0 | 39 stop(soundID); |
b@0 | 40 play(soundID, curSample); |
b@0 | 41 end |
b@0 | 42 |
b@0 | 43 % TODO after this: button back to green? |
b@0 | 44 |
b@0 | 45 end |