Hi,
i want to convert a .wav file (16Bit, 44100Hz, stereo) to a binary stream file, than send it through simulink via "Binary File Reader", read the Output from "Binary File Writer" back into Matlab and convert it back to .wav to hear the result of my Reverb i build with simulink.
my steps so far:
wavdata = audioread("Closed-Hi-Hat-1.wav");wavbinary = dec2bin( typecast( single(wavdata(:)), 'uint8'), 8 ) - '0';
now i have a wavdata variable with value:3247×2 double
and a wavbinary with 25976×8 double
fid = fopen('wav.bin', 'w');fwrite(fid, wavbinary);fclose(fid);
I now have the "wav.bin" file i can add to my "Binary File Reader" in simulink, when i send it through my "Reverb" i get a new "wav_reverb.bin" file.
next steps back in matlab:
fid = fopen('wav_reverb.bin');A = fread(fid);sound(A);
when i now play (A) it sounds not like the actual "Closed-Hi-Hat-1.wav" i sent through my "Reverb". It sounds very bad and scratchy. I think its a problem with the data types. And i dont know how to convert the "wav_reverb.bin" back to a .wav (maybe it sounds better than).
PS: i tried the example from Walter
>> wavbinary = dec2bin( typecast( single(wavdata(:)), 'uint8'), 8 ) - '0';>> orig_size = size(wavdata);>> data_class_to_use = 'int32';>> SampleRate = 22100; >> wavdata = reshape( typecast( uint8(bin2dec( char(wavbinary + '0') )), data_class_to_use ), orig_size );>> audiowrite('FileNameGoesHer33e.wav', wavdata, SampleRate)
but the new audiofile sounds also scratchy and bad.
I hope anyone can help me
thanks
LK
Best Answer