# MATLAB freezes after playing audio file

**URL:** <https://psychtoolbox.discourse.group/t/matlab-freezes-after-playing-audio-file/1665>\
**Category:** Uncategorized\
**Created:** [May 20, 2008, 5:22pm UTC](https://psychtoolbox.discourse.group/t/matlab-freezes-after-playing-audio-file/1665 "2008-05-20T17:22:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [May 20, 2008, 5:22pm UTC](https://psychtoolbox.discourse.group/t/matlab-freezes-after-playing-audio-file/1665/1 "2008-05-20T17:22:22Z")

</div>

I have a problem with this PsyhPortAudio. I'm running on MAC10.5 Could that be the   
problem? The problem persist even when I run it on MAC10.4. After installing it and   
adding it to the library, I tried to play this audio sound with commands below. But every   
time it plays it, MATLAB freezes and won't do anything. Could someone help me out on   
this?  
  
Thanks  
  
MATLAB commands to play audio file.  
Got this file from [http://faculty.washington.edu/ionefine/html/Sound.html#3](http://faculty.washington.edu/ionefine/html/Sound.html#3)  
  
  
load handel;  
nrchannels = 1; % One channel only -\> Mono sound.  
freq = Fs; % Fs is the correct playback frequency for handel.  
wavedata = y'; % Need sound vector as row vector, one row per channel.  
repetitions=1;  
  
% Perform basic initialization of the sound driver:  
InitializePsychSound;  
  
% Open the default audio device [], with default mode [] (==Only playback),  
% and a required latencyclass of zero 0 == no low-latency mode, as well as  
% a frequency of freq and nrchannels sound channels.  
% This returns a handle to the audio device:  
pahandle = PsychPortAudio('Open', [], [], 0, freq, nrchannels);  
  
% Fill the audio playback buffer with the audio data 'wavedata':  
PsychPortAudio('FillBuffer', pahandle, wavedata);  
  
% Start audio playback for 'repetitions' repetitions of the sound data,  
% start it immediately (0) and wait for the playback to start, return onset  
% timestamp.  
t1 = PsychPortAudio('Start', pahandle, repetitions, 0, 1);  
  
% Wait for release of all keys on keyboard:  
while KbCheck; end;  
  
disp('Audio playback started, press any key for about 1 second to quit.');  
  
% Stay in a little loop until keypress:  
while ~KbCheck  
% s = PsychPortAudio('GetStatus', pahandle);  
end  
  
% Stop playback:  
PsychPortAudio('Stop', pahandle);  
  
% Close the audio device:  
PsychPortAudio('Close', pahandle);  
  
% Done.  
disp('Demo finished, bye!');
