WAV into binary bits
조회 수: 23 (최근 30일)
이전 댓글 표시
How to convert a wav file data into binary (0,1) format, so that it can again be converted from binary form to wav?
댓글 수: 0
채택된 답변
Walter Roberson
2013년 3월 18일
wavdata = wavread('FileName.wav');
wavbinary = dec2bin( typecast( single(wavdata(:)), 'uint8'), 8 ) - '0';
orig_size = size(wavdata);
Then the reverse:
wavdata = reshape( typecast( bin2dec( uint8(wavbinary + '0') ), 'single' ), orig_size );
댓글 수: 6
Nelson Rodriguez Hernandez
2016년 7월 8일
편집: Nelson Rodriguez Hernandez
2016년 7월 8일
But if I have a binary array of only "Zeros and Ones"(0,1), how can I create sound from binary in .wav or other extension? Do I have to create my own samples using audiowrite, bin2dec or what? In other words how can I sampling from binary?
Walter Roberson
2016년 7월 8일
Assuming your binary array of 0 and 1 is stored in wavbinary then
data_class_to_use = 'int32'; %or as appropriate
SampleRate = 22100; %set as appropriate
wavdata = reshape( typecast( uint8(bin2dec( char(wavbinary + '0') )), data_class_to_use ), orig_size );
audiowrite('FileNameGoesHere.wav', wavdata, SampleRate)
The data_class_to_use will depend upon kind of data you intend your binary array to represent. The sample code I gave here assumes that your binary array uses groups of 32 bits per sample, and that the 32 bits represent a signed 32 bit integer. For the question that was originally posted, it was 'float' that was appropriate to use, because the binary array represented 32 bit single precision numbers.
추가 답변 (2개)
Jan
2013년 3월 19일
What exactly are "wav file data"? Are you talking about doubles or integer types?
What is the prupose of converting the data to a binary format, when you consider, that all data are store in a binary format inside the computer. What do you want to achieve?
댓글 수: 3
Kushant
2014년 4월 2일
i also have the same problem...
i want to use generated c code on dsp, but matlab coder do not support wavread function. i am planning to use fopen and fread but for that i need binary files instead of .wav files.
please tell me how to do it?
and how it can be done arithmatically?
Walter Roberson
2014년 4월 2일
Outside of the dsp, wavread() the .wav files, and fwrite() them to a binary file. In the dsp read the binary file.
Kyaw Yegaung
2018년 9월 24일
I get the problem converting wav file to binary with wave file read command wavread. But i use another command audioread. Authoug it was work i got trouble in another command like dec2bin. It said that deceimal be less than 2 power 52. The point is what actually the data type of wav or other audio source file and how can i convert to decimal before converting binary data. If anyone could help me please contact my mail 'oooooyaungoooo@gmail.com'. Thank you.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File 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!