0001 function ChangeBinaryGain(filename,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 nChannels = 1;
0032 precision = 'int16';
0033 skip = 0;
0034 gains = [];
0035 output = [filename '-gains'];
0036
0037 if nargin < 1 | mod(length(varargin),2) ~= 0,
0038 error('Incorrect number of parameters (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0039 end
0040
0041
0042 for i = 1:2:length(varargin),
0043 if ~ischar(varargin{i}),
0044 error(['Parameter ' num2str(i+3) ' is not a property (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).']);
0045 end
0046 switch(lower(varargin{i})),
0047 case 'output',
0048 output = varargin{i+1};
0049 if ~isastring(output),
0050 error('Incorrect value for property ''output'' (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0051 end
0052 case 'nchannels',
0053 nChannels = varargin{i+1};
0054 if ~isiscalar(nChannels,'>0'),
0055 error('Incorrect value for property ''nChannels'' (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0056 end
0057 case 'gains',
0058 gains = varargin{i+1};
0059 if ~isdvector(gains,'>=0'),
0060 error('Incorrect value for property ''gains'' (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0061 end
0062 case 'precision',
0063 precision = varargin{i+1};
0064 if ~isastring(precision),
0065 error('Incorrect value for property ''precision'' (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0066 end
0067 case 'skip',
0068 skip = varargin{i+1};
0069 if ~isiscalar(skip,'>=0'),
0070 error('Incorrect value for property ''skip'' (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0071 end
0072 otherwise,
0073 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).']);
0074 end
0075 end
0076
0077
0078 f = fopen(output,'r');
0079 if f ~= -1,
0080 error(['Output file ''' output ''' exists.']);
0081 end
0082
0083
0084 gains = gains(:)';
0085 nGains = length(gains);
0086 if nGains == 1,
0087 gains = repmat(gains,1,nChannels);
0088 nGains = nChannels;
0089 elseif nGains ~= nChannels,
0090 error('Incorrect number of gains (type ''help <a href="matlab:help ChangeBinaryGain">ChangeBinaryGain</a>'' for details).');
0091 end
0092
0093
0094 offset = 0;
0095 nSamples = floor(100000/nChannels);
0096 while true,
0097 data = LoadBinary(filename,'nChannels',nChannels,'offset',offset,'samples',nSamples,'precision',precision,'skip',skip);
0098 data = data .* repmat(gains,size(data,1),1);
0099 SaveBinary(output,data,'precision',precision,'mode','append');
0100 offset = offset + nSamples;
0101 if size(data,1) < nSamples, break; end
0102 end