################################################################################
## AUDIOMOTH
################################################################################
audiomoth <- function(x, # a character vector, not a Wave object
tz = "" # a character vector defining a time zone specification, see as.POSIXct(), argument 'tz'
)
{
## INPUT
if (!is.character(x)) stop("'x' should be of mode character.")
## PREPARE RESULTS
options(stringsAsFactors = FALSE)
res <- data.frame(year = numeric(0), month = numeric(0), day = numeric(0),
hour = numeric(0), min = numeric(0), sec = numeric(0),
time = numeric(0))
N <- length(x) ## number of file names
## LOOP
for (i in 1:N)
{ tmp <- x[i]
n <- nchar(tmp)
## check if .WAV or .wav file
extension <- substr(tmp, start = n-3, stop = n)
if(extension != ".wav" & extension != ".WAV"){warning(paste("File '", tmp, "' is not a '.wav' file", sep=""))}
else{
if(nchar(tmp)==12) ## hexadecimal format
{
hex <- unlist(strsplit(tmp, extension))
num <- strtoi(hex, base = 16)
time <- as.POSIXct(num, tz=tz, origin = "1970-01-01") ## POSIXct as in songmeter()
year <- as.numeric(format(time, "%Y"))
month <- as.numeric(format(time, "%m"))
day <- as.numeric(format(time, "%d"))
hour <- as.numeric(format(time, "%H"))
min <- as.numeric(format(time, "%M"))
sec <- as.numeric(format(time, "%S"))
}
else if(nchar(tmp)==19) ## YYYYMMDD_HHMMSS.wav format
{ print(tmp)
year <- substr(tmp, start = 1, stop = 4)
month <- substr(tmp, start = 5, stop = 6)
day <- substr(tmp, start = 7, stop = 8)
hour <- substr(tmp, start = 10, stop = 11)
min <- substr(tmp, start = 12, stop = 13)
sec <- substr(tmp, start = 14, stop = 15)
time <- strptime(paste(year,month,day,hour,min,sec), "%Y%m%d%H%M%S")
}
res <- rbind(res, data.frame(year, month, day, hour, min, sec, time))
}
}
return(res)
options(stringsAsFactors = TRUE)
}
dir <- "F:/WavFiles"
print(audiomoth(dir(dir, pattern="[wav]$|[WAV]$")))
You see what lts passeswhich will in my case result to the decoding routine. Maybe your 'debugging' printout gives an indication. It could be that some (sub)
> source("C:/Users/zimme/Documents/R/Scripts/do_lts_2.R")
[1] "20111208_203052.wav"
[1] "20111208_203122.wav"
year month day hour min sec time
1 2011 12 08 20 30 52 2011-12-08 20:30:52
2 2011 12 08 20 31 22 2011-12-08 20:31:22
Obviously directory remaining, etc.path to data needs to be adapted