Identify HD music tracks (Quick ‘n’ dirty Bash script)

I’m building a library of HD music tracks and decided that it would be nice if it was in a separate folder from all my other music. Since I can’t remember what I have and where it’s located I’ve conjured up a quick ‘n’dirty Bash script to recursively scan a folder tree and produce two lists of SD and HD tracks.

HD is defined, for these purposes, as having a 24bit sample depth, irrespective of sample rate, but obviously using soxi’s other options (e.g. soxi -r) sample rates can be determined and acted upon accordingly.

It’s presented as is, with no comments, hope it’s useful to someone: –

#! /bin/bash
red=`tput setaf 1` 
green=`tput setaf 2` 
reset=`tput sgr0` 
find . -type f -name '*.flac' -print0 | while IFS= read -r -d '' file 
   bitdepth=$(soxi -b "$file") 
   if [ "$bitdepth" = "24" ] 
       echo "${red} $file " has a bitdepth of " $bitdepth " bits"${reset}" >> HD_tracks.txt 
       echo "${red} $file " has a bitdepth of " $bitdepth " bits"${reset}" 
       echo "${green} $file " has a bitdepth of " $bitdepth " bits"${reset}" >> SD_tracks.txt 
       echo "${green} $file " has a bitdepth of " $bitdepth " bits"${reset}" 


This entry was posted in Linux, Music, Technical. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.