This Crosstalk Cancellation Function kills my computer!
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dont run this function. but please tell me how to fix it! it is a very basic cross talk cancellation filter. It takes a little while to compute, less than a minute, then it outputs a .wav file into the Current Folder Window. THEN, if you attempt to open that file, inside matlab, outside in iTunes, wherever. Your computer will DIE!!! System overload, have to do a complete shutdown. I dont think there is much heavy computation to this function, in fact other functions I've written have been more computationally complex on the CPU. So this is a mystery to me why it isn't working properly. Any ideas?
code:
% FUNCTION DESCRIPTION
%
% XTalker
% function takes 2 channels of 3d surround audio and removes deleterious
% crosstalk signal. KEMAR HRTF impulse responses from
% http://sound.media.mit.edu/resources/KEMAR.html were used. For optimal
% results please listen through stereo speakers 2 to4 meters apart at 30 and 330
% degrees, 0 elevation, and 1.4 meters distance from your head. Also adds a 10 kHz
% lowpass filter to widen the sweet spot.
%
% Inputs:
% 1) INFile : Name of stereophonic .wav file needing xtalk
% 2) OUTFile : Name of xtalked .wav file to which the
% signal will be written
%
% Output:
% A crosstalk cancelled .wav file of the INFile named OUTFile
%
function XTalker( INfile, OUTfile )
% BASIC ERROR CHECKING
if ischar(INfile) == 0,
error('INfile input needs to be a string');
end
% number of arguments check.
if nargin ~= 2,
error('number of inputs is incorrect')
end
% READ THE FILES
% The function reads the input .wav file
[y, Fs] = wavread(INfile);
RChannel = y(:,1);
LChannel = y(:,2);
% Function makes sure the sampling rates match up. (The sampling rates of
% the files I provided and the KEMAR impulse responses line up at 44100.
% If user chooses to use different 3D input file, and or different HRTF IRs,
% please make sure they are of the same sampling rate.
if Fs ~= 44100
error('HRTF IR and signal sampling rates dont match');
end
% Check length of the signal channels to make sure they are the same
if length(LChannel) > length(RChannel);
zeropad = length(LChannel) - length(RChannel);
RChannel = [RChannel; zeros(zeropad, 1)];
end
if length(RChannel) > length(LChannel);
zeropad = length(RChannel) - length(LChannel);
LChannel = [LChannel; zeros(zeropad, 1)];
end
% Reads compact data file of + and - 30 degrees HRTF IRs from KEMAR.
fp = fopen('L0e030a.dat','r','ieee-be');
data = fread(fp, 256, 'short');
fclose(fp);
L2RIR = data(1:256);
L2RIRLength = length(L2RIR);
fp = fopen('L0e330a.dat','r','ieee-be');
data = fread(fp, 256, 'short');
fclose(fp);
L2LIR = data(1:256);
L2LIRLength = length(L2LIR);
fp = fopen('R0e030a.dat','r','ieee-be');
data = fread(fp, 256, 'short');
fclose(fp);
R2RIR = data(1:256);
R2RIRLength = length(R2RIR);
fp = fopen('R0e330a.dat','r','ieee-be');
data = fread(fp, 256, 'short');
fclose(fp);
R2LIR = data(1:256);
R2LIRLength = length(R2LIR);
% NORMALIZATION TO PREVENT CLIPPING AND MAKE STABLE FILTERS
% Find the maximum value of the samples in the stereo matrix
maxLChannel = max(abs(LChannel));
maxRChannel = max(abs(RChannel));
maxVec = [ maxLChannel , maxRChannel ]';
maxVal = max(maxVec);
% Normalize all samples in the stereo pair matrix to that maximum value sample.
y = y / 1.0001 * maxVal;
% Find the maximum value of the HRTF IR data points
L2RMax = max(abs(L2RIR));
L2LMax = max(abs(L2LIR));
R2LMax = max(abs(R2LIR));
R2RMax = max(abs(R2RIR));
maxiVec = [ L2RMax, L2LMax, R2LMax, R2RMax ]';
maxiVal = max(maxiVec);
% Normalize all HRTF IRs to the maximum value
L2RIR = L2RIR / 1.0001 * maxiVal;
L2LIR = L2LIR / 1.0001 * maxiVal;
R2LIR = R2LIR / 1.0001 * maxiVal;
R2RIR = R2RIR / 1.0001 * maxiVal;
% CONVOLVE SIGNALS WITH HRTF IMPULSE RESPONSES TO CREATE THEORETICAL SIGNAL
% OF WHAT YOUR EARS WOULD HEAR IF THE SIGNAL WAS PLAYED TRANSAURALLY
% convolve : take FFTs, multiply, take iffts
LC2RE = conv(L2RIR, LChannel); % alternate side CROSSTALK SIGNAL
LC2LE = conv(L2LIR, LChannel); % same side
RC2LE = conv(R2LIR, RChannel); % alternate side CROSSTALK SIGNAL
RC2RE = conv(R2RIR, RChannel); % same side
% CREATE ANTI PHASE SIGNALS OF CROSSTALK SIGNALS
XLC2RE = LC2RE * -1;
XRC2LE = RC2LE * -1;
% NOTE: ACCORDING TO THE KEMAR WEBSITE THE INTERAURAL TIME DELAY IS STILL
% PRESENT IN THE TWO EARS, SO THERE IS NO NEED TO ACCOUNT FOR THIS
% INFORMATION WHEN SENDING THE SIGNAL
% ADD ANTI PHASED CROSSTALK SIGNALS TO ALTERNATE CHANNELS
% find length of INFile channels
lengthCHANS = length(LChannel);
% find length of Convolved Signals
lengthCONVS = length(XLC2RE);
% zeropad channels
zeropad = lengthCONVS - lengthCHANS;
LChannel = [LChannel; zeros(zeropad, 1)];
RChannel = [RChannel; zeros(zeropad, 1)];
% Add signals
XLChannel = LChannel + XRC2LE;
XRChannel = RChannel + XLC2RE;
% ADD 10 kHz BUTTERWORTH FILTER TO WIDEN THE SWEET SPOT
Wn = 10000 / (Fs/2);
[b,a] = butter(10, Wn, 'low');
% filter audio
FXLChannel = filter(b, a, XLChannel);
FXRChannel = filter(b, a, XRChannel);
% FUNCTION OUTPUT
% Allocate left and right channel matrices.
MTXleft = zeros(length(FXLChannel), 1);
MTXright = zeros(length(FXRChannel), 1);
MTXleft = FXLChannel;
MTXright = FXRChannel;
outputMTX = [ MTXleft , MTXright ];
wavwrite ( outputMTX, Fs, OUTfile );
end
2 Commenti
Geoff
il 1 Mag 2012
Oh, just cottoned on to your 'system overload' quote... Um, how large is this file? How much RAM and virtual RAM do you have?
Geoff
il 2 Mag 2012
PS: When you post code in a question, please use the 'code' formatting button in the toolbar. Otherwise it comes out as a mess, my eyes glaze over, and I don't actually read it.
Risposte (2)
Geoff
il 1 Mag 2012
I wouldn't be surprised if iTunes takes your computer down.
Have you tried plotting the waveform in MatLab? Does it look sensible, or does it perhaps look like it would challenge your hardware?
Have you tried loading inside a program that actually understands audio files, such as Adobe Audition? (Trial version available from their website - don't know if this is available for Mac). Or maybe open-source Audacity which I think is cross-platform.
A data file like this shouldn't kill your computer, even if the audio is complete garbage, unless perhaps:
(A) You have a serious issue with your sound hardware;
(B) You have a dead or pokey RAM module, and your WAV just happens to get loaded into it;
(C) The WAV file is too large to fit in RAM but your OS is too stupid to realise;
(D) You're opening the file with sucky software (eg iTunes)
(E) The file has been written into a corrupted area of disk that freaks your OS out;
(F) The use of this crosstalk algorithm is banned by alien police from the 5th dimension.
4 Commenti
Michael
il 26 Gen 2015
First thing I'd make sure of it that the variable you're writing to the WAV file is all real. Either take the abs() or real() of it.
0 Commenti
Vedere anche
Categorie
Scopri di più su Audio Processing Algorithm Design in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!