Merging important fixes and improvements from OpenDAFF repository

parent a9eb8078
# OpenDAFF - A free, open source software package for directional audio data
OpenDAFF is distributed under the terms of the GNU Lesser Public License (LGPL) with an exception for static linking permission.
## License
Copyright (c) Institute of Technical Acoustics, RWTH Aachen University, 2009-2016
Visit the OpenDAFF homepage: http://www.opendaff.org
Copyright 2016 Institute of Technical Acoustics, RWTH Aachen University
Licensed under the Apache License, Version 2.0 (the "License");
you may not use the OpenDAFF software package except in compliance with the License.
You may obtain a copy of the License at
<http://www.apache.org/licenses/LICENSE-2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You should also have received a [copy of the License](LICENSE.md) with the OpenDAFF software package.
## Matlab scripts
......
function [] = daffv17_convert_from_miro( miro_obj, target_file_path, additional_metadata )
function [] = daffv17_convert_from_miro( miro_obj, target_file_path, additional_metadata, domain )
%
% daffv17_convert_from_miro Converts a MIRO object into DAFF
%
......@@ -14,8 +14,12 @@ if nargin < 1
elseif nargin < 2
target_file_path = [ miro_obj.name '.ir.v17.daff' ];
additional_metadata = [];
domain = 'time';
elseif nargin < 3
additional_metadata = [];
domain = 'time';
elseif nargin < 4
domain = 'time';
end
......@@ -65,17 +69,31 @@ betanums = size( unique( quadrature( :, 2 ) ), 1 );
betarange = rad2deg( [ min( miro_obj.elevation ) max( miro_obj.elevation ) ] );
betares = diff( betarange ) / ( betanums - 1 );
%$ Execute using data function 'dfMIRO'
daffv17_write( 'filename', target_file_path, ...
'datafunc', @dfMIRO, ...
'userdata', miro_obj, ...
'metadata', metadata, ...
'content', 'ir', ...
'alphares', alphares, ...
'alpharange', alpharange, ...
'betares', betares, ...
'betarange', betarange, ...
'orient', [ 0 0 0 ], ...
'channels', 2, ...
'quantization', 'float32' );
\ No newline at end of file
if strcmpi( domain, 'frequency' )
%$ Execute using data function 'dfMIRODFT' (frequency domain)
daffv17_write( 'filename', target_file_path, ...
'datafunc', @dfMIRODFT, ...
'userdata', miro_obj, ...
'metadata', metadata, ...
'content', 'dft', ...
'alphares', alphares, ...
'alpharange', alpharange, ...
'betares', betares, ...
'betarange', betarange, ...
'orient', [ 0 0 0 ], ...
'channels', 2 );
else
%$ Execute using data function 'dfMIRO' (time domain)
daffv17_write( 'filename', target_file_path, ...
'datafunc', @dfMIRO, ...
'userdata', miro_obj, ...
'metadata', metadata, ...
'content', 'ir', ...
'alphares', alphares, ...
'alpharange', alpharange, ...
'betares', betares, ...
'betarange', betarange, ...
'orient', [ 0 0 0 ], ...
'channels', 2, ...
'quantization', 'float32' );
end
\ No newline at end of file
function [ data, sampleRate, isSymetric, metadata ] = dfMIRODFT( alpha, beta, miro_obj )
isSymetric = true;
sampleRate = miro_obj.fs;
if ~isempty( miro_obj.resampleToFS )
sampleRate = miro_obj.resampleToFS;
end
if strcmp( miro_obj.angles, 'DEG' )
[ irID, azimuth, elevation ] = closestIr( miro_obj, alpha, beta );
else
[ irID, azimuth, elevation ] = closestIr( miro_obj, deg2rad( alpha ), deg2rad( beta ) );
end
hrir = getIR( miro_obj, irID );
nResidual = mod( size( hrir, 1 ), 4 );
if nResidual > 0
dft_raw = fft( [ hrir' zeros( 2, 4 - nResidual ) ] );
else
dft_raw = fft( hrir' );
end
fft_size = size( dft_raw, 1 ) / 2 + 1;
data = dft_raw( 1:fft_size, : );
metadata = [];
if strcmp( miro_obj.angles, 'RAD' )
azimuth = rad2deg( azimuth );
elevation = rad2deg( elevation );
end
angle_threshold_deg = 0.2;
if abs( diff( [ azimuth alpha ] ) ) < angle_threshold_deg || ...
abs( diff( [ elevation beta ] ) < angle_threshold_deg )
daffv17_add_metadata( metadata, 'MIRO Nearest Neighbour Search Applied', 'Bool', true );
daffv17_add_metadata( metadata, 'MIRO Nearest Neighbour Azimuth', 'Float', azimuth );
daffv17_add_metadata( metadata, 'MIRO Nearest Neighbour Elevation', 'Float', elevation );
end
end
......@@ -44,3 +44,7 @@ daffv17_convert_from_miro( HRIR_FULL2DEG, 'HRIR_FULL2DEG_48kHz_web.v17.ir.daff',
% ... with resampling to common 44.1 kHz
HRIR_FULL2DEG.resampleToFS = 44.1e3;
daffv17_convert_from_miro( HRIR_FULL2DEG, 'HRIR_FULL2DEG_44kHz_web.v17.ir.daff', additional_metadata );
% ... in frequency domain.
HRIR_FULL2DEG.resampleToFS = HRIR_FULL2DEG.fs; % reset fs
daffv17_convert_from_miro( HRIR_FULL2DEG, 'HRIR_FULL2DEG_44kHz_web.v17.dft.daff', additional_metadata, 'frequency' );
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