Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.3KB

  1. #!/bin/bash
  2. # Script to bridge/start pulseaudio into JACK mode
  3. INSTALL_PREFIX="X-PREFIX-X"
  4. # ----------------------------------------------
  5. if [ ! -d ~/.pulse ]; then
  6. mkdir -p ~/.pulse
  7. fi
  8. if [ ! -f ~/.pulse/client.conf ]; then
  9. echo "autospawn = no" > ~/.pulse/client.conf
  10. else
  11. if (! cat ~/.pulse/client.conf | grep "autospawn = no" > /dev/null); then
  12. sed -i '/autospawn =/d' ~/.pulse/client.conf
  13. echo "autospawn = no" >> ~/.pulse/client.conf
  14. fi
  15. fi
  16. if [ ! -f ~/.pulse/daemon.conf ]; then
  17. echo "default-sample-format = float32le" > ~/.pulse/daemon.conf
  18. echo "realtime-scheduling = yes" >> ~/.pulse/daemon.conf
  19. echo "rlimit-rttime = -1" >> ~/.pulse/daemon.conf
  20. echo "exit-idle-time = -1" >> ~/.pulse/daemon.conf
  21. else
  22. if (! cat ~/.pulse/daemon.conf | grep "default-sample-format = float32le" > /dev/null); then
  23. sed -i '/default-sample-format = /d' ~/.pulse/daemon.conf
  24. echo "default-sample-format = float32le" >> ~/.pulse/daemon.conf
  25. fi
  26. if (! cat ~/.pulse/daemon.conf | grep "realtime-scheduling = yes" > /dev/null); then
  27. sed -i '/realtime-scheduling = /d' ~/.pulse/daemon.conf
  28. echo "realtime-scheduling = yes" >> ~/.pulse/daemon.conf
  29. fi
  30. if (! cat ~/.pulse/daemon.conf | grep "rlimit-rttime = -1" > /dev/null); then
  31. sed -i '/rlimit-rttime =/d' ~/.pulse/daemon.conf
  32. echo "rlimit-rttime = -1" >> ~/.pulse/daemon.conf
  33. fi
  34. if (! cat ~/.pulse/daemon.conf | grep "exit-idle-time = -1" > /dev/null); then
  35. sed -i '/exit-idle-time =/d' ~/.pulse/daemon.conf
  36. echo "exit-idle-time = -1" >> ~/.pulse/daemon.conf
  37. fi
  38. fi
  39. # ----------------------------------------------
  40. PLAY_ONLY="no"
  41. case $1 in
  42. -h|--h|--help)
  43. echo "usage: $0 [command]
  44. -p, --play Playback mode only
  45. -h, --help Show this help menu
  46. --dummy Don't do anything, just create the needed files
  47. NOTE:
  48. When runned with no arguments, pulse2jack will
  49. activate PulseAudio with both playback and record modes.
  50. "
  51. exit
  52. ;;
  53. --dummy)
  54. exit
  55. ;;
  56. -p|--p|--play)
  57. PLAY_ONLY="yes"
  58. FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play.pa
  59. ;;
  60. *)
  61. FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play+rec.pa
  62. ;;
  63. esac
  64. # ----------------------------------------------
  65. IsPulseAudioRunning()
  66. {
  67. PROCESS=`ps -u $USER | grep pulseaudio`
  68. if [ "$PROCESS" == "" ]; then
  69. false
  70. else
  71. true
  72. fi
  73. }
  74. if (IsPulseAudioRunning); then
  75. {
  76. if (`jack_lsp | grep "PulseAudio JACK Sink:" > /dev/null`); then
  77. {
  78. echo "PulseAudio is already running and bridged to JACK"
  79. }
  80. else
  81. {
  82. echo "PulseAudio is already running, bridge it..."
  83. if [ "$PLAY_ONLY" == "yes" ]; then
  84. {
  85. pactl load-module module-jack-sink > /dev/null
  86. pacmd set-default-source jack_in > /dev/null
  87. }
  88. else
  89. {
  90. pactl load-module module-jack-sink > /dev/null
  91. pactl load-module module-jack-source > /dev/null
  92. pacmd set-default-sink jack_out > /dev/null
  93. pacmd set-default-source jack_in > /dev/null
  94. }
  95. fi
  96. echo "Done"
  97. }
  98. fi
  99. }
  100. else
  101. {
  102. if (`pulseaudio --daemonize --high-priority --realtime --exit-idle-time=-1 --file=$FILE -n`); then
  103. echo "Initiated PulseAudio successfully!"
  104. else
  105. echo "Failed to initialize PulseAudio!"
  106. fi
  107. }
  108. fi