What does [a,fs] = audioread(filename) do?
9 views (last 30 days)
I dont really understand the matlab explanation.
When i run it, in the command window after inputting a song that was around 3 min long, i got a mx2 matrix that had millions of rows and 2 columns and a fs value at the end.
What exactly was the matrix? What are its rows and columns exactly? Would love to get an explanation.
Voss on 4 May 2022
[a,fs] = audioread(filename)
reads the audio file filename and returns the audio data as a and the sampling rate as fs.
The number of columns of a is the number of channels in the recording, so 2 columns means it's a stereo recording, 1 column would be a mono recording.
The number of rows of a is the number of samples in the recording.
The sampling rate fs tells you how the samples correspond to actual time. For example, fs = 44100 means a 44.1kHz sampling rate, which means 44100 samples per second. This is necessary to know because generally you need to know how to map that matrix of samples (i.e., matrix of numbers) a to actual time if you want to play back the audio or do anything else with it. The matrix a itself doesn't tell you how far apart consecutive samples are in time; you need the sampling rate for that, so fs is returned separately.
sound(a,fs) % play the recording back
sound(a,fs/2) % play the recording back at half-speed (pitch is also necessarily halved doing this)
filename = 'Pink Floyd - Empty Spaces.wav';
[a,fs] = audioread(filename);
sound(a(end:-1:1,:),fs) % play the recording backwards to hear the secret message