Created
September 7, 2011 14:53
-
-
Save statistic-on-air/1200780 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PlayTel <- function(x=character){ | |
| # load package | |
| require(sound) | |
| # control if the input is a character | |
| if (!is.character(x)) stop("x must be a character") | |
| # split the input | |
| num <- strsplit(as.character(x), "") | |
| len <- length(num[[1]]) | |
| # create the sequence of time | |
| t <- seq(0, 0.2, length=44100 * 0.2) | |
| # control if all characters are in the group of those supported | |
| poss <- c("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "*", "#", "A", "a", "B", "b", "C", "c", "D", "d") | |
| if(prod(num[[1]] %in% poss) == 0) stop("Character not supported") | |
| # create a silence of 0.1 sec | |
| ts <- as.Sample(seq(0, 0.1, length=44100 * 0.1), 44100, 16) | |
| # create an empty list | |
| ll <- vector("list", length=len) | |
| # here are the frequencies of the tones =) | |
| t1 <- appendSample(as.Sample((sin(4379*t)+sin(7596*t))/2, 44100, 16), ts) | |
| t2 <- appendSample(as.Sample((sin(4379*t)+sin(8394*t))/2, 44100, 16), ts) | |
| t3 <- appendSample(as.Sample((sin(4379*t)+sin(9280*t))/2, 44100, 16), ts) | |
| t4 <- appendSample(as.Sample((sin(4838*t)+sin(7596*t))/2, 44100, 16), ts) | |
| t5 <- appendSample(as.Sample((sin(4838*t)+sin(8394*t))/2, 44100, 16), ts) | |
| t6 <- appendSample(as.Sample((sin(4838*t)+sin(9280*t))/2, 44100, 16), ts) | |
| t7 <- appendSample(as.Sample((sin(5353*t)+sin(7596*t))/2, 44100, 16), ts) | |
| t8 <- appendSample(as.Sample((sin(5353*t)+sin(8394*t))/2, 44100, 16), ts) | |
| t9 <- appendSample(as.Sample((sin(5353*t)+sin(9280*t))/2, 44100, 16), ts) | |
| t0 <- appendSample(as.Sample((sin(5912*t)+sin(8394*t))/2, 44100, 16), ts) | |
| tas <- appendSample(as.Sample((sin(5912*t)+sin(7596*t))/2, 44100, 16), ts) | |
| tca <- appendSample(as.Sample((sin(5912*t)+sin(9280*t))/2, 44100, 16), ts) | |
| ta <- appendSample(as.Sample((sin(4379*t)+sin(10260*t))/2, 44100, 16), ts) | |
| tb <- appendSample(as.Sample((sin(4838*t)+sin(10260*t))/2, 44100, 16), ts) | |
| tc <- appendSample(as.Sample((sin(5353*t)+sin(10260*t))/2, 44100, 16), ts) | |
| td <- appendSample(as.Sample((sin(5912*t)+sin(10260*t))/2, 44100, 16), ts) | |
| # full the list with the tone sequence | |
| for(i in 1:len){ | |
| if(num[[1]][i] == "1") ll[[i]] = t1 | |
| if(num[[1]][i] == "2") ll[[i]] = t2 | |
| if(num[[1]][i] == "3") ll[[i]] = t3 | |
| if(num[[1]][i] == "4") ll[[i]] = t4 | |
| if(num[[1]][i] == "5") ll[[i]] = t5 | |
| if(num[[1]][i] == "6") ll[[i]] = t6 | |
| if(num[[1]][i] == "7") ll[[i]] = t7 | |
| if(num[[1]][i] == "8") ll[[i]] = t8 | |
| if(num[[1]][i] == "9") ll[[i]] = t9 | |
| if(num[[1]][i] == "0") ll[[i]] = t0 | |
| if(num[[1]][i] == "*") ll[[i]] = tas | |
| if(num[[1]][i] == "#") ll[[i]] = tca | |
| if(num[[1]][i] == "A" | num[[1]][i] == "a") ll[[i]] = ta | |
| if(num[[1]][i] == "B" | num[[1]][i] == "b") ll[[i]] = tb | |
| if(num[[1]][i] == "C" | num[[1]][i] == "c") ll[[i]] = tc | |
| if(num[[1]][i] == "D" | num[[1]][i] == "d") ll[[i]] = td | |
| } | |
| # make sound | |
| s <- as.Sample(unlist(ll)) | |
| # make stereo sound | |
| sst <- stereo(s, s) | |
| sst | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment