library(sound) dyn.load("steganography.so") stegaBits <- function(sonido,bits=0,porcentaje=100,accion=0) { # sonido: Sample a modificar # bits: cantidad de bits menos significativos a modificar # porcentaje: relación de la muestras que a modificar. Se distribuyen de manera uniforme. # accion: 0riza (0), 1riza(1) o random(2). # devuelve un Sample con las muestras en integer modificadas. return(as.Sample(.C("bits", sonido[["sound"]], length(sonido[["sound"]]),as.integer(bits),as.integer(porcentaje),as.integer(accion))[[1]],sonido$rate,sonido$bits)) } loadSampleAsBits <- function(filename,filecheck=TRUE) { #Copiado, con pequeñas modificaciones, de "sound,loadSample()" if (!is.null(class(filename)) && class(filename)=="Sample") return(filename) if (mode(filename)!="character") stop("Argument 'filename' must be a character string.") if (substr(filename,nchar(filename)-3,nchar(filename))!=".wav") stop("Filename must have the extension .wav.") if (filecheck){ if (file.access(filename)==-1) stop("File not found.") if (file.access(filename,4)==-1) stop("No read permission for this file.") } fileR <- file(filename,"rb") if(readChar(fileR, nchars=4) != 'RIFF') stop("File is not RIFF format.") readBin(fileR, "integer", n = 4, size = 1) if(readChar(fileR, nchars=4) != 'WAVE') stop("File is not WAVE format.") readBin(fileR,"integer",n=10,size=1) channels <- readBin(fileR,"integer", size=2, endian='little') rate <- readBin(fileR,"integer", size=4, endian='little') readBin(fileR,"integer",n= 6,size=1) bits <- readBin(fileR,"integer", size=2, endian='little') readBin(fileR,"integer",n= 4,size=1) Length <- readBin(fileR,"integer", size=4, endian='little') if (bits==8) data <- readBin(fileR,"integer",n=Length ,size=1,signed=FALSE, endian='little') else data <- readBin(fileR,"integer",n=Length/2,size=2,signed=TRUE , endian='little') close(fileR) if (channels==2) dim(data) <- c(channels,length(data)/channels) return(as.Sample(data,rate,bits)) } stegaSampleAsDouble <- function (sonido) { if (sonido$bits==8) sonido$sound <- sonido$sound/128-1 else sonido$sound <- sonido$sound/32768 return(sonido) } stegaSampleAsBits <- function (sonido) { canales=channels(sonido) if (sonido$bits==8) sonido$sound <- as.integer((sonido$sound+1)*128) else sonido$sound <- as.integer(sonido$sound*32768) if (canales==2) dim(sonido$sound) <- c(canales,length(sonido$sound)/canales) return(sonido) }