sphear_h2n_process_recording 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. #
  3. # Convert a raw X/Y M/S H2n recording into a four channel A-format soundfile
  4. #
  5. # Copyright Fernando Lopez-Lezcano 2016
  6. # nando@ccrma.stanford.edu
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. if [ "$1" == "" ] ; then
  21. echo "usage: sphear_h2n_process_recording PATH/FILEPREFIX (SR00x where x is the recording number)"
  22. exit 1
  23. else
  24. BASENAME=$1;
  25. fi
  26. XYFILE=${BASENAME}XY.WAV
  27. MSFILE=${BASENAME}MS.WAV
  28. if [ ! -r ${XYFILE} ] ; then
  29. echo "ERROR: could not find ${XYFILE}!"
  30. exit 1
  31. fi
  32. if [ ! -r ${MSFILE} ] ; then
  33. echo "ERROR: could not find ${MSFILE}!"
  34. exit 1
  35. fi
  36. # extract the directory path of the files
  37. DIRNAME=`dirname $XYFILE`
  38. # process XY
  39. echo "processing XY files..."
  40. sox ${XYFILE} ${DIRNAME}/a-format-4.wav remix 1
  41. sox ${XYFILE} ${DIRNAME}/a-format-3.wav remix 2
  42. # process MS and convert to individual mono files
  43. echo "processing MS files..."
  44. sox ${MSFILE} ${DIRNAME}/a-format-MSL.wav remix 1 gain
  45. sox ${MSFILE} ${DIRNAME}/a-format-MSR.wav remix 2 gain 2.0
  46. # invert R
  47. sox ${DIRNAME}/a-format-MSR.wav ${DIRNAME}/a-format-MSRI.wav remix 1i0
  48. # M = L + R / 2
  49. sox --combine mix ${DIRNAME}/a-format-MSL.wav ${DIRNAME}/a-format-MSR.wav ${DIRNAME}/a-format-1.wav gain 0.5
  50. # S = (L - R) / 2
  51. sox --combine mix ${DIRNAME}/a-format-MSL.wav ${DIRNAME}/a-format-MSRI.wav ${DIRNAME}/a-format-2.wav gain 0.5
  52. # create a four channel A-format file
  53. echo "creating AF file..."
  54. AFFILE=`echo ${BASENAME}|sed 's|SR|AF|g'`
  55. sox -M ${DIRNAME}/a-format-1.wav ${DIRNAME}/a-format-2.wav ${DIRNAME}/a-format-3.wav ${DIRNAME}/a-format-4.wav ${AFFILE}.WAV
  56. echo "-- removing temporary files..."
  57. rm -f ${DIRNAME}/a-format-*.wav
  58. echo "-- done"