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.

140 lines
3.7KB

  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. if test -n "${CADENCE_PULSE2JACK_PLAY}"; then
  59. FILE="$CADENCE_PULSE2JACK_PLAY"
  60. elif test -f ~/.config/Cadence/pulse2jack/play.pa; then
  61. FILE=~/.config/Cadence/pulse2jack/play.pa
  62. else
  63. FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play.pa
  64. fi
  65. ;;
  66. *)
  67. if test -n "${CADENCE_PULSE2JACK_PLAYREC}"; then
  68. FILE="$CADENCE_PULSE2JACK_PLAYREC"
  69. elif test -f ~/.config/Cadence/pulse2jack/play+rec.pa; then
  70. FILE=~/.config/Cadence/pulse2jack/play+rec.pa
  71. else
  72. FILE=$INSTALL_PREFIX/share/cadence/pulse2jack/play+rec.pa
  73. fi
  74. ;;
  75. esac
  76. # ----------------------------------------------
  77. IsPulseAudioRunning()
  78. {
  79. PROCESS=`ps -u $USER | grep pulseaudio`
  80. if [ "$PROCESS" == "" ]; then
  81. false
  82. else
  83. true
  84. fi
  85. }
  86. if (IsPulseAudioRunning); then
  87. {
  88. if (`jack_lsp | grep "PulseAudio JACK Sink:" > /dev/null`); then
  89. {
  90. echo "PulseAudio is already running and bridged to JACK"
  91. }
  92. else
  93. {
  94. echo "PulseAudio is already running, bridge it..."
  95. if [ "$PLAY_ONLY" == "yes" ]; then
  96. {
  97. pactl load-module module-jack-sink > /dev/null
  98. pacmd set-default-source jack_in > /dev/null
  99. }
  100. else
  101. {
  102. pactl load-module module-jack-sink > /dev/null
  103. pactl load-module module-jack-source > /dev/null
  104. pacmd set-default-sink jack_out > /dev/null
  105. pacmd set-default-source jack_in > /dev/null
  106. }
  107. fi
  108. echo "Done"
  109. }
  110. fi
  111. }
  112. else
  113. {
  114. if (`pulseaudio --daemonize --high-priority --realtime --exit-idle-time=-1 --file=$FILE -n`); then
  115. echo "Initiated PulseAudio successfully!"
  116. else
  117. echo "Failed to initialize PulseAudio!"
  118. fi
  119. }
  120. fi