WAV into binary bits
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sangeeta
el 18 de Mzo. de 2013
Respondida: Kyaw Yegaung
el 24 de Sept. de 2018
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 comentarios
Respuesta aceptada
Walter Roberson
el 18 de Mzo. de 2013
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 comentarios
Nelson Rodriguez Hernandez
el 8 de Jul. de 2016
Editada: Nelson Rodriguez Hernandez
el 8 de Jul. de 2016
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
el 8 de Jul. de 2016
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.
Más respuestas (2)
Jan
el 19 de Mzo. de 2013
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 comentarios
Kushant
el 2 de Abr. de 2014
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
el 2 de Abr. de 2014
Outside of the dsp, wavread() the .wav files, and fwrite() them to a binary file. In the dsp read the binary file.
Kyaw Yegaung
el 24 de Sept. de 2018
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 comentarios
Ver también
Categorías
Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!