9

I have loaded audio files into R and would now like to get a list of the complex number samples so I can use FFT and Wavelet transforms on the samples.

How do I get the list of numbers to work with whilst in R? I've tried 'audio$data', but get an error message as $ is not defined in the s4 class.

Any help would be highly appreciated, thanks.

3
  • Welcome to SO! Could you please show some code?
    – krlmlr
    Dec 11, 2012 at 20:31
  • 1
    Well, you could try audio@data as befits S4 class :-) . But it's hard to say without knowing what sort of file you loaded and how you loaded it. Dec 11, 2012 at 20:38
  • All I've done so far is to input the audio by audio = readWave("audio.wav")
    – EmmaL
    Dec 11, 2012 at 20:40

1 Answer 1

8

After reading the file with readWave from the tuneR package, you can use audio@left and audio@right to access the raw data. The latter is only available if your data is stereo. str(audio) will give you details about the structure of an object, and is immensely useful to find out what data it contains and how to access that data.

For obvious reasons, the data in a wave file will be real (and in fact even integers), so if you need complex numbers you might have to convert them. But I would guess that such a conversion will be performed automatically if you pass a vector of integers. The normal fft function (from package stats) can handle the integer vector without a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.