# How is the 'difference' of two audio tracks best computed, in order to maximise instrument isolation?

I'm hoping to improve the results of a simple application I've been working on, which aims to isolate as fully as possible the electric guitar heard (along with drums/bass/vocals) on a single track of a commercially available 5.1 mix. It was inspired by the observation that simply inverting the content of another track ('nonGuitarTrack', containing only drums/bass/vocals) and adding it to 'guitarTrack' gets quite some way toward this goal, and that a better result can be achieved by manually adjusting the amplitude of the subtracted track so that as much unwanted audio as possible is removed from the sum.

Initially, the application output the gain factor that minimized the RMS amplitude of

guitarTrack - (gain factor) * nonGuitarTrack

and produced pleasing results for carefully selected input of a few seconds duration.

I then tired of processing songs a few seconds at a time, and so the program now both consumes and produces song-length WAV files. It does this by processing the input samples in clusters of (say) 0.1s duration. It seems to my naive mind that the best result is to be obtained by lowering the cluster size until the result begins to sound bad (e.g. 2k clusters with 96kHz audio results in 'crackling'). Results were again generally pleasing, although occasionally audibly sub-optimal.

Was the placement of cluster boundaries at fault? I got to work on a new (perhaps impracticably expensive) version that will perform a 'pass' for every possible placement of this boundary, and then combine the result of each pass in some sensible fashion - which brings me here.

Should each sample in the resulting WAV file be the mean of the samples computed in each pass? Should it simply be the minimal value computed? Would fewer passes be needed if using clusters of constantly varying random size? Perhaps a better approach would average the results of using cluster sizes of $$2^{n}$$ for $$n = 1, 2, \ldots, 12$$? My knowledge of statistics is very dismal, and I'd be very grateful for any advice re how to best combine multiple passes, or indeed re how isolation in this easy case is best achieved.

(The waveforms of both input files clearly depict when a bass or snare is struck. Ideally, the program would perhaps use beat detection and employ variable-sized clusters formed during- and between beats; currently, I shudder to think how the loud samples during a beat skew the RMS volume of a beat-straddling cluster. Beat detection is something I hope to avoid investigating, but if audibly superior results are likely then I'll have no excuse.)

• If those two tracks are from same mix then time align them if needed and turn phase 180 degrees for the 2nd track should work but if those tracks are from different mix then you're on your own with a lot of manual editing (maybe with a spectral editor) to get instruments well isolated. Commented Feb 13, 2022 at 6:31
• I believe that this case falls in the field Blind Source Separation where there's some techniques for separating two sources without much prior knowledge about them. One method in the field is Independent Component Analysis but there's way more than that. I am not an expert in the field so I can't provide an educated answer. Additionally, I believe I've encountered a couple of methods utilising Neural Networks to do the job. I am not sure how much training they need or if you can find some "pre-trained" models for your case. Commented Feb 14, 2022 at 9:21
• Here are some tools you maybe find information of techniques used by reading their documentations : startingtodj.com/… and here are couple sources of methods @ZaellixA suggests : se.mathworks.com/matlabcentral/… , se.mathworks.com/matlabcentral/… , Commented Feb 14, 2022 at 11:39
• not sure whether I've underestimated the complexity of the channel-subtraction approach or whether my question was just unintelligible. I feel that the inputs are close-to ideal and that this has to be one of the easiest 'source separation' situations imaginable. The question really boils down perhaps to how to chop up a song into louder sections (in which e.g. a snare or bass drum is hit) and quieter sections, or how to avoid having to perform this 'optimal' chopping by combining multiple non-optimally-chopped passes in some sensible way... Commented Feb 14, 2022 at 21:45