主要内容

间纹

3-D与头部相关的传输函数(HRTF)插值

描述

example

InterpolatedHrtf= InterpalyHrtf(HRTF,源定位s,所需的信息)returns the interpolated head-related transfer function (HRTF) at the desired position.

example

InterpolatedHrtf= InterpalyHrtf(___,名称,价值)specifies options using one or more名称,价值配对参数。

例子

全部折叠

通过与头部相关的传输功能(HRTF)对声音文件进行过滤,修改声音文件的3-D音频图像。通过指定所需的方位角和高程来设置声源的位置。

load'ReferenthHrtf.mat'HRTFDATA源定位HRTFDATA= permute(double(hrtfData),[2,3,1]); sourcePosition = sourcePosition(:,[1,2]);

使用所需源位置的VBAP算法计算与头部相关的脉冲响应(HRIR)。分开输出,interpolatedIR,进入左耳和右耳的冲动反应。

desiredAz = 110; desiredEl = -45; desiredPosition = [desiredAz desiredEl]; interpolatedIR = interpolateHRTF(hrtfData,sourcePosition,desiredPosition,。。。"Algorithm","VBAP");leftir = squeeze(interpolatedir(:,1,1,:))';Rightir = Squeeze(Interpolatedir(:,2,:))';

Create adsp.AudioFileReader对象逐帧读取文件。创建一个AudioDeviceWriter对象可以通过框架播放音频到您的声卡。创建两个dsp.FIRFilterobjects and specify the filter coefficients using the head-related transfer function interpolated impulse responses.

filereader = dsp.audiofilereader('Rockdrums-48-Stereo-11secs.mp3');deviceWriter = audioDeviceWriter ('SampleRate',fileReader.mamplater);leftFilter = dsp.firfilter('Numerator',左);RightFilter = DSP.Firfilter('Numerator',rightIR);

在音频流循环中:

  1. 在音频数据框架中阅读。

  2. Feed the stereo audio data through the left and right HRIR filters, respectively.

  3. 加入左右通道,并将音频写入输出设备。

尽管〜ISDONE(FILEREADER)AUDIOIN = FILEREADER();leftChannel = leftFilter(Audioin(:,1));RightChannel = RightFilter(Audioin(:,2));DeviceWriter([[leftChannel,RightChannel]);结尾

As a best practice, release your System objects when complete.

release(deviceWriter) release(fileReader)

Create arrays of head-related impulse responses corresponding to desired source positions. Filter mono input to model a moving source.

Load the ARI HRTF dataset. Cast theHRTFDATA要键入double,然后将其重塑为所需的维度:(源位置的数量) - by-2-by-(HRTF样本数)。使用的前两列源定位matrix only, which correspond to the azimuth and elevation of the source in degrees.

load'ReferenthHrtf.mat'HRTFDATA源定位HRTFDATA= permute(double(hrtfData),[2,3,1]); sourcePosition = sourcePosition(:,[1,2]);

指定所需的源位置,然后使用该位置计算HRTF间纹function. Separate the output,interpolatedIR,进入左耳和右耳的冲动反应。

desiredAz = [-120;-60;0;60;120;0;-120;120]; desiredEl = [-90;90;45;0;-45;0;45;45]; desiredPosition = [desiredAz desiredEl]; interpolatedIR = interpolateHRTF(hrtfData,sourcePosition,desiredPosition); leftIR = squeeze(interpolatedIR(:,1,:)); rightIR = squeeze(interpolatedIR(:,2,:));

创建一个audio file sampled at 48 kHz for compatibility with the HRTF dataset.

Desiredfs = 48e3;[音频,fs] = Audioread('Counting-16-44p1-mono-15secs.wav');音频= 0.8*resplame(音频,desiredfs,fs);AudioWrite('Counting-16-48-Mono-15secs.wav',音频,Desiredfs);

Create adsp.AudioFileReader对象逐帧读取文件。创建一个AudioDeviceWriter对象可以通过框架播放音频到您的声卡。创建两个dsp.FIRFilter对象NumeratorSource调成Input port。SettingNumeratorSourcetoInput portenables you to modify the filter coefficients while streaming.

filereader = dsp.audiofilereader('Counting-16-48-Mono-15secs.wav');deviceWriter = audioDeviceWriter ('SampleRate',fileReader.mamplater);leftFilter = dsp.firfilter('NumeratorSource','Input port');RightFilter = DSP.Firfilter('NumeratorSource','Input port');

在音频流循环中:

  1. 在音频数据框架中阅读。

  2. Feed the audio data through the left and right HRIR filters.

  3. 加入左右通道,并将音频写入输出设备。如果您有立体声输出硬件(例如耳机),则可以随着时间的推移听到源位置的位置。

  4. 通过更新过滤器系数,以2秒的间隔修改所需的源位置。

durationPerPosition = 2; samplesPerPosition = durationPerPosition*fileReader.SampleRate; samplesPerPosition = samplesPerPosition - rem(samplesPerPosition,fileReader.SamplesPerFrame); sourcePositionIndex = 1; samplesRead = 0;尽管〜ISDONE(FILEREADER)AUDIOIN = FILEREADER();samplesRead = samplesRead + filereader.samplesperframe;leftChannel = leftFilter(audioin,leftir(sourcePositionIndex,:));RightChannel = RightFilter(Audioin,Rightir(sourcePositionIndex,:));DeviceWriter([[leftChannel,RightChannel]);如果mod(samplesRead,samplesperposition)== 0 sourcePositionIndex = sourcePositionIndex + 1;结尾结尾

As a best practice, release your System objects when complete.

release(deviceWriter) release(fileReader)

输入参数

全部折叠

在源位置测量的HRTF值,指定为N-by-2-by-M大批。

  • N- - 已知的HRTF对数量

  • M- - 每个已知HRTF中的样品数量

如果指定HRTFwith real numbers, the function assumes that the input represents an impulse response, andMcorresponds to the length of the impulse response. If you specifyHRTFwith complex numbers, the function assumes that the input represents a transfer function, andM对应于频率响应中的垃圾箱数量。输出间纹function has the same complexity and interpretation as the input.

数据类型:single|双倍的
Complex Number Support:Yes

对应于测得的HRTF值的源位置, specified as aN-by-2矩阵。Nis the number of known HRTF pairs. The two columns correspond to the azimuth and elevation of the source in degrees, respectively.

方位角必须在[-180,360]范围内。您可以使用-180至180惯例或0至360惯例。

Elevation must be in the range [−90,180]. You can use the −90 to 90 convention or the 0 to 180 convention.

数据类型:single|双倍的

Desired source position for HRTF interpolation, specified as aP-by-2矩阵。P是所需的源位置的数量。这些列分别对应于所需的方位角和源的高度。

方位角必须在[-180,360]范围内。您可以使用-180至180惯例或0至360惯例。

Elevation must be in the range [−90,180]. You can use the −90 to 90 convention or the 0 to 180 convention.

数据类型:single|双倍的

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, 在哪里Nameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and encloseName用引号。

例子:'算法','vbap'

插值算法,指定为"Bilinear"或者"VBAP"

  • Bilinear–– 3-D bilinear interpolation, as specified by[1]

  • VBAP- - 矢量基础振幅平插插插,如[2]

数据类型:char|string

Output Arguments

全部折叠

插值HRTF,返回为P-by-2-by-M大批。

  • P–– Number of desired source positions, specified by the number of rows in the所需的信息输入参数。

  • M- - 每个已知HRTF中的样本数量,由页面数量指定HRTF输入参数。

InterpolatedHrtfhas the same complexity and interpretation as the input. If you specify the input,HRTF, with real numbers, the function assumes that the input represents an impulse response. If you specify the input with complex numbers, the function assumes that the input represents a transfer function.

数据类型:single|双倍的
Complex Number Support:Yes

参考

[1] F.P.Freeland,L.W.P。Biscainho和P.S.R.Diniz,“与头部相关转移功能(HRTFS)的插值:一种多源方法”。2004 12th European Signal Processing Conference。维也纳,2004年,第1761–1764页。

[2]普尔基,维尔。“使用基于矢量的振幅平移的虚拟声源定位。”Journal of Audio Engineering Society。卷。45.第6期,第456–466页。

Extended Capabilities

C/C ++代码生成
使用MATLAB®CODER™生成C和C ++代码。

Version History

Introduced in R2018b