Hi Mario,
It sounds like I am using the port wrong then? Am I opening up (in this example) 5 audio devices? I haven't tested it with more than 5 yet as I assummed it would work. Have I done this right?
Also, I really need to be able to specify a Left channel (monaural presentations) for 1 wave file and right channel for another wave file. How do I do this please?
I am running on a mac, but I can run using a PC. Although when I ran the same code I have on the mac on the PC it wouldn't run and had heaps of errors, so if I can get the mac to do monaural presentation that would be alot easier!
Many thanks, I greatly appreciate the help of the forum!
Regards,
Vanessa
clear all;
n=5; % number of trials/files you have
%-------------------------------------
% Text files Set up: Sentences & Wavefile names
%-------------------------------------
fidTxt = fopen('5HintSent.txt');
Sent = textscan(fidTxt, '%s', 'delimiter', ';'); % need fopen to use textscan, reads array of strings with the delimiter ; as the end of the cell
fidWaveTxtH = fopen('WaveHfiles.txt');
WavesH = textscan(fidWaveTxtH, '%s', 'delimiter', ';'); % need fopen to use textscan, reads array of strings with the delimiter ; as the end of the cell
fidWaveTxtL = fopen('WaveLfiles.txt');
WavesL = textscan(fidWaveTxtL, '%s', 'delimiter', ';');
%-------------------------------------
% Actual Wavefiles
%-------------------------------------
cd Hwav;
c = 0;
files = dir('*wav');
for c=1:length(files);
[y{c}, freqH{c}]= wavread([WavesH{1,1}{c,1}]);
[WavesH{1,1}{c,1}] = y{c}';
[nrchannelsH{1,1}{c,1}] = size([WavesH{1,1}{c,1}],1);
end
cd ..;
cd Lwav;
c = 0;
files = dir('*wav');
for c=1:length(files);
[y{c}, freqL{c}]= wavread([WavesL{1,1}{c,1}]);
[WavesL{1,1}{c,1}] = y{c}';
[nrchannelsL{1,1}{c,1}] = size([WavesL{1,1}{c,1}],1);
end
cd ..;
%-------------------------------------
% Randomisation
%-------------------------------------
TOrder = randperm(n); % array works TOrder 1 2 3 4 5 goes to e.g: 5 4 3 1 2 to call see below [TOrder(1,c)] where c is the counter
% e.g. if you call [TOrder(1,2)] it will give you 4 in this particular example; [TOrder(1,4)] = 1
%-------------------------------------
% Initialisation of sound driver
%-------------------------------------
% you need to download Psychtoolbox which must have psychportaudio
InitializePsychSound(1);
c = 0;
for c = 1:n;
[pahandleH{1,1}{c,1}] = PsychPortAudio('Open', [], [], 1, freqH{c}, [nrchannelsH{1,1}{c,1}]);
[pahandleL{1,1}{c,1}] = PsychPortAudio('Open', [], [], 1, freqL{c}, [nrchannelsL{1,1}{c,1}]);
PsychPortAudio('FillBuffer', [pahandleH{1,1}{c,1}], [WavesH{1,1}{c,1}]);
PsychPortAudio('FillBuffer', [pahandleL{1,1}{c,1}], [WavesL{1,1}{c,1}]);
end
%-------------------------------------
% Main Experiment
%-------------------------------------
c = 0;
for c = 1:n
H1 = PsychPortAudio('Start', [pahandleH{1,1}{[TOrder(1,c)],1}], 1, 0, 1); % play the High freq wave files
L1 = PsychPortAudio('Start', [pahandleL{1,1}{[TOrder(1,c)],1}], 1, 0, 1); % play the low freq wave files
disp(Sent{1,1}{[TOrder(1,c)],1}) % display the sentence
Resp = input('Response or ~ to escape: ','s') % get sub response
RespStore(c) = cellstr(Resp);
RespStore2 = char(RespStore(c)); % change the response to check for ~ quit key here
if (RespStore2) == ('~')
break;
end
PsychPortAudio('Stop', [pahandleH{1,1}{[TOrder(1,c)],1}], 1);
PsychPortAudio('Stop', [pahandleL{1,1}{[TOrder(1,c)],1}], 1);
end
%-------------------------------------
% Close devices and screens
%-------------------------------------
c = 0;
for c = 1:n
PsychPortAudio('Close', [pahandleH{1,1}{c,1}]);
PsychPortAudio('Close', [pahandleL{1,1}{c,1}]);
end
Screen('CloseAll');
--- In psychtoolbox@yahoogroups.com, "Mario Kleiner" <mario.kleiner@...> wrote:
>
> Hi,
>
> one more tip: You should not open one audio device for
> each wavfile. That will not work, because we have a limit
> of about 10 open devices (or maybe 100, can't remember),
> as this consumes a lot of system ressources. Some operating
> systems don't even allow opening multiple devices, so your
> code becomes non-portable. The idea is to have 1 open
> PsychPortAuido device for each real soundcard in your system.
>
> Instead you'd read the wavfiles into a cell array or similar,
> as suggested. In your trial loop at the start of each trial you'd
> PsychPortAudio('FillBuffer', ...); that specific cell array entry
> into the sound buffer of your single open audio device.
>
> This is fast enough for most purposes. We have more
> elaborate ways if if isn't an option. An upcoming PsychPortAudio
> release will also have a new function that allows to have
> multiple predefined soundbuffers.
>
> best,
> -mario
>
>
> --- In psychtoolbox@yahoogroups.com, "vlimhamm" <vlim003@> wrote:
> >
> > Hi,
> > I am trying to read in multiple wav files (2 channels separately but simultaneously),
> > randomise them and play them back.
> >
> > I can play 2 files which seem simultaneous
> > wavfilename1 = 'files1H.wav';
> > [y, freqH]= wavread(wavfilename1);
> > wavedataH = y';
> > nrchannelsH = size(wavedataH,1);
> > wavfilename2 = 'files1L.wav';
> > [y, freqL]= wavread(wavfilename2);
> > wavedataL = y';
> > nrchannelsL = size(wavedataL,1);
> > pahandleH = PsychPortAudio('Open', [], [], 1, freqH, nrchannelsH);
> > pahandleL = PsychPortAudio('Open', [], [], 1, freqL, nrchannelsL);
> > PsychPortAudio('FillBuffer', pahandleH, wavedataH );
> > PsychPortAudio('FillBuffer', pahandleL, wavedataL );
> > H1 = PsychPortAudio('Start', pahandleH, 1, 0, 1);
> > L1 = PsychPortAudio('Start', pahandleL, 1, 0, 1);
> > close etc.
> >
> > But I have 400 files that I need to read in (200 in left and 200 in the right channels) so I
> > can't "hard" code this.
> >
> > I tried below but this doesn't work - where the wavefile names have been read in from a
> > text file
> > wavfilename(n) = WavesH(n);
> > [y(n), freqH(n)]= wavread(wavfilename(n));
> > wavedataH(n) = y(n)';
> > nrchannelsH(n) = size(wavedataH(n),1);
> >
> > Ideally it would be great to read them into an array, randomise and then call them when
> > needed.
> >
> > Sorry, I'm new to matlab and psychtoolbox, after years of turbo pascal, technology has
> > moved along, so must I....
> > Many thanks,
> > Vanessa
> >
>