Commit 7371ed2c authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen

Fixing merge problem for exception in channel determiniation of daff export

parents 72d6ee33 9f3e66ff
......@@ -432,6 +432,25 @@ classdef itaHRTF < itaAudio
end
end
% Proceed (version independent)
names=fieldnames(tempMetadata);
for k=1:(numel(names))
switch class(tempMetadata.(names{k}))
case 'logical'
datatype='bool';
case 'char'
datatype='string';
case 'double'
if rem(tempMetadata.(names{k}),1)==0
datatype='int';
else
datatype='float';
end
case 'int32'
datatype='int';
end
metadata=daffv17_add_metadata(metadata,cell2mat(names(k)),datatype,tempMetadata.(names{k}));
end
phiM = coordDaff(:,1)*pi/180;
%phiM = mod(coordDaff(:,1),360)*pi/180;
......@@ -668,6 +687,14 @@ classdef itaHRTF < itaAudio
end
function obj = direction(this, idxCoord)
%return the HRTF (L&R) for a/multiple given direction indices
% hOut = hObj.direction(idxCoord)
%
% idxCoord: index of the direction in hObj.dirCoord
%
% hOut: HRTF in given direction
%
% see also: hObj.findnearestHRTF
idxDir = zeros(numel(idxCoord)*2,1);
idxDir(1:2:numel(idxCoord)*2,:) = 2*idxCoord-1;
idxDir(idxDir==0)=1;
......@@ -694,11 +721,11 @@ classdef itaHRTF < itaAudio
end
function thetaUni = theta_UniqueDeg(this,varargin)
thetaUni = rad2deg(theta_Unique(this,varargin));
thetaUni = rad2deg(theta_Unique(this,varargin{:}));
end
function phiUni = phi_UniqueDeg(this,varargin)
phiUni = rad2deg(phi_Unique(this,varargin));
phiUni = rad2deg(phi_Unique(this,varargin{:}));
end
function slice = sphericalSlice(this,dirID,dir_deg,exactSearch)
......@@ -1315,8 +1342,12 @@ classdef itaHRTF < itaAudio
[this,sArgs]= ita_parse_arguments(sArgs,varargin);
ah = sArgs.axes_handle;
phiC_deg = rad2deg(unique(round(this.phi_Unique*100)/100));
thetaC_deg = rad2deg(unique(round(this.theta_Unique*100)/100));
phiC_deg = uniquetol(round(this.phi_UniqueDeg,1),0.05);
thetaC_deg = uniquetol(round(this.theta_UniqueDeg,1),0.05);
%hbr: changed to round to 1 decimal in deg, seems more stable
%phiC_deg = rad2deg(unique(round(this.phi_Unique*100)/100));
%thetaC_deg = rad2deg(unique(round(this.theta_Unique*100)/100));
% create slice
if numel(thetaC_deg)>1 && numel( phiC_deg)>1
......
......@@ -26,8 +26,8 @@ end
% errors
newCoordinates.r = mean(oldCoords.r);
oldCoords = oldCoords.build_search_database;
% don't use the mex file to make use of bugfix as poles
% oldCoords = oldCoords.build_search_database;
newIndex = oldCoords.findnearest(newCoordinates);
......@@ -39,7 +39,7 @@ newSamplingDistance = getVectorLength(newCoordinates.n(1),newCoordinates.n(2));
% the maximum of the found points should always be smaller
if max(pointDistances) > newSamplingDistance
error('The found points are further apart than the sampling allows. Something is wrong')
ita_verbose_info('The found points are further apart than the sampling allows. Something is wrong',0)
end
......
......@@ -141,9 +141,12 @@ end
%% Channels
channels=this.nChannels/this.nDirections;
if( channels < 1 || mod( channels, 2 ) ~= 0 )
if( channels < 1 )
warning('Number of channels per record was not detected correctly, assuming 2 channel records');
channels = 2;
elseif( mod( channels, 2 ) ~= 0 )
warning( [ 'Number of channels per record was not and integer number, trying floor() of ' num2str( channels ) ] );
channels = floor( channels );
end
daff_write_args.channels = channels;
......
......@@ -13,7 +13,7 @@ classdef itaMotorNanotec_Arm < itaMotorNanotec
end
properties
horizontalCorrectionFactor = 0;
end
properties(Constant, Hidden = true)
......@@ -224,14 +224,14 @@ classdef itaMotorNanotec_Arm < itaMotorNanotec
return;
end
if (angle < this.ARM_limit(1)) || (angle > this.ARM_limit(2))
ita_verbose_info(['Arm: Only values between ' num2str(this.ARM_limit(1)) ' and ' num2str(this.ARM_limit(2)) ' are allowed!'], 0)
if (angle < this.motorLimits(1)) || (angle > this.motorLimits(2))
ita_verbose_info(['Arm: Only values between ' num2str(this.motorLimits(1)) ' and ' num2str(this.motorLimits(2)) ' are allowed!'], 0)
ret = false;
% this.wait = false;
return;
end
angle = angle - 120.1; % Larger substractive value: Higher position. Checkt at 90�.
angle = angle - 120-1.7+this.horizontalCorrectionFactor; % Larger substractive value: Higher position. Checkt at 90�.
motorControl = this.mMotorControl;
......
......@@ -200,9 +200,6 @@ classdef itaOptitrack < handle
% calculated (instantenous) offset won't be valid anymore as soon
% as the orientation of the head-mounted rigid body is changed.
%
% Author: Florian Pausch, fpa@akustik.rwth-aachen.de
% Version: 2016-11-18
%
% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved.
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder.
......@@ -306,7 +303,7 @@ classdef itaOptitrack < handle
openStream(urljava);
catch
% url is not existing or computer is not connected to Internet
error(['[itaOptitrack] No Internet connection or, ',url,' does not exist. Missing NatNet SDK cannot be downloaded. Please update URL (l.297) and version (l. 313/317/321).'])
error(['[itaOptitrack] No Internet connection or, ',url,' does not exist. Missing NatNet SDK cannot be downloaded. Please update download URL and NatNet version number.'])
end
% create directory
......@@ -324,6 +321,10 @@ classdef itaOptitrack < handle
fprintf('.\n')
delete(fullfile(Optitrack_obj.dllPath,'NatNet_SDK_2.10.zip'))
% delete downloaded quaternion.m version
delete(fullfile(Optitrack_obj.dllPath,'NatNet_SDK_2.10\NatNetSDK\Samples\Matlab\quaternion.m'))
delete(fullfile(Optitrack_obj.dllPath,'NatNet_SDK_2.10\NatNetSDK\Samples\Matlab\quaternion-license.txt'))
fprintf( '[itaOptitrack] NatNet SDK has been successfully downloaded.\n' );
end
......@@ -1183,9 +1184,9 @@ classdef itaOptitrack < handle
frameID = varargin{3};
frameTime = varargin{4};
Optitrack_obj.tempRigidBodyLogData = zeros(1,13,Optitrack_obj.numRigidBodies);
Optitrack_obj.tempRigidBodyLogData = nan(1,13,Optitrack_obj.numRigidBodies);
for idx=1:Optitrack_obj.numRigidBodies % TODO: quick and dirty solution with for loop, implement without for loop
for idx=1:data.nRigidBodies % TODO: quick and dirty solution with for loop, implement without for loop
rigidBodyData = data.RigidBodies(idx); %#ok
% Rigid body position [X,Y,Z]
......
......@@ -220,6 +220,12 @@ classdef itaMSPlaybackRecord < itaMSRecord
end
max_rec_lvl = max(abs(result.timeData),[],1);
% add history line
commitID = ita_git_getMasterCommitHash;
if ~isempty(commitID)
result = ita_metainfo_add_historyline(result,'Measurement',commitID);
end
end
function [result, max_rec_lvl] = run(this)
......
......@@ -20,8 +20,24 @@ hw_ch = MC(1).hardware_channel;
preamp_var = false;
switch(lower(MCE.type))
case {'sensor'}
sInit.Reference = '94';
sInit.Unit = 'dB re Pa';
tmp = itaValue(1,'V')/MCE.sensitivity;
switch tmp.unit
case 'Pa'
sInit.Reference = '94';
sInit.Unit = 'dB re Pa';
case 'm/s'
sInit.Reference = '1';
sInit.Unit = 'm/s';
case 'm/s^2'
sInit.Reference = '9.8';
sInit.Unit = 'm/s^2';
case 'N'
sInit.Reference = '1';
sInit.Unit = 'N';
otherwise
sInit.Reference = '1';
sInit.Unit = '1';
end
case {'preamp','ad','preamp_robo_fix','preamp_modulita_fix','preamp_aurelio_fix'}
sInit.Reference = '1';
sInit.Unit = 'V';
......@@ -148,8 +164,10 @@ oldSens = MCE.sensitivity;
sInit.Channel = hw_ch;
if strcmpi(sInit.Unit,'V')
sInit.Reference = itaValue(pList{1},'V');
else
elseif strcmpi(sInit.Unit,'dB re Pa')
sInit.Reference = itaValue(10^(pList{1}/20)*2e-5,'Pa');
else
sInit.Reference = itaValue(pList{1},sInit.Unit);
end
sInit.samplingRate = pList{2};
sInit.length = pList{3}*sInit.samplingRate;
......
......@@ -14,8 +14,24 @@ hw_ch = MC(1).hardware_channel;
preamp_var = false;
switch(lower(MCE.type))
case {'sensor'}
sInit.Reference = '94';
sInit.Unit = 'dB re Pa';
tmp = itaValue(1,'V')/MCE.sensitivity;
switch tmp.unit
case 'Pa'
sInit.Reference = '94';
sInit.Unit = 'dB re Pa';
case 'm/s'
sInit.Reference = '1';
sInit.Unit = 'm/s';
case 'm/s^2'
sInit.Reference = '9.8';
sInit.Unit = 'm/s^2';
case 'N'
sInit.Reference = '1';
sInit.Unit = 'N';
otherwise
sInit.Reference = '1';
sInit.Unit = '1';
end
case {'preamp','ad','preamp_robo_fix'}
sInit.Reference = '1';
sInit.Unit = 'V';
......@@ -118,8 +134,10 @@ oldSens = MCE.sensitivity;
sInit.Channel = hw_ch;
if strcmpi(sInit.Unit,'V')
sInit.Reference = itaValue(pList{1},'V');
else
elseif strcmpi(sInit.Unit,'dB re Pa')
sInit.Reference = itaValue(10^(pList{1}/20)*2e-5,'Pa');
else
sInit.Reference = itaValue(pList{1},sInit.Unit);
end
sInit.samplingRate = pList{2};
sInit.length = pList{3}*sInit.samplingRate;
......
......@@ -14,23 +14,26 @@ opts.heightCorrection = 0.0597; % in meter || ensures that the louds
opts=ita_parse_arguments(opts, varargin);
hc=opts.heightCorrection;
% X Y Z (openGL)
pos = itaCoordinates(zeros(12,3));
pos.r= 2.28;
pos.phi_deg=[45 315 225 135 0 270 180 90 0 270 180 90];
pos.theta_deg=[88.5 88.5 88.5 88.5 60 60 60 60 118 118 118 118];
pos.z=pos.z-hc;
if opts.virtualSpeaker
pos = [pos;...
0 0+hc 0;... % virtual speaker
0 3+hc 0]; % virtual speaker
pos.cart = [pos.cart;...
0 0 -2.3;... % virtual speaker
0 0 2.3]; % virtual speaker
end
if strcmp(opts.coordSystem,'openGL')
pos = ita_matlab2openGL(pos);
% Correction of head height
pos.z=pos.z-opts.heightCorrection;
if strcmpi(opts.coordSystem,'opengl')
pos.cart = ita_matlab2openGL(pos);
end
if (~opts.isItaCoordinates)
......
function [ binOut ] = ita_3da_binauralMixdown( lsSignals, varargin )
%ITA_3DA_BINAURALMIXDOWN Produces a 2-Channel binaural stream out of
%loudspeaker signal(s) and coordinates (given as optional coordinates or
%better: encoded in the itaAudio channel coordinates
% Detailed explanation goes here
opts.HRTF='D:\DATA\sciebo\MKOScripts\HRTFs\2015_ITA-Kunstkopf_HRIR_2ch_D186_1x1_256_v17.daff';
opts.LSPos=itaCoordinates;
if nargin>1
opts=ita_parse_arguments(opts,varargin);
end
if ~(isa(lsSignals, 'itaAudio')&&(lsSignals.nChannels>0))
error('First input must be itaAudio with at least one channel')
end
if opts.LSPos.nPoints<1
opts.LSPos=lsSignals.channelCoordinates;
if opts.LSPos.nPoints<1
error('We need some channel coordinates!');
end
end
hrtfSet=itaHRTF('DAFF',opts.HRTF);
binOut=itaAudio;
for k=1:lsSignals.nChannels
hrtf=hrtfSet.findnearestHRTF(opts.LSPos.n(k));
convolved=ita_convolve(lsSignals.ch(k),hrtf);
if k==1
binOut=convolved;
else
binOut=binOut+convolved
end
end
function [ loudspeakerSignals ] = ita_decodeAmbisonics( Bformat, LoudspeakerPos, varargin )
function [ OutputSignals ] = ita_decodeAmbisonics( Bformat, LoudspeakerPos, varargin )
%ITA_DECODEAMBISONICS Summary of this function goes here
% Detailed explanation goes here
opts.decoding='remax'; % Decoding strategy (remax,inphase,plane)
% BFormat<nmax,LS>
opts.decoding='remax'; % Decoding strategy (remax,inphase,plane)
% opts.decoding='none';
opts = ita_parse_arguments(opts,varargin);
% Initializing further parameters
nmax=numel(Bformat);
if isa(Bformat, 'itaAudio')
nmax=max(Bformat.nChannels);
else
nmax=size(Bformat,2);
end
N=floor(sqrt(nmax)-1);
% Weighting for Inphase/ReMax
g_re=ones(nmax,1); %init weighting factors for ReMax
......@@ -23,7 +30,8 @@ if(sum(strcmp(lower(opts.decoding),{'remax' 'both'})))
% g_m=P_m(r_E) with n=0 for P
% r_E is largest root of P_(order+1)
syms x;
f=1/2^(TheOrder+1)/factorial(TheOrder+1)*diff(((x^2-1)^(TheOrder+1)),(TheOrder+1));%Legendre Polynom n=0 m=order+1
f=1/2^(N+1)/factorial(N+1)*diff(((x^2-1)^(N+1)),(N+1));%Legendre Polynom n=0 m=order+1
maxroot=max(eval(solve(f))); %find maximum root(Nullstelle)
for k=1:nmax
leggie=legendre(ita_sph_linear2degreeorder(k),abs(maxroot)); % g_m=P_m(r_E)
......@@ -35,41 +43,50 @@ end
% Inphase Decoding
if(sum(strcmp(lower(opts.decoding),{'inphase' 'both'})))
% Calculates the B-format channel weights for InPhase-Decoding
TheOrder = obj.ambGetOrder; % amb order from sim room
nmax = (TheOrder+1)^2; % number of channels
weightsInPhase=zeros(nmax,1);
N=numel(obj.monitorRoom.getSourcePosition)/3;% get number of loudspeaker
%Dissertation J.Daniel p.314, 'preserve Energy' in 0. order
%g_0=sqrt[N*(2*M+1)/(M+1)^2]
weightsInPhase(1)=sqrt(N*(2*TheOrder+1)/(TheOrder+1)^2);
weightsInPhase(1)=sqrt(N*(2*N+1)/(N+1)^2);
for k=2:nmax
m=ita_sph_linear2degreeorder(k);
% Dissertation J.Daniel p.314
% g_m=M!*(M+1)!/[(M+m+1)!*(M-n)!]
weightsInPhase(k)=factorial(TheOrder)*factorial(TheOrder+1)/factorial(m+TheOrder+1)/factorial(TheOrder-m);
weightsInPhase(k)=factorial(N)*factorial(N+1)/factorial(m+N+1)/factorial(N-m);
end
g_in=weightsInPhase;
end
weights=g_in.*g_re; %merge weighting factors
for k=1:numel(weights)
Bformat(:,k)=weights(k).*Bformat(:,k); %Apply weighting factors
weights=g_in.*g_re; % merge weighting factors
%% Applying weighting to BFormat
if isa(Bformat,'itaAudio')
for k=1:Bformat.nChannels
Bformat.time(:,k)=Bformat.time(:,k).*weights(k);
end
else
for k=1:numel(weights)
Bformat(:,k)=weights(k).*Bformat(:,k);
end
end
% SH and inversion
Y = ita_sph_base(LS, TheOrder, 'real'); % generate basefunctions
Yinv=pinv(Y); % calculate Pseudoinverse
%% SH and inversion of loudspeaker set-up
Y = ita_sph_base(LoudspeakerPos, N, 'real'); % generate basefunctions
Yinv=pinv(Y); % calculate Pseudoinverse, moore penrose, svd
if isa(Bformat,'itaAudio')
for k=1:LS.nPoints
OutputSignals(k)=sum(Bformat*Yinv(:,k)');
for k=1:LoudspeakerPos.nPoints
for l=1:nmax
temp(l)=Bformat.ch(l)*Yinv(l,k);
end
OutputSignals(k)=sum(temp);
end
OutputSignals=ita_merge(OutputSignals(:));
OutputSignals.channelCoordinates=LoudspeakerPos;
else
OutputSignals=Bformat*Yinv;
end
end
function [ Bformat ] = ita_encodeAmbisonics( sourcePos, varargin )
%ITA_ENCODEAMBISONICS Summary of this function goes here
function [ audioOut ] = ita_encodeAmbisonics( audioIn, order, sourcePos )
%ITA_ENCODEAMBISONICS Encodes a itaAudio with channel coordinates or a
% itaCoordinate with source positions into ambisonics channels
%
% Detailed explanation goes here
if nargin<1
error('Source position is needed as itaCoordiantes!');
end
if ~isa(sourcePos,'itaCoordinates')
error('First input data has to be an itaCoordinates!')
elseif isempty(sourcePos.cart)
error('First input data has to be an itaCoordinates WITH inputdata!')
%% Init
if isa(audioIn, 'itaAudio')
aud=true;
elseif isa(audioIn, 'itaCoordinates')
aud=false;
sourcePos=audioIn;
if nargin>2
error('For itaCoordinates no additional source positions can be given!');
end
else
error('itaAudio or itaCoordinates has to be the first input!');
end
opts.order=1; %Ambisonics truncation order
opts.audioSource=''; %Signal of the source (itaAudio or filename)
opts = ita_parse_arguments(opts, varargin);
% Encode Source
Bformat = ita_sph_base(sourcePos, opts.order, 'real');
if nargin<2
warning('SH Truncation order missing, assuming order of one');
order=1;
end
if ~isempty(opts.audioSource)
if isa(opts.audioSource,'char')
audioIn = ita_read(opts.audioSource);
elseif isa(opts.audioSource,'itaAudio')
audioIn = opts.audioSource;
elseif ~isa(audioIn,'itaAudio')
error('Audio input must eihter be itaAudio or valid filename (see ita_read)');
end
audioOut=audioIn*Bformat(1);
for k=2:numel(Bformat)
audioOut=ita_merge(audioOut,audioIn*Bformat(k));
if nargin<3 && aud
sourcePos=audioIn.channelCoordinates;
if sourcePos.nPoints<1 || ~isa(sourcePos,'itaCoordinates')
error('No sourcePos found or it is not itaCoordinates! Add channelCoordinates to itaAudio!')
end
Bformat=audioOut;
end
%% Encode Source
if ~aud
audioOut=ita_sph_base(sourcePos, order, 'real');
end
%% Applying audio data
if aud
audioOut=itaAudio;
audioOut_temp=itaAudio;
for idxCh=1:audioIn.nChannels
Bformat = ita_sph_base(sourcePos(idxCh), order, 'real');
for idxCoeff=1:numel(Bformat)
audioOut_temp(idxCoeff)=audioIn.ch(idxCh)*Bformat(idxCoeff);
end
if idxCh==1
audioOut=ita_merge(audioOut_temp);
else
audioOut=audioOut+ita_merge(audioOut_temp);
end
end
end
\ No newline at end of file
......@@ -34,6 +34,12 @@ else
dists = sqrt(sum((this.cart-repmat(coords.cart(idinput,:),size(this.cart,1),1)).^2,2));
for idx = 1:num
[dist(idinput, idx), ind(idinput, idx)] = min(dists); %#ok<AGROW>
if sum(dists == min(dists)) > 1
distsSph = sqrt(sum((this.sph-repmat(coords.sph(idinput,:),size(this.sph,1),1)).^2,2));
[dist(idinput, idx), ind(idinput, idx)] = min(distsSph);
end
dists(ind(idinput, idx)) = inf;
end
end
......
......@@ -96,10 +96,9 @@ if strcmp(mode,'filter') %mli version
end
% sum the squared values
band_values = zeros(numel(fmExact),input.nChannels);
for idxch = 1:numel(fmExact)
% don't be confused: sqrt will be extracted at the end!
band_values(idxch,:) = sum(abs(squeeze(result.freq(:,idxch,:))).^exponent);
band_values = squeeze(sum(abs(result.freq).^exponent,1));
if input.nChannels == 1
band_values = band_values(:);
end
% FFT Mode
......
......@@ -32,16 +32,16 @@ else
nOverlap = round(sArgs.overlap);
end
nSegments = ceil(a.nSamples / (nWindow - nOverlap)) + 1;
nNewLength = (nSegments - 1) * (nWindow - nOverlap) + nWindow;
if nNewLength-nWindow > a.nSamples
a = ita_extend_dat(a,nNewLength - nWindow,'forcesamples');
end
% half a window length at beginning and end
ext_zeros = zeros(nWindow/2,a.nChannels);
data = [ext_zeros; a.time; ext_zeros];
nSegments = ceil((size(data,1) - nWindow) / (nWindow - nOverlap)) + 1;
nNewLength = (nSegments - 1) * (nWindow - nOverlap) + nWindow;
if nNewLength > a.nSamples
a = ita_extend_dat(a,nNewLength,'forcesamples');
end
%% generate window
win_vec = window(sArgs.window,nWindow+1);
win_vec(end) = [];
......
......@@ -36,7 +36,7 @@ function varargout = ita_sound_power(varargin)
% Modified: 28-Nov-2017
%% Initialization and Input Parsing
sArgs = struct('pos1_spl', 'itaSuper', 'pos2_T_empty', 'itaSuper', 'room_volume', 124,'room_surface',181,'T',20,'RH',0.5,'p_s',101325, 'freqRange', ita_preferences('freqRange'), 'bandsPerOctave', ita_preferences('bandsPerOctave') );
sArgs = struct('pos1_spl', 'itaSuper', 'pos2_T_empty', 'itaSuper', 'room_volume', 124,'room_surface',181,'T',20,'RH',0.5,'p_s',101325, 'freqRange', ita_preferences('freqRange'), 'bandsPerOctave', ita_preferences('bandsPerOctave'), 'bandMode','fft');
[spl,T_empty,sArgs] = ita_parse_arguments(sArgs,varargin);
% acoustic constants
......@@ -48,7 +48,7 @@ C2 = 101325./double(sArgs.p_s).*sqrt((273.15 + sArgs.T)/296).^3;
%% calculate sound pressure level data
% first third-octaves then average
spl = ita_spk2frequencybands(spl, 'freqRange',sArgs.freqRange , 'bandsPerOctave',sArgs.bandsPerOctave);
spl = ita_spk2frequencybands(spl, 'freqRange',sArgs.freqRange , 'bandsPerOctave',sArgs.bandsPerOctave,'mode',sArgs.bandMode);
spl_m = sqrt(mean(spl^2));
spl_m = itaResult(spl_m,T_empty.freqVector);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment