clear;
close all;
clc;
filename = ('stereo_sinwave.wav');
filename_h = ('hexdata.h');
%To see the contents of the file you created, use the type function:
%type hexdata.txt
% [fname,pname]=uigetfile(filename,'Open Wave File');
% file=[pname,fname];
% % % % % % % % % % % % % % % % % % % % % % % % % %
[x,fs]=audioread(filename, 'native'); % 读入声音文件(*.wav)
whos x
x;
%x1 = x(:,1); % 抽取第 1 声道
%x2 = x(:,2); % 抽取第 2 声道
a = fi(x,1);
[m,n]=size(a);
z = a.hex; % or using z = hex(a);
z = z(1:1+20,:);
h = fopen(filename_h,'w');
%Use the fprintf function to write your data to the hexdata.txt file:
for k=1:m
fprintf(h,'0x%s, 0x%s\r\n', hex(a(k,1)),hex(a(k,2))); %dec2hex dec 2 hex string
end
fclose(h);
% % % % % % % % % % % verify the data
% Ways to Import Text Files
tic
filename = ('hexdata.h');
fid = fopen(filename,'r');
lines = 0;
while ~feof(fid)
fgetl(fid);
lines = lines +1;
end
fclose(fid);
toc
lines
% [x2, x4] = textread(filename,'0x