Skip to content

Commit d96fda2

Browse files
marcobarilariRemi-Gau
authored andcommitted
add stand alone function to get the sound devise id
1 parent ead1d8c commit d96fda2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/utils/ptb_soundDevice_test.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
sca
2+
clear
3+
clc
4+
% PsychPortAudio('Close');
5+
6+
cfg.audio.playbackMode = 1;
7+
cfg.audio.channels = 2;
8+
cfg.audio.requestedLatency = 3;
9+
10+
InitializePsychSound(1);
11+
audioDev = PsychPortAudio('GetDevices');
12+
13+
% tmp = [2 3 9];
14+
15+
for idx = 10
16+
17+
fprintf(1, '\n%i: %s\n', idx, audioDev(idx).DeviceName);
18+
19+
cfg.audio.devIdx = audioDev(idx).DeviceIndex;
20+
21+
% get device's sampling rate
22+
cfg.audio.fs = audioDev(idx).DefaultSampleRate;
23+
24+
try
25+
cfg.audio.pahandle = PsychPortAudio('Open', ...
26+
cfg.audio.devIdx, ...
27+
cfg.audio.playbackMode, ...
28+
cfg.audio.requestedLatency, ...
29+
cfg.audio.fs, ...
30+
cfg.audio.channels);
31+
32+
clear sound
33+
sound = rand(cfg.audio.channels, cfg.audio.fs);
34+
35+
PsychPortAudio('FillBuffer', cfg.audio.pahandle, sound);
36+
PsychPortAudio('Start', cfg.audio.pahandle);
37+
38+
WaitSecs(1.5);
39+
40+
PsychPortAudio('Close');
41+
42+
WaitSecs(1);
43+
catch
44+
end
45+
46+
pressSpaceForMe
47+
48+
end

0 commit comments

Comments
 (0)