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.

108 lines
3.0KB

  1. #!/bin/bash
  2. # Script to bridge/start pulseaudio into loopback 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. case $1 in
  41. -h|--h|--help)
  42. echo "usage: $0 [command]
  43. -p, --play Playback mode only
  44. -h, --help Show this help menu
  45. --dummy Don't do anything, just create the needed files
  46. NOTE:
  47. When runned with no arguments, pulse2jack will
  48. activate PulseAudio with both playback and record modes.
  49. "
  50. exit
  51. ;;
  52. --dummy)
  53. exit
  54. ;;
  55. -p|--p|--play)
  56. FILE=$INSTALL_PREFIX/share/cadence/pulse2loopback/play.pa
  57. ;;
  58. *)
  59. FILE=$INSTALL_PREFIX/share/cadence/pulse2loopback/play+rec.pa
  60. ;;
  61. esac
  62. # ----------------------------------------------
  63. IsPulseAudioRunning()
  64. {
  65. PROCESS=`ps -u $USER | grep pulseaudio`
  66. if [ "$PROCESS" == "" ]; then
  67. false
  68. else
  69. true
  70. fi
  71. }
  72. if (IsPulseAudioRunning); then
  73. {
  74. echo "PulseAudio is already running, make sure it outputs to Loopback"
  75. pactl load-module module-alsa-source source_name=input_loopback device=hw:Loopback > /dev/null
  76. pactl load-module module-alsa-sink sink_name=output_loopback device=hw:Loopback > /dev/null
  77. pacmd set-default-source input_loopback > /dev/null
  78. pacmd set-default-sink output_loopback > /dev/null
  79. echo "Done"
  80. }
  81. else
  82. {
  83. if (`pulseaudio --daemonize --high-priority --realtime --exit-idle-time=-1 --file=$FILE -n`); then
  84. echo "Initiated PulseAudio successfully!"
  85. else
  86. echo "Failed to initialize PulseAudio!"
  87. fi
  88. }
  89. fi