metalx1000

Noise-O-Tron Noise Maker

Jul 18th, 2020
989
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2020  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #Noise-O-tron
  7. #makes noise from keypresses to dsp audio hardware
  8.  
  9. #This program is free software: you can redistribute it and/or modify
  10. #it under the terms of the GNU General Public License as published by
  11. #the Free Software Foundation, either version 3 of the License, or
  12. #(at your option) any later version.
  13.  
  14. #This program is distributed in the hope that it will be useful,
  15. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #GNU General Public License for more details.
  18.  
  19. #You should have received a copy of the GNU General Public License
  20. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. ######################################################################
  22.  
  23. # Inspired by code written by: Antonio Macchi
  24. # https://www.tldp.org/LDP/abs/html/devref1.html
  25.  
  26. duration=1000      
  27. volume=$'\xc0'      
  28. mute=$'\x80'
  29.  
  30. function main(){
  31.   echo "Press Keys on Keyboard"
  32.   echo "(ASCII Characters) - Press Enter to exit."
  33.   while [ 1 ];do
  34.     read -n 1 n
  35.     n="$(ord $n)"
  36.     [[ $n == 0 ]]&& exit
  37.     n="$(note $n)"
  38.     echo -n "$n" > /dev/dsp
  39.   done
  40. }
  41.  
  42. function note(){
  43.   for i in `seq 0 $duration`
  44.   do
  45.     [ $(( $i % $1 )) -eq 0 ] && echo -n $volume || echo -n $mute
  46.   done
  47. }
  48.  
  49. function ord() {
  50.   LC_CTYPE=C printf '%d' "'$1"
  51. }
  52.  
  53. main
RAW Paste Data