main content

ambisonic binaural decoding -凯发k8网页登录

this example shows how to decode ambisonic audio into binaural audio using virtual loudspeakers. a virtual loudspeaker is a sound source positioned on the surface of a sphere, with the listener located at the center of the sphere. each virtual loudspeaker has a pair of head-related transfer functions (hrtf) associated with it: one for the left ear and one for the right ear. the virtual loudspeaker locations along with the ambisonic order are used to calculate the ambisonic decoder matrix. the output of the decoder is filtered by the hrtfs corresponding to the virtual loudspeaker position. the signals from the left hrtfs are summed together and fed to the left ear. the signals from the right hrtfs are summed together and fed to the right ear. a block diagram of the audio signal flow is shown here.

load the ari hrtf dataset

aridataset = load('referencehrtf.mat');

get the hrtf data in the required dimension of: [numofsourcemeasurements x 2 x lengthofsamples]

hrtfdata = aridataset.hrtfdata;
sourceposition = aridataset.sourceposition(:,[1,2]);

the ari hrtf databases used in this example is based on the work by acoustics research institute. the hrtf data and source position in referencehrtf.mat are from ari nh2 subject.

the hrtf databases by acoustics research institute, austrian academy of sciences are licensed under a creative commons attribution-sharealike 3.0 unported license: .

select points from ari hrtf dataset

now that the hrtf dataset is loaded, determine which points to pick for virtual loudspeakers. this example picks random points distributed on the surface of a sphere and selects the points of the hrtf dataset closest to the picked points.

  1. pick random points from a spherical distribution

  2. compare sphere to points from the hrtf dataset

  3. pick the points with the shortest distance between them

% create a sphere with a distribution of points
npoints = 24;   % number of points to pick
rng(0);         % seed random number generator
sphereaz = 360*rand(1,npoints);
sphereel = rad2deg(acos(2*rand(1,npoints)-1))-90;
pickedsphere = [sphereaz' sphereel'];
% compare distributed points on the sphere to points from the hrtf dataset
pick = zeros(1, npoints);
d = zeros(size(pickedsphere,1), size(sourceposition,1));
for ii = 1:size(pickedsphere,1)
    for jj = 1:size(sourceposition,1)
        % calculate arc length
        d(ii,jj) = acos( ...
            sind(pickedsphere(ii,2))*sind(sourceposition(jj,2))   ...
            cosd(pickedsphere(ii,2))*cosd(sourceposition(jj,2)) * ...
            cosd(pickedsphere(ii,1) - sourceposition(jj,1)));
    end
    [~,idx] = sort(d(ii,:)); % sort points
    pick(ii) = idx(1);       % pick the closest point
end

create ambisonic decoder

specify a desired ambisonic order and desired virtual loudspeaker source positions as inputs to the audioexample.ambisonics.ambidecodemtrx helper function. the function returns an ambisonics decoder matrix.

order = 7;
devices = sourceposition(pick,:)';
dmtrx = audioexample.ambisonics.ambidecodemtrx(order, devices);

create hrtf filters

create an array of fir filters to perform binaural hrtf filtering based on the position of the virtual loudspeakers.

fir = cell(size(pickedsphere));
for ii = 1:length(pick)
    fir{ii,1} = dsp.frequencydomainfirfilter(hrtfdata(:,pick(ii),1)');
    fir{ii,2} = dsp.frequencydomainfirfilter(hrtfdata(:,pick(ii),2)');
end

create audio input and output objects

load the ambisonic audio file of helicopter sound and convert it to 48 khz for compatibility with the hrtf dataset. specify the ambisonic format of the audio file.

create an audio file sampled at 48 khz for compatibility with the hrtf dataset.

desiredfs = 48e3;
[audio,fs] = audioread('heli_16ch_acn_sn3d.wav');
audio = resample(audio,desiredfs,fs);
audiowrite('heli_16ch_acn_sn3d_48.wav',audio,desiredfs);

specify the ambisonic format of the audio file. set up the audio input and audio output objects.

format = 'acn-sn3d';
samplesperframe = 2048;
filereader = dsp.audiofilereader('heli_16ch_acn_sn3d_48.wav', ...
                    'samplesperframe',samplesperframe);
devicewriter = audiodevicewriter('samplerate',desiredfs);
audiofiltered = zeros(samplesperframe,size(fir,1),2);

process audio

while ~isdone(filereader)
    audioambi = filereader();
    audiodecoded = audioexample.ambisonics.ambidecode(audioambi, dmtrx, format);
    for ii = 1:size(fir,1)
        audiofiltered(:,ii,1) = step(fir{ii,1}, audiodecoded(:,ii)); % left
        audiofiltered(:,ii,2) = step(fir{ii,2}, audiodecoded(:,ii)); % right
    end
    audioout = 10*squeeze(sum(audiofiltered,2));   % sum at each ear 
    numunderrun = devicewriter(audioout); 
end
% release resources
release(filereader)
release(devicewriter)

references

[1] kronlachner, m. (2014). spatial transformations for the alteration of ambisonic recordings (master's thesis).

[2] noisternig, markus. et al. "a 3d ambisonic based binaural sound reproduction system." presented at 24th aes international conference: multichannel audio, the new reality, alberta, june 2003.

see also

网站地图