File: sine.sh

package info (click to toggle)
openvlbi 3.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,524 kB
  • sloc: ansic: 21,182; cpp: 4,119; sh: 141; makefile: 5
file content (25 lines) | stat: -rwxr-xr-x 673 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash

tao=$1
type=$2
duration=$3
max=127
i=0
k=0
printf $(while (( $k<$duration )); do
i=$(( $k%$tao ))
if [ "$type"=="triwave" ]; then
    if (( $i<$(( $tao/2 )) )); then
        printf "\\%02x" "$(( $i*$max/$(( $tao/2 )) ))"
    else
        printf "\\%02x" "$(( $max*2-$i*$max/$(( $tao/2 )) ))"
    fi
elif [ "$type"=="sinewave" ]; then
    printf "\\%02x" $(echo "x = (s($i*3.1415/$tao)*$max)+$(( $max/2-1 )); scale = 0; x / 1" | bc -l)
elif [ "$type"=="quadwave" ]; then
    printf "\\%02x" $(echo "x = (sqrt(s($i*3.1415/$tao))*$max)+$(( $max/2-1 )); scale = 0; x / 1" | bc -l)
elif [ "$type"=="random" ]; then
    head -c 1 /dev/urandom
fi
k=$(( $k+1 ))
done)