How to verify whether a track is in mono or stereo?

19,137

Solution 1

One way to tell if a stereo-file has the same mono-track on both its channels is by phase-inverting one of the channels (for example, the left one) and then add it up with the other channel. (Therefore we're looking for the phase-coherence)

I don't use audacity very frequently, so I do not know if it is able to do such a thing, but here's a small FFmpeg-syntax that does what you want:

ffmpeg -i 'is_this_stereo.wav' -filter_complex "stereotools=phasel=1" -ac 1 'output.wav'

(Also works with other audio-codecs - outputting a lossless format like WAV ensures that the encoding doesn't delete anything)

What that FFmpeg-script does: It reverses the phase of the left channel, then sums up both channels in one new channel.

Instead of -ac 1, you could also alter the filter_complex-chain to stereotools=phasel=1[tmp];[tmp]pan=1c:c0=0.5*c0+0.5*c1. I don't think this is necessary, however.

If you then look at the newly created file, and you see a flat line in the waveform, then the left channel of the original file is exactly the same as the right one. If there are only very small peaks (say, around -60dB or less) then the difference probably is just caused by encoding artifacts - just listen to it to be sure.

Code sources:

Solution 2

As mentioned in the comments, there is a fundamental difference between a stereo file and a stereo recording.

Nothing stops us from creating a file, that has both stereo channels fed from a single audio source - this is e.g. Standard for old recordings remastered for CD.

The typical way to get an idea of whether a stereo file actually contains sterophonic content is to calculate the quadratic sum of the number of zero-passes per second on both channels. I do not know, if Audacity or other free software tools have this bilt-in.

Turns out, that the human eye is quite good in spotting channel differences, so if the number of recordings to check is low, a wave graph (as produced by audacity) should give you a good feel, whether this is stereophonic or not.

Solution 3

I prefer to let computers do the dull work, so starting from flolilo's answer, I ended up with:

ffmpeg -i is_this_stereo.wav -filter_complex 'pan=mono|c0=0.5*FL+-0.5*FR,silenceremove=start_periods=1' -f null -

This shows a warning "Output file is empty, nothing was encoded" if the input file's channels are exact replicas (which they are for at least one of my CDs). You could relax the silenceremove filter to ignore some noise, for instance silenceremove=start_periods=1:start_threshold=0.02 or start_threshold=-17dB, but that relative amplitude is relative to the PCM capability, not relative to the recording level. For some of my CDs, this value filters out subtle but quite audible stereo; for others, it's about the minimum.

The -f null - part simply suppresses file output, in case the console message is enough, but of course you can let it write the difference file. To check the mono-ness in a script, the best I come up with is:

out=$(ffmpeg -nostdin -loglevel error -i "$infile" -filter_complex 'pan=mono|c0=0.5*FL+-0.5*FR,silenceremove=start_periods=1:detection=peak' -t 0.00002 -f crc -)
if [ "$out" == 'CRC=0x00000001' ]
then echo "$infile is definitely mono"
fi

In that script fragment:

  • Time limit -t 0.00002 cuts the difference down to a single sample (for standard 44,100 samples/second CD contents), which greatly speeds up the detection in stereo files. -frames 1 results in the same, on my system, but I'm not sure it's supposed to because a frame contains more than one sample. -fs 1 goes relatively far beyond one byte.
  • -f crc writes the output as something ASCII, which is way easier to handle in a script. If one 16 bit sample makes it through the silence remover, the 32 bit CRC has to change from its initial value of 1, I think. Could also use -f md5 or -f hash.
  • Assigning out separately, instead of in the test below it, ensures that the script stops on error if you use the shell's -e option.
Share:
19,137

Related videos on Youtube

user598527
Author by

user598527

If I haven't accepted your correct answer I likely haven't yet been able to verify it — I only mark answers as accepted when either a reliable source is provided or I'm capable confirming myself. Additionally in some questions there can be multiple equally great answers, please also keep this in mind.

Updated on September 18, 2022

Comments

  • user598527
    user598527 over 1 year

    Sometimes I have to verify using a reputable method if an audio track is recorded in mono or stereo, especially when researching older music albums.
    I have a reason to believe that Audacity doesn't tell this when opening a file (2009 mono remaster of Please Please Me by The Beatles is displayed as stereo).

    • Admin
      Admin almost 7 years
      by "mono", it's quite possible that this means the same signal is mixed to both left and right channels. This might be done in order to ensure that both left and right speakers get signal
    • Admin
      Admin almost 7 years
      @Blaine's comment kind of suggests that this question might be impossible to solve as you'll never be able to identify whether the original was recorded in mono, stereo or whether the "mix" was one channel of an originally stereo-recorded song...
    • Admin
      Admin almost 7 years
      Not saying i know of a way to do it, but a potential solution would be to somehow compare the right channel and left and check if they are identical or not
    • Admin
      Admin almost 7 years
      @Kinnectus: It doesn't matter in what format the original album was recorded, that is outside the scope of this question. But as explained in Blaine's comment, I now understand that potentially "the same signal is mixed to both left and right channels" - therefore technically stereo, but practically mono.
    • Admin
      Admin almost 7 years
      @Blaine: I'm considering asking about comparing channels in Audacity as a follow-up question.
    • Admin
      Admin almost 7 years
      Does Audacity have a function of subtracting one channel from another? If (left - right) != 0, it's a stereo recording. (Although not necessarily originally recorded as stereo, in the era of algorithms...)
    • Admin
      Admin almost 7 years
    • Admin
      Admin almost 7 years
      Please do not double post: superuser.com/questions/1218450/…
    • Admin
      Admin almost 7 years
      @Xavierjazz: It is a different question. This one has been resolved.
  • user598527
    user598527 almost 7 years
    Audacity can't open the output file, "file could not be found error": i.imgur.com/hKnYnaI.png
  • flolilo
    flolilo almost 7 years
    you have to use a "proper" path (meaning: one that your account can read/write to), for example C:\Users\<yourname>\Desktop\testfile.wav
  • user598527
    user598527 almost 7 years
    Thank you, works now! This is how the file looks in Audacity, a flat waveform: i.imgur.com/mQkBtYz.png
  • flolilo
    flolilo almost 7 years
    You're welcome. Two things: 1) I would suggest you use "waveform (dB)" for waveform representation: imgur.com/a/5WcRr 2) I would change the dB range to at least -72 in the settings: imgur.com/a/7WVxl . If you then still can't see (and, more importantly: hear) anything, then it most certainly is a stereo-file with the same mono-track on both channels.
  • user598527
    user598527 about 5 years
    I'm unaccepting this since others have answered the question.
  • KeyC0de
    KeyC0de over 4 years
    @flolilo I get the errror: [AVFilterGraph @ 0074ea00] No such filter: 'stereotools' Error configuring filters. Conversion failed! Any ideas?
  • person27
    person27 over 4 years
    @user598527 Please accept an answer since some time has passed :)
  • user598527
    user598527 over 4 years
    @person27: I found it difficult to verify these methods. I hope that SE adds community-accepted answers.