We make the sound in the headphones three-dimensional. Digital Signal Processing for Home Use

If you have ever listened to music through headphones and through speakers, then you must have noticed that it sounds different. Headphones often have the feeling that the sound source is somewhere inside the head. There are other negative effects: some older recordings are made so that, for example, the guitar is completely mixed into the left channel, and the drums - into the right. On the speakers it sounds normal - as if the guitarist is standing about where one of the loudspeakers is, but in headphones it is very unpleasant, because it is unnatural: in nature there is no such thing that only one ear can hear the sound.





I will say more: the vast majority of commercial audio recordings are designed specifically for listening through speakers. That is, the sound engineer, when preparing the recording, does everything so that it sounds correctly (in accordance with the author's ideas) in studio monitors, and how it will be in the headphones will most likely not even be checked.





It would seem that if you like it, you can always listen through the speakers. But alas, there are limitations: you want to listen to music in the office, in transport, or just late in the evening, when children / parents / neighbors have been sleeping for a long time. In addition, the cost of high-quality speaker systems is several times higher than the cost of high-quality headphones. And then there may still be a need for a separate amplifier, acoustic treatment of the room, etc. Sometimes there is simply no place for the speakers in the apartment ... With headphones, everything is easier.





What to do?

One minute! But when we listen to music through the speakers (or even sit in a concert hall), a very specific acoustic signal reaches each ear. So if you record this signal with a small microphone located inside each auricle, and then reproduce it through good headphones, we will get the same feeling of being in the hall. Except for the low-frequency signals felt by the chest. However, this is too complicated a procedure, although such recordings (they are called binaural) are sometimes made, and even sold.





And what if you play some test signal through the speakers, record it with these tiny microphones in your ears, determine how the signal was converted, and then similarly transform your favorite music before playing it through the headphones?





HRTF and HRIR

, , , , . . x(t). , . , , "" . , : , , , . . , , , , , , . , , XL(t), - XR(t). , : XL(t)=FL(x(t)) XR(t)=FR(x(t)).





, - - - - , , ( *), :





XL(t) = hL(t) * x(t) XR(t) = hR(t) * x(t),





hL(t) hR(t) - .





? , ( ). , 2003- IRCAM () . , , , , , , . . , . . Head-Related Impulse Response - . HRTF, .





, . IRCAM , , , 30 , FIR- . , …





, - Sennheizer, AKG, Beyerdynamic, Sony . . . - : "" "" . , . , "Harman Target Curves". , , "" , , . "" - , , . , HRTF.





, "" HRTF , - .





, - .





, : hR(t) hL(t). , "" HRTF ( hR(t) ) , , FR(), hR(t). , , XL(t) - . hcorr(t). : hcorr(t)*hR(t)*x(t)=hL(t)*x(t). hR(t), . ( ): hcorr(t)*hR(t)=hL(t).





, , , . . , - , . fft(). :

fft(hcorr(t)) ⋅ fft(hR(t)) = fft(hL(t))

( ).

, , :

fft(hcorr(t)) = fft(hL(t)) / fft(hR(t)).





( ), !





, , - , - . : .





, , , , , , .





, , , . . , .





: ( ) ( "target curve") - . , , . , , , . / .





, - - . - - , cross-feed. - . / . . , , , , "" . , , - ( ).





, , - Dolby Headphones. - foobar2000, Dolby. . -, . , ( ). , - . - . , , Dolby, , . , Windows. , , , , reverse-engineering, .





, - GitHub, - , . . , readme.md .





Matlab. , - GNU Octave. , .





, IRCAM. +-30 - , . -, , , (, ), , , , . IRC_1006_R_R0195_T030_P000.wav IRC_1006_R_R0195_T330_P000.wav, , , , - .





1006 - , 0195 - , 030/330 - (0 - , 90 , 180 - , 270 - ), 000 - . IRCAM xml- - , , , . . .





Direct impulse
Direct impulse
Opposite impulse
Opposite impulse

8192 , 44.1. 186, 63. , , ( 2 !) , . 1024..4096 . :





channel_idx = 1; % Channel index, used from input files: 1 - left, 2 - right
max_impulse_len = 4096;
[impulse, fs] = audioread(fname);
len = min(rows(impulse), max_impulse_len);
      
      



.





impulse = impulse(1 : len, channel_idx);
      
      



:





fft_div = fft(impulse_opposite) ./ fft(impulse_direct);
impulse_tf = real(ifft(fft_div));
      
      



- deconvolution system identification (. . ). , :





FFT deconvolution
FFT deconvolution

- :) , . , - . ... , , hcorr(t) * hR(t) = hL(t).

, " ":





plot(conv(impulsedirect, impulsetf)(1:4096) - impulseopposite);
      
      



FFT error
FFT error

, , . ...





. , : . , . - () -. Matlab, , ( , - ).





, :





LMS deconvolution
LMS deconvolution

" ":





LMS error
LMS error

, .





:





LMS deconvolution, zoomed-in
LMS deconvolution, zoomed-in

, . , , 20 ( ) :





lpf = remez(2 * round(fs / 600), [0 20000 / (fs / 2) 21000 / (fs / 2) 1], [1 1 0 0]); % For Matlab environment change "remez" to "firpm". 
filteredImpulse=conv(impulse_tf, lpf, 'same');
      
      



LMS deconvolution, LPF
LMS deconvolution, LPF

.

, . . , , .





, … , 8192 - , . - ! , , , .





, , , , , DRC, , . , DRC :)

, , ...





, . , :





avgDelay = round(median(grpdelay(impulse_tf)));
      
      



.





wnd = window(@blackman, 2 * (size(impulse_tf)(1) - avgDelay));
% Cut the window in size
wnd = flipud(wnd(1:size(impulse_tf)));
% Apply window
impulse_tf = impulse_tf .* wnd;
      
      



LMS deconvolution, LPF, windowing
LMS deconvolution, LPF, windowing

. . , 2..4 , . - . , .





( FFT). , , - ( ), :





. ( :)) - , . , , .





-, .





impulse_tf_stereo_L(:, 2) = impulse_tf;
impulse_tf_stereo_L(1, 1) = 1;
impulse_tf_stereo_R(:, 1) = impulse_tf;
impulse_tf_stereo_R(1, 2) = 1;
audiowrite(strcat(directory, fname_direct, '_TF_stereo_L.wav'), impulse_tf_stereo_L, fs);
audiowrite(strcat(directory, fname_direct, '_TF_stereo_R.wav'), impulse_tf_stereo_R, fs);
      
      



, . foobar2000 "Stereo Convolver". :





- , … , .





- IRCAM . - .





, . . .





- .





GNU Octave GitHub.





, . .












All Articles