Skip to content

Commit

Permalink
Numerous bug fixes and modifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswbishop committed May 23, 2014
1 parent 9a993cf commit ea6bb4f
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 27 deletions.
2 changes: 1 addition & 1 deletion HINT_GUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function HINT_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
end % d=1:max_words

% Set domain
xlim([1 p.ntrials]);
xlim([0 p.ntrials+1]);

%% ADD WORDS AND SCORING PANELS
% Add words to figure and enable scoring panels
Expand Down
9 changes: 5 additions & 4 deletions SIN_TestSetup.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@
opts.player.stop_if_error = true;

% Add player control modifiers
% pausePlayback allows user to pause playback if he wants to.
% Include a basic playback controller to handle "pauses",
% "resume", and "quit" requests.
opts.player.modifier{1} = struct( ...
'fhandle', @modifier_pausePlayback);
'fhandle', @modifier_PlaybackControl);

case 'HINT (SNR-50)'

Expand Down Expand Up @@ -240,7 +241,7 @@
% longer for longer files (due to indexing overhead)
%
% ============================
opts.player.playback.block_dur=0.3;
% opts.player.playback.block_dur=0.3;

% ============================
% Player configuration
Expand Down Expand Up @@ -289,7 +290,7 @@
'fhandle', @modifier_dBscale, ... % use a decibel scale
'dBstep', 5, ... % use constant 1 dB steps
'change_step', 1, ... % always 1 dB
'channels', 2); % apply modification to channel 2
'channels', 1); % apply modification to channel 2

otherwise

Expand Down
69 changes: 69 additions & 0 deletions modifier_PlaybackControl.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function [Y, d]=modifier_PlaybackControl(X, mod_code, varargin)
%% DESCRIPTION:
%
% Function designed to handle basic playback control requests. At time of
% writing, this includes "pause", "run/resume", and "exit/quit".
%
% INPUT:
%
% X: time series
%
% mod_code: modification code. Will respond to codes 99 (pause), 100
% (resume), and 86 (quit). All other codes have no effect.
%
% OUTPUT:
%
% Y: zeroed time series
%
% d: altered data structure with player state set to 'pause'.
%
% Christopher W. Bishop
% University of Washington
% 5/14

d=varargin2struct(varargin{:});

% The player is made to work with a "SIN" style structure. If the user has
% defined inputs just at the commandline, then reassign to make it
% compatible.
if ~isfield(d, 'player')
d.player = d;
end % if

%% GET IMPORTANT VARIABLES FROM SANDBOX
% trial = d.sandbox.trial;
modifier_num=d.sandbox.modifier_num;

%% INITIALIZATION
if ~isfield(d.player.modifier{modifier_num}, 'initialized') || isempty(d.player.modifier{modifier_num}.initialized), d.player.modifier{modifier_num}.initialized=false; end

if ~d.player.modifier{modifier_num}.initialized

% Set the initialization flag
d.player.modifier{modifier_num}.initialized=true;

% To be safe, assign input to output.
Y=X;
return
end % if ~d.player.modifier{modifier_num}.initialized

% Switch to change state of player
switch mod_code
case {86}
d.player.state='exit';
case {99}
% % pause code
d.player.state='pause';
case {100}
d.player.state='run';
otherwise

end % switch

% State actions
switch d.player.state
case {'pause' 'exit'}
Y=zeros(size(X));
otherwise
Y=X;
end % switch
23 changes: 21 additions & 2 deletions modifier_dBscale.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
% portaudio_adaptiveplay (that is, always applying operations to the
% original signal (X)) first.
%
% 6. Should change flow so sounds are always scaled to the most recent
% scaling factor, not matter the code.
%
% Christopher W. Bishop
% University of Washington
% 5/14
Expand Down Expand Up @@ -107,6 +110,8 @@
%% GET APPROPRIATE STEP SIZE
dBstep=d.player.modifier{modifier_num}.dBstep(find(d.player.modifier{modifier_num}.change_step <= trial, 1, 'last'));

channels=d.player.modifier{modifier_num}.channels;

%% WHAT TO DO?
% What do we do if no mod_code is provided?
if ~isempty(mod_code)
Expand All @@ -117,8 +122,6 @@
dBstep = mod_code*dBstep;

%% SCALE TIME SERIES
channels=d.player.modifier{modifier_num}.channels;

% Assign X to Y.
Y=X;

Expand Down Expand Up @@ -149,6 +152,22 @@
d.sandbox.xdata=1:length(d.sandbox.xdata)+1; % xdata (call #)
d.sandbox.ydata(end+1)=d.player.modifier{modifier_num}.history(end);

case {100}
% This is the modification code (mod_code) sent by
% ANL_modcheck_keypress when playback is "resumed" after a
% pause. CWB noticed that the sounds are not scaled
% appropriately when playback is resumed. This is meant to fix
% that.

% Copy over input data
Y=X;

% Grab the most recent scaling factor applied.
sc = db2amp(d.player.modifier{modifier_num}.history(end));

% Apply scaling factor to the appropriate channels.
Y(:, channels)=Y(:, channels).*sc;

otherwise
% We don't want to throw an error because sometimes other
% mod_codes will be passed around that other modifiers know
Expand Down
5 changes: 1 addition & 4 deletions modifier_pausePlayback.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@
d.player.state='exit';
case {99}
% % pause code
% Y = zeros(size(X));
d.player.state='pause';
case {100}
d.player.state='run';
otherwise
% If we don't have anything to do, then just spit back the original
% time series
Y=X;

end % switch

% State actions
Expand Down
36 changes: 20 additions & 16 deletions portaudio_adaptiveplay.m
Original file line number Diff line number Diff line change
Expand Up @@ -643,19 +643,6 @@
% ANL_modcheck_keypress)
d.sandbox.nblocks=nblocks;

% Data mask
% This is a circular mask used as a logical index of the
% playback data (from stim{trial}, stored in X/Y). We load in
% a full buffer worth of data (two "blocks"). This is
% necessary for fading in/out upon subsequent iterations of
% block_num
%
% CWB tried to use a circularly shifted mask, but it ended up
% being slower for longer sounds (not surprising in
% hindsight). CWB wants indexing that works equally well for
% sounds of all sizes.
% mask=[true(buffer_nsamps, 1); false(size(Y,1)-buffer_nsamps, 1)];

% initiate block_num
block_num=1;

Expand Down Expand Up @@ -880,19 +867,36 @@

end % d.player.record_mic

% Increment block count
block_num=block_num+1;
% Only increment block information if the sound is still
% being played.
if isequal(d.player.state, 'run')

% Increment block count
block_num=block_num+1;

end % if isequal ...

% Clear mod_code
% Important if playback is paused for any reason. Do not
% want the mod_code applying to the same sound twice.
clear mod_code;

% If player state is in 'exit', then stop all playback and
% return variables
if isequal(d.player.state, 'exit')
break;
end %
end % while
% end % for block_num=1:nblocks

% Schedule stop of playback device.
% Should wait for scheduled sound to complete playback.
PsychPortAudio('Stop', phand, 1);
if isequal(d.player.state, 'run')
PsychPortAudio('Stop', phand, 1);
elseif isequal(d.player.state, 'exit')
PsychPortAudio('Stop', phand, 0);
break;
end % if isequal ...

% Stop unmodulated noise
if isequal(d.player.unmod_playbackmode, 'stopafter')
Expand Down

0 comments on commit ea6bb4f

Please sign in to comment.