record_tetraproc_b_format 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/python
  2. #
  3. # PyEcasound Control Script
  4. #
  5. # Play back A format files (already trimmed and windowed) from disk to
  6. # the inputs of TetraProc, and at the same time record B format data from
  7. # the output of TetraProc to a disk file.
  8. #
  9. # As ecasound does not recognize the input soundfiles written by octave,
  10. # they are converted first to 24 bit PCM using sndfile-convert
  11. #
  12. #
  13. # Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
  14. # nando@ccrma.stanford.edu
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. import time
  29. from ecacontrol import *
  30. from subprocess import *
  31. e = ECA_CONTROL_INTERFACE()
  32. e.command("cs-add tetraproc_process")
  33. status = e.command("c-add AF_play")
  34. status = e.command("c-add BF_record")
  35. print(status)
  36. ## new chain for A-format playback
  37. print(e.command("c-select AF_play"))
  38. print("== starting jack output...")
  39. print(e.command("cs-set-audio-format ,4,48000"))
  40. print(e.command("ao-add jack_multi,tetraproc:A-form.1(LF),tetraproc:A-form.2(RF),tetraproc:A-form.3(LB),tetraproc:A-form.4(RB)"))
  41. ## new chain for B-format recording
  42. print(e.command("c-select BF_record"))
  43. print("== starting jack input...")
  44. print(e.command("cs-set-audio-format ,4,48000"))
  45. print(e.command("ai-add jack_multi,tetraproc:B-form.W,tetraproc:B-form.X,tetraproc:B-form.Y,tetraproc:B-form.Z"))
  46. ## start processing
  47. for measurement in range(1, 17):
  48. m = "%0.3d" % (measurement)
  49. print("==== processing measurement %d" % (measurement))
  50. ## convert soundfile to format needed by ecasound
  51. os.system("sndfile-convert -pcm24 ../data/current/af/a-format-cal-" + m + ".wav " +
  52. " ../data/current/af/a-format-cal-" + m + "-pcm24.wav ")
  53. ## set up file playbak
  54. print(e.command("c-select AF_play"))
  55. print("== reading soundfile...")
  56. print(e.command("ai-add ../data/current/af/a-format-cal-" + m + "-pcm24.wav"))
  57. ## set up file recording
  58. print(e.command("c-select BF_record"))
  59. print("== writing soundfile...")
  60. print(e.command("ao-add ../data/current/bf-tetraproc/b-format-" + m + ".wav"))
  61. ## start jack...
  62. print(e.command("engine-launch"))
  63. time.sleep(0.25)
  64. print(e.command("start"))
  65. print("== waiting...")
  66. time.sleep(1.0)
  67. print("== woke up")
  68. e.command("stop")
  69. print("== stopped")
  70. ## remove old chains
  71. # (this prints an error but seems to work anyway)
  72. print("== remove objects")
  73. print(e.command("ao-select ../data/current/bf-tetraproc/b-format-" + m + ".wav"))
  74. print(e.command("ao-remove"))
  75. ## wait a little bit...
  76. time.sleep(0.5)
  77. #print(e.command("aio-status"))
  78. ## done with processing
  79. e.command("cs-disconnect")
  80. print("== disconnected!")
  81. ## remove all temporary files
  82. for measurement in range(1, 17):
  83. m = "%0.3d" % (measurement)
  84. print("==== removing %d" % (measurement))
  85. os.system("rm -f ../data/current/af/a-format-" + m + "-pcm24.wav")
  86. print("== done")