Aufgrund einer Wartung wird GitLab am 29.10. zwischen 9:00 und 10:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 29.10. between 9:00 and 10:00 am.

Aufgrund einer Konfigurationsänderung wird die GitLab Registry ab 10 Uhr nur Read Only zur Verfügung stehen. / Due to a configuration change, the GitLab Registry will be available for read-only access from 10am.

ita_aurelio_control_old.m 9.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
function varargout = ita_aurelio_control(varargin)
%ITA_AURELIO_CONTROL - Send Settings to Aurelio 2014 Frontend
%  This function sends Midi Sysex Commands to the Aurelio High Precision
%  Frontend (Swen Mueller, Immetro, Rio de Janiero, Brazil).
%
%  Syntax: ita_aurelio_control(options)
%       'init' (false): set the frontend to last know values
%       'range' (0): inputRange as double, will round to nearest possible
%       'samplingRate' (ita_preferences), 32000, 44100 or 48000 multiplied by 1x, 2x, or 4x.
%       'coupling'
%
%   Reference page in Help browser
%        <a href="matlab:doc ita_robocontrol">doc ita_robocontrol</a>

% <ITA-Toolbox>
% This file is part of the application RoboAurelioModulITAControl for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>

% Author: Pascal Dietrich - pdi@akustik.rwth-aachen.de

%% persistent
persistent oldSettings last_input last_AmpHighPower last_Amplifier last_AmpBridgeMode last_AmpLowImpedanceMode last_Amp26dBu last_AmpAC last_AmpMono
% force_init = false;
if isempty(last_input)
    %     force_init = true;
    last_input = 'xlr';
    last_AmpHighPower = false;
    last_Amplifier = true;
    last_AmpBridgeMode = false;
    last_AmpLowImpedanceMode = false;
    last_Amp26dBu = false;
    last_AmpAC = false;
    last_AmpMono = false;
    oldSettings.ch(1).inputrange = 6;
    oldSettings.ch(2).inputrange = 6;
    oldSettings.ch(1).inputfeed = 'none';
    oldSettings.ch(2).inputfeed = 'none';
    oldSettings.ch(1).inputselect = 'xlr';
    oldSettings.ch(2).inputselect = 'xlr';
    
    oldSettings.amp_gain = -20;
end

if nargin == 0
    ita_aureliocontrol_gui();
end

%% init
sArgs     = struct('channel',1:2,'groundLift',true,'inputCouplingAC',true,'feed',oldSettings.ch(1).inputfeed,'inputrange',[],...
    'input',last_input,'mode','norm','securityMode',false,'init',false,'samplingRate',ita_preferences('samplingRate'),'outputvolume',[],...
    'AmpHighPower',last_AmpHighPower,'AmpLowPower',false,'Amplifier',last_Amplifier,'NoAmplifier',false,'AmpBridgeMode',last_AmpBridgeMode,'AmpLowImpedanceMode',last_AmpLowImpedanceMode,...
    'Amp26dBu',last_Amp26dBu,'Amp06dBu',false , 'NoGroundLift', false, 'AmpAC', last_AmpAC, 'AmpMono', last_AmpMono, 'getSettings',false,'reset',false);

%% parse
[sArgs]   = ita_parse_arguments(sArgs,varargin);
ch_number = ita_angle2str( sArgs.channel - 1, 2); %zero indexing for channel numbering

if sArgs.getSettings
    varargout{1} = oldSettings;
    return;
end

if sArgs.reset
    clear all
    ita_aurelio_control('init');
    if nargout == 1
        varargout{1} = [];
    end
    return;
end

%% inverse parameters
if sArgs.Amp06dBu
    sArgs.Amp26dBu = false;
end
if sArgs.NoAmplifier
    sArgs.Amplifier = false;
end
if sArgs.AmpLowPower
    sArgs.AmpHighPower = false;
end
if sArgs.NoGroundLift
    sArgs.groundLift = false;
    %     sArgs.feed = 'none';
end

%% write back to persistents
last_input          = sArgs.input;
last_AmpHighPower   = sArgs.AmpHighPower;
last_Amplifier      = sArgs.Amplifier;
last_AmpBridgeMode  = sArgs.AmpBridgeMode;
last_AmpLowImpedanceMode = sArgs.AmpLowImpedanceMode;
last_Amp26dBu       = sArgs.Amp26dBu;
last_AmpAC          = sArgs.AmpAC;
last_AmpMono        = sArgs.AmpMono;

%% INIT device
if sArgs.init
    % go thru all stages
    clear
    ita_aurelio_control('input','XLR','inputrange',6,'feed',0 , 'samplingRate',ita_preferences('samplingRate'));
    return
end

%% range
if ~isempty( sArgs.inputrange )
    sArgs.inputrange = min( max(sArgs.inputrange,-34) , 56);
    par_number = '02';
    par_value  = round((- sArgs.inputrange + 56)/10); %round to nearest possible
    for idx = 1:numel(sArgs.channel)
        oldSettings.ch(sArgs.channel(idx)).inputrange = 56 - (par_value * 10);
    end
    if sArgs.securityMode
        par_value  = par_value + 40;
    end
    par_value = ita_angle2str(par_value,2);
    send_sysex(par_number, par_value, ch_number); %send to device
end

%% input select -- routing control -- HUHU old values needed
if ~isempty(sArgs.input)
    par_number = '01';
    switch lower(sArgs.mode)
        case 'norm' %normal mode
            Mode = '0000';
        case 'imp' %impedance measurement
            Mode = '0001';
            sArgs.feed = false;
            %             ChSwp = '1'; % pdi: oct 2012: for some reason
            %             this is not required anymore ???!!!
        case {'impref','iref'}
            Mode = '0010';
            sArgs.feed = false;
        case {'bncref','bref'}
            Mode = '0100';
            sArgs.input = 'gnd';
            sArgs.feed = false;
        case {'ampref','aref'}
            Mode = '0101';
            sArgs.input = 'gnd';
            sArgs.feed = false;
        case {'xlrref','xref','lineref'}
            Mode = '0011';
            sArgs.feed = false;
        case 'specialref'
            Mode = ['010' num2str(~ch_number) ];
            sArgs.input = 'gnd';
        otherwise
            error('argument not correct for ''input''')
    end
    
    if ~exist('ChSwp','var')
        ChSwp = '0'; %funny channel swapping for crazy people. take care, dude!
    else
        ita_verbose_info('Careful, channel swapping is activated.',0)
    end
    
    switch lower(sArgs.input)
        case 'xlr'
            IS = '11';
        case 'lemo'
            IS = '01';
            sArgs.feed = 'pol';
        case 'gnd'
            IS = '00';
        case 'bnc'
            IS = '10';
        otherwise
            error(['input select unknown: ' sArgs.input])
    end
    par_value = dec2hex( bin2dec( [IS ChSwp Mode ] ) );
    send_sysex(par_number, par_value, ch_number); %send to device
    
    for iCh = 1:numel(sArgs.channel)
        oldSettings.ch(sArgs.channel(iCh)).inputselect = lower(sArgs.input);
    end
end

%% coupling and feed control
if ~isempty( sArgs.feed )
    par_number = '00';
    Wait  = '0'; %wait for relays to switch later
    Lem28 = '0'; %switch 14 to 28Volts, Pin7 is then grounded
    Phan  = '0';
    Feed  = '0';
    ICP   = '0';
    Glift = num2str(sArgs.groundLift);
    AC    = num2str(sArgs.inputCouplingAC);
    
    switch lower(sArgs.feed)
        case 'pha'
            Phan = '1';
            AC   = '1'; %block DC from preamp inputs
        case 'pol'
            Feed = '1';
            AC   = '1'; %block DC from preamp inputs
        case {'icp','iepe'}
            ICP  = '1';
            Feed = '1';
            AC   = '1';
        case 'p+p'
            Phan = '1';
            Feed = '1';
            AC   = '1';
        case 'all'
            Phan = '1';
            Feed = '1';
            ICP  = '1';
            AC   = '1';
        case 'ccx'
            Phan = '0';
            Feed = '0';
            ICP  = '0';
            AC   = '0';
            Glift = '1';
        case {0 ,'none','off'}
            %
        otherwise
            error('feed wrong')
    end
    par_value  = dec2hex( bin2dec ( ['0' Wait Lem28 Phan Feed ICP Glift AC] ));
    send_sysex(par_number, par_value, ch_number); % send final sysex
    
    for iCh = 1:numel(sArgs.channel)
        oldSettings.ch(sArgs.channel(iCh)).inputfeed = lower(sArgs.feed);
    end
end

%% sampling rate
if sArgs.samplingRate
    par_number = '03';
    
    if isnatural(sArgs.samplingRate / 48000)
        modifier  = (sArgs.samplingRate / 48000);
        base_rate = 2;
    elseif isnatural(sArgs.samplingRate / 44100)
        modifier  = sArgs.samplingRate / 44100;
        base_rate = 1;
    elseif isnatural(sArgs.samplingRate / 32000)
        modifier  = sArgs.samplingRate / 32000;
        base_rate = 0;
    else
        error('sampling rate not supported.')
    end
    switch modifier
        case 1
            modifier = 0;
        case 2
            modifier = 1;
        case 4
            modifier = 2;
        otherwise
            error('sampling rate not supported.')
    end
    par_value  =  dec2hex(modifier*4 + base_rate);
    send_sysex(par_number, par_value, []); % send final sysex
    
    ita_preferences('samplingRate',sArgs.samplingRate); % also initializes playrec
end



%% analog output control - Parameter 05
HiPow   = num2str(sArgs.AmpHighPower);
AmpOn   = num2str(sArgs.Amplifier);
Bridge  = num2str(sArgs.AmpBridgeMode);
LoImp   = num2str(sArgs.AmpLowImpedanceMode);
dBu26   = num2str(sArgs.Amp26dBu);
AC      = num2str(sArgs.AmpAC);
mono    = num2str(sArgs.AmpMono);

par_number = '05';
par_value  = dec2hex(bin2dec(['0' HiPow AmpOn Bridge LoImp dBu26 AC mono])); % 0dB attenuation
send_sysex(par_number, par_value, ch_number); %send to device

if sArgs.Amp06dBu
    oldSettings.amp_gain = -20;
elseif sArgs.Amp26dBu
    oldSettings.amp_gain = 0;
end


%% output volume - Parameter 06
% if ~isempty( sArgs.outputvolume )
%     par_number = '06';
%     par_value  = '7F'; % 0dB attenuation
%     send_sysex(par_number, '0', []); %send to device
% end




end

%% **********************  send sysex  ************************************
function send_sysex(par_number, par_value, ch_number)
if ~isempty(ch_number) && numel(str2num(ch_number)) >= 2
    ch_number = '7F';
end
%build complete sysex
sys_hex = {};
sys_hex{numel(sys_hex)+1} = par_number; % hex
sys_hex{numel(sys_hex)+1} = par_value;  % hex
if ~isempty(ch_number)
    sys_hex{numel(sys_hex)+1} = ch_number;  % hex
end

for idx = 1:numel(sys_hex)
    sys_dec(idx) = hex2dec( sys_hex{idx} );
end

% generate checksum
checksum = sum(sys_dec);
checksum = bin2dec(num2str(mod(str2double(dec2bin(checksum)), 10000000)));
complete_sysex = [sys_dec checksum];

%send sysex
sysex = [hex2dec('F0') hex2dec('70') complete_sysex hex2dec('F7')]; %pre- post- ampel
ita_midi(sysex,ita_preferences('out_midi_DeviceID'));

end