
Why do wavwrite and audiowrite produce different results?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am transitioning from wavwrite to audiowrite and encountered the problem that wavread and audioread do not always produce identical wav files. For example the code
y = repmat((1:750)', 1, 3);
wavwrite(y, 500, 32, 'test1.wav');
audiowrite('test2.wav', y, 500, 'BitsPerSample', 32);
fid = fopen('test1.wav');
test1 = fread(fid);
fclose(fid);
fid = fopen('test2.wav');
test2 = fread(fid);
fclose(fid);
length(test1)
length(test2)
returns 9044 and 9096. Why is that and how can I reproduce the results from wavwrite in my existing code with audiowrite?
PS: I am aware of audioread, but that is not an option here.
0 Kommentare
Antworten (1)
Rajanya
am 13 Mär. 2025 um 14:10
WAV files organize the whole file data as chunks identified by four-character code (FourCC) identifiers to identify the dedicated chunks to header, metadata and the actual data (often called payload). The main chunks are "RIFF", "WAVE", "fmt " and "data" while other chunks may also be present. Now, as evident by name, the "data" chunk contains the actual audio data (see link).
The difference, as stated here, between 'wavwrite' and 'audiowrite' is because how they pack the headers and metadata along with the data chunk. On opening the 'test1' and 'test2' wav files in binary (as text), the difference in the chunks can be spotted -

Among other things, the chunks 'fact' and 'PEAK' can be seen to be added in 'test2.wav'. The difference in the length of 'test1' and 'test2' and in the sizes of both the files account to this same reason which lies in the organizational construct of the RIFF headers by 'wavwrite' and 'audiowrite'.
The 'data' chunk (text starting after 'data'), as expected, can be verified to be the equal for both the binaries indicating that the required results (the actual payloads) are the same, with the only difference being in the way in which they are packed.
PS: 'wavwrite' and 'wavread' are depricated as of MATLAB R2015b and 'audiowrite' and 'audioread' are to be used instead.
To learn more about 'audioread' and 'audiowrite', you can refer to the respective documentation pages by executing the following commands from MATLAB Command Window -
doc audioread
doc audiowrite
Thanks!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!