Adding MIRO converter functions for different DAFF content types

parent a6991753
function [] = daffv17_convert_from_miro( miro_obj, target_file_path, additional_metadata, domain )
function [] = daffv17_convert_from_miro( miro_obj, target_file_path, additional_metadata, contenttype )
%
% daffv17_convert_from_miro Converts a MIRO object into DAFF
%
......@@ -14,12 +14,12 @@ if nargin < 1
elseif nargin < 2
target_file_path = [ miro_obj.name '.ir.v17.daff' ];
additional_metadata = [];
domain = 'time';
contenttype = 'ir';
elseif nargin < 3
additional_metadata = [];
domain = 'time';
contenttype = 'ir';
elseif nargin < 4
domain = 'time';
contenttype = 'ir';
end
......@@ -69,8 +69,8 @@ betanums = size( unique( quadrature( :, 2 ) ), 1 );
betarange = rad2deg( [ min( miro_obj.elevation ) max( miro_obj.elevation ) ] );
betares = diff( betarange ) / ( betanums - 1 );
if strcmpi( domain, 'frequency' )
%$ Execute using data function 'dfMIRODFT' (frequency domain)
if strcmpi( contenttype, 'dft' )
%$ Execute using data function 'dfMIRODFT' (discrete fourier transform)
daffv17_write( 'filename', target_file_path, ...
'datafunc', @dfMIRODFT, ...
'userdata', miro_obj, ...
......@@ -82,10 +82,23 @@ if strcmpi( domain, 'frequency' )
'betarange', betarange, ...
'orient', [ 0 0 0 ], ...
'channels', 2 );
elseif strcmpi( contenttype, 'ms' )
%$ Execute using data function 'dfMIROMS' (magnitude spectrum)
daffv17_write( 'filename', target_file_path, ...
'datafunc', @dfMIROMS, ...
'userdata', miro_obj, ...
'metadata', metadata, ...
'content', 'ms', ...
'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, ...
'datafunc', @dfMIROIR, ...
'userdata', miro_obj, ...
'metadata', metadata, ...
'content', 'ir', ...
......
......@@ -15,14 +15,11 @@ function [ data, sampleRate, isSymetric, metadata ] = dfMIRODFT( alpha, beta, mi
nResidual = mod( size( hrir, 1 ), 4 );
if nResidual > 0
dft_raw = fft( [ hrir' zeros( 2, 4 - nResidual ) ] );
data = fft( [ hrir' zeros( 2, 4 - nResidual ) ] );
else
dft_raw = fft( hrir' );
data = 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 );
......
function [ data, samplerate, metadata ] = dfMIRO( alpha, beta, miro_obj )
function [ data, samplerate, metadata ] = dfMIROIR( alpha, beta, miro_obj )
samplerate = miro_obj.fs;
if ~isempty( miro_obj.resampleToFS )
......
function [ freqs, mags, metadata ] = dfMIROMS( alpha, beta, miro_obj )
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
mags = abs( fft( [ hrir' zeros( 2, 4 - nResidual ) ] ) );
else
mags = abs( fft( hrir' ) );
end
freqs = ( 1:size( mags, 2 ) ) * miro_obj.fs / 2 / size( mags, 2 );
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
......@@ -47,4 +47,4 @@ daffv17_convert_from_miro( HRIR_FULL2DEG, 'HRIR_FULL2DEG_44kHz_web.v17.ir.daff',
% ... 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' );
daffv17_convert_from_miro( HRIR_FULL2DEG, 'HRIR_FULL2DEG_44kHz_web.v17.dft.daff', additional_metadata, 'dft' );
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