ropensci / av

Working with Video in R
https://docs.ropensci.org/av
Other
92 stars 10 forks source link

read_audio_bin() returning NAs #33

Closed Athospd closed 3 years ago

Athospd commented 3 years ago

It seems that numeric overflow is causing NA outputs. And bit rate is not been taken into account as well (apologies for my poor English speaking skills).

url <- "https://raw.githubusercontent.com/curso-r/torchaudio/master/inst/sample_audio_2.mp3"
f <- tempfile()
download.file(url, destfile = f)
a <- tuneR::readMP3(f)
b <- av::read_audio_bin(f)

# NAs -----------
b[is.na(b)]
#>  [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
#> [26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
#> [51] NA NA NA NA NA NA
a@left[is.na(a@left)]
#> integer(0)
a@right[is.na(a@right)]
#> integer(0)

# Same size -----
length(b)
#> [1] 829440
length(c(a@right, a@right))
#> [1] 829440

# Equivalent audio in different bit encoding ----
b1 <- b[c(TRUE, FALSE)]
plot(a@right, b1, type = "l")


# Look like it is been clipped due numerical issues ---
plot(b1, type = "l")
points(which(is.na(b1)), numeric(sum(is.na(b1))), col = "red")

Created on 2021-01-19 by the reprex package (v0.3.0)

jeroen commented 3 years ago

Thanks. I think you are right that we are reading data that happens to have exactly the value of what is NA_INTEGER in R.

jeroen commented 3 years ago

I have added a workaround, could you confirm that this solves your issue (and doesn't introduce any new problems)?

Athospd commented 3 years ago

For this particular example your workaround worked perfectly! i'll let you know if I face any other problem. Thank you very much for this package.

PS: you called it a "workaround", so I'll let you decide if this issue should be closed now or not, despite the main problem had been fixed.

jeroen commented 3 years ago

OK so hopefully no major side effects :)