Problem with 64 bit WAV file using audiowrite

4 次查看(过去 30 天)
I am using a script to generate test wav files at different sampling rates and bit depths. So far everything has worked fine up until I try to generate a 64 bit wav file. I generate the file but if I try to import the wav file in Matlab, I get an error that says "File contains uninterpretable data." The file also doesn't play in Windows Media Player. However, using the audioinfo function correctly decodes the wav header information. The script I am using is below. I am using R2015a on Windows 7 64-bit. Any ideas?
%%Generate wav file.
% Sampling rate and bit depth.
fs = 44100;
nbits = 64; %8, 16, 24, 32, 64
channels = 1;
fm = 1000; % Message frequency.
% Generate a filename
filename = strcat(num2str(fm),'_Hz_tone_fs_',num2str(fs),'_',num2str(nbits),'bits.wav');
osr = fs/fm;
decimal = osr - floor(osr);
if decimal ~= 0
cycles = round(1/decimal);
else
cycles = 100;
end
npts = cycles*osr - 1;
t = 0:1/fs:npts/fs;
m = cos(2*pi*fm*t).';
% add dummy channel to make sure c++ code works for multi-channel.
if channels > 1
m(:,2:channels) = 0;
end
%%Normalize the data based on nbits.
% Normalization ranges are from matlab's audiowrite function.
if nbits == 8
% 8 bits: uint8 ( 0 <= m(t) <= 255 )
m = uint8((m+1)/2*255);
elseif nbits == 16
% 16 bits: int16 ( -32768 <= m(t) <= 32767 )
m = int16((m+1)/2*(32767 - -32768) + -32768);
elseif nbits == 24
% 24 bits: int32 ( -2^31 <= m(t) <= 2^31-1 )
m = int32((m+1)/2*(2^31-1 - -2^31) + -2^31);
elseif nbits == 32
% 32 bits: int32 ( -2^31 <= m(t) <= 2^31-1 )
m = int32((m+1)/2*(2^31-1 - -2^31) + -2^31);
elseif nbits == 64
% 64 bits: double (-1.0 < m(t) <= 1.0 )
m = m;
else
fprintf('Invalid bit depth: %d\n',nbits);
return;
end
audiowrite(filename,m,fs,'BitsPerSample',nbits);
  1 个评论
Geoff Hayes
Geoff Hayes 2016-7-23
Elliot - I don't have any problems when running your above code (for R2014a on OSX 10.11.5).

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by