How to analyze .wav and .dat file? - wav

I want to read .wav or .dat files and plot the spectrum, for the plot spectrum I need the center frequency and bits per samples, in the .dat file I can find the center frequency but I can not find it in .wav
How can I calculate it?
I can also find bits per samples in the .wav file according to the canonical wave file format but not in the .dat file, is .dat file contain it?
Is .dat file data stored in little endian like a .wav file?

Related

Convert multiple ASCII files to Raster files in R

Could you please explain in detail how I can open multi ASCII files from the beginning and convert them to the raster files in RStudio? I have ASCII files from several years and need to compress the files into one file at the end, containing all the years.

How to read multiple .nc files and export it to different respective .csv files?

I have many .nc (netcdf) files, each file representing rainfall at hourly interval. I need to convert multiple .nc files to multiple respective .csv file. Using R, I am able to convert one .nc file to .csv successfully but I want to convert multiple files at one time.
I have successfully converted one .nc file to .csv file. For conversion of multiple files at one time, I have tried to stack all the files together using 'stack' command and then convert the to .csv using 'write.csv' or 'writetable' but it showed error and didn't work.
Code to convert one .nc file to .csv is as follows:
library(raster)
nc.brick <- brick(file.choose())
nc.df <- as.data.frame(nc.brick[[1]], xy=TRUE)
write.csv(nc.df, file.choose())
As an output, I have got a .csv file with three columns, one representing latitutde, second-longitude and third-rainfall value. I want such similar multiple .csv files to be converted from multiple .nc files at one go. So, is there any way to convert multiple .nc files to multiple .csv files respectively?
You can make a loop over files in a directory. So rather than using file.choose() which require manual choosing of files, you can make a vector of the files in your directory.
rm(list = ls())
install.packages(“raster”)
install.packages(“ncdf4”)
library(raster)
ptf <- "/path/to/nc/files"
setwd(ptf) # change your working directory
lf <- list.files(pattern="[.]nc$") # list of files ending in .nc
for(i in lf){
nc.brick <- brick(i)
nc.df <- as.data.frame(nc.brick[[1]], xy=T)
write.csv(nc.df, sub("[.]nc$",".csv",i)) # write to the same file name substituting .nc to .csv
}

Is it possible to write mp3 files from `tuneR::Wave` object in R?

mp3 to WAV is easy by monitoR::readMP3 and tuneR::writeWave. What about Wave object to mp3?
I have done some audio splitting with R tuneR::Wave objects, and want to output them as mp3 files. I don't need the resolution as in WAV file which takes up a lot of unnecessary space.

.wav file length/duration without reading in the file

Is there a way to extract the information about .wav file length/duration without having to read in the file in R? I have thousands of those files and it would take a long time if I had to read in every single one to find its duration. Windows File Explorer gives you and option to turn on the Length field and you can see the file duration, but is there a way to extract that information to be able to use in in R?
This is what I tried and would like to avoid doing since reading in tens of thousands of audio files in R will take a long time:
library(tuneR)
audio<-readWave("AudioFile.wav")
round(length(audio#left) / audio#samp.rate, 2)
You can use the readWave function from the tuneR package with header=TRUE. This will only head the metadata of the file and not the entire file.
library(tuneR)
audio<-readWave("AudioFile.wav", header=TRUE)
round(audio$samples / audio$sample.rate, 2)

jlayer increasing size of file when convert .mp3 file to .wav file

I am using jlayer to convert mp3 file to wav format. The code is working good but the size of wav file is increased about 5 times the size of mp3 file. For converting i have used the jar file provided by the jlayer.
Anyone please tell how to optimize the size of the file.
You cannot optimize the size of a WAV file, its size depends on the audio data written into it. The higher the quality of audio, the larger the file. The longer the length of audio, the larger the file.
WAV files contain PCM encoded digital audio. The reason we use MP3 and other audio encoding formats is to reduce the file size, in exchange of quality.
So when you convert a file from WAV to MP3, you get a smaller file but you lose audio quality.
If you convert the resulting file from MP3 to WAV (which is what you do), you always get a larger file and you never get back to the original audio quality.

Resources