diff --git a/applications/Binaural-HRTF/HRTF_class/@itaHRTF/itaHRTF.m b/applications/Binaural-HRTF/HRTF_class/@itaHRTF/itaHRTF.m index 943164983d89e741b68b2c5505bb1bc79cfa9bf4..af28abc4d4d0061664f967e413168c934410bb85 100644 --- a/applications/Binaural-HRTF/HRTF_class/@itaHRTF/itaHRTF.m +++ b/applications/Binaural-HRTF/HRTF_class/@itaHRTF/itaHRTF.m @@ -1378,160 +1378,6 @@ classdef itaHRTF < itaAudio grid on;set(gca,'layer','top') end - % writes DAFF file to hard disc - % - % Input: filePath / fileName (string) - % - % Required: openDAFF matlab executables - % - % Output: none - - if nargin == 2 - fileName = filePath; - else - fileName = [ 'HRTF_Length' int2str(this.nSamples) '_' int2str(this.resAzimuth) 'x' int2str(this.resElevation) '.daff']; - end - - - %.............................................................. - % Comment: Angles are not exact - improve it if you like to :) - precision = 3; - nThetaU = numel(unique(round(this.channelCoordinates.theta_deg*10)./10)); - nPhiU = numel(unique(round(this.channelCoordinates.phi_deg*10)./10)); - - resElevation= round(median(diff(rad2deg(this.theta_Unique)))*10^precision)/10^precision; - rangeEl = round([min(rad2deg(this.theta_Unique)) max(rad2deg(this.theta_Unique))]*10^precision)/10^precision; - rangeElnew = [min(rangeEl) min(rangeEl)+(nThetaU-1)*resElevation]; - - resAzimuth= round(median(diff(rad2deg(this.phi_Unique)))*10^precision)/10^precision; - rangeAz = round([min(rad2deg(this.phi_Unique)) max(rad2deg(this.phi_Unique))]*10^precision)/10^precision; - rangeAznew = [min(rangeAz) min(rangeAz)+(nPhiU-1)*resAzimuth]; - %.............................................................. - - - %% config values - threshold_db = -20; - pre_taps = 12; - window_length = 128; - - delay = 10; - - gPeakL = 0; - gPeakR = 0; - gRangeStart = inf; - gRangeEnd = 0; - gRangeStartHit = []; - gRangeEndHit = []; - gPower = 0; - - - % Measurement distance [m], rounded on one digit - distance = delay / 44100 * 340; - distance = round(distance * 100)/100; - - % this = ita_time_shift(this,delay); - % metadata.object = 'ITA Kunstkopf, an artificial head developed and designed at the Institute of Technical Acoustics (ITA), RWTH Aachen University'; - % metadata.copyright = '(c) Copyright Institute of Technical Acoustics (ITA), RWTH Aachen University, Germany'; - % metadata.contact = 'Frank Wefers (fwe@akustik.rwth-aachen.de)'; - % metadata.environment = 'semi-anechoic chamber'; - % metadata.session = 'Mess01: Farfield HRIRs, Tobias Lentz, 2001'; - % metadata.processing = 'Loudspeaker deconvolved. Windowed using peak-oriented tukey window (0.1) to length 96 taps.'; - - %% find filter ranges - peak = max(abs(this.timeData)); - threshold = peak * 10^(threshold_db/20); - timeData = abs(this.timeData); - for index = 1:this.nChannels - kTemp = find(timeData(:,index) >=threshold(index)); - if (isempty(kTemp)) - error('Impulse response is completely below the threshold') - end - - r(index,:) = [ kTemp(1) kTemp(end) ]; - k{index} = kTemp; - end - - - - offset = max(r(:,1)-pre_taps,1); - - - for index = 1:this.nChannels - chObj = ita_time_window(this.ch(index),[offset(index) offset(index)+ window_length-1],'samples'); - timeData(:,index) = chObj.timeData; - - end - - copyObj = this; - copyObj.timeData = timeData; - copyCoordinates = copyObj.channelCoordinates; - copyCoordinates = copyCoordinates.build_search_database; - - - %% global peaks - - peak = max(abs(copyObj.timeData)); - threshold = peak * 10^(threshold_db/20); - timeData = abs(copyObj.timeData); - for index = 1:copyObj.nChannels - kTemp = find(timeData(:,index) >=threshold(index)); - if (isempty(kTemp)) - error('Impulse response is completely below the threshold') - end - - r(index,:) = [ kTemp(1) kTemp(end) ]; - k{index} = kTemp; - end - - - gRangeStart = min(r(r(:,1) > delay,1)); - gRangeEnd = max(r(r(:,2) < 1000,2)); - - - nDegree = log2(window_length); - - % create dataset - dataset = daff_create_dataset(... - 'alphares', resAzimuth, ... - 'alpharange',rangeAznew,... - 'betares', resElevation, ... - 'betarange', rangeElnew, ... - 'channels', 2); - - % set samplerate and metainfo - dataset.samplerate = this.samplingRate; - dataset.metadata.desc = 'Dummy HRTF'; - - dataset.metadata.delay_samples = int32(delay); - dataset.metadata.measurement_distance_meters = distance; - dataset.metadata.creation_date = datestr(now, 'yyyy-mm-dd HH:MM'); - % assign data - - - for i=1:dataset.numrecords - %dataset.records{i}.data = this.data(:,(2*i-1:2*i))'; - - alpha = dataset.records{i}.alpha; - beta = dataset.records{i}.beta; - - % get and save data - data = this.findnearestHRTF(180-beta,alpha); - % if ceil(nDegree) ~= floor(nDegree),data.nSamples = ceil(nDegree); - % end - - dataset.records{i}.data = data.timeData(gRangeStart:gRangeStart+window_length-1,:).'; - - - % Optionally you can supply individual metadata for the records - dataset.records{i}.metadata.filename = fileName; - end - - % write file - daff_write( 'filename', fileName, ... - 'content', 'IR', ... - 'dataset', dataset, 'verbose'); - - end end methods(Hidden = true)