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.

124 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. NOTE:
  47. When runned with no arguments, pulse2jack will
  48. activate PulseAudio with both playback and record modes.
  49. "
  50. exit
  51. ;;
  52. -p|--p|--play)
  53. PLAY_ONLY="yes"
  54. FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play.pa
  55. ;;
  56. *)
  57. FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play+rec.pa
  58. ;;
  59. esac
  60. # ----------------------------------------------
  61. IsPulseAudioRunning()
  62. {
  63. PROCESS=`ps -e | grep pulseaudio`
  64. if [ "$PROCESS" == "" ]; then
  65. false
  66. else
  67. true
  68. fi
  69. }
  70. if (IsPulseAudioRunning); then
  71. {
  72. if (`jack_lsp | grep "PulseAudio JACK Sink:" > /dev/null`); then
  73. {
  74. echo "PulseAudio is already running and bridged to JACK"
  75. }
  76. else
  77. {
  78. echo "PulseAudio is already running, bridge it..."
  79. if [ "$PLAY_ONLY" == "yes" ]; then
  80. {
  81. pactl load-module module-jack-sink > /dev/null
  82. pacmd set-default-source jack_in > /dev/null
  83. }
  84. else
  85. {
  86. pactl load-module module-jack-sink > /dev/null
  87. pactl load-module module-jack-source > /dev/null
  88. pacmd set-default-sink jack_out > /dev/null
  89. pacmd set-default-source jack_in > /dev/null
  90. }
  91. fi
  92. echo "Done"
  93. }
  94. fi
  95. }
  96. else
  97. {
  98. if (`pulseaudio --daemonize --high-priority --realtime --disallow-module-loading --exit-idle-time=-1 --file=$FILE -n`); then
  99. echo "Initiated PulseAudio successfully!"
  100. else
  101. echo "Failed to initialize PulseAudio!"
  102. fi
  103. }
  104. fi