📄 dsk6713_rxtx.m
字号:
function [Xin,no_samples_delivered,buffer_size]=DSK6713_rxtx(no_samples_wanted,no_repeats,repeat_ix_receive,Xout,sample_rate)
%
% [Xin,no_samples_delivered,buffer_size]=DSK6713_rxtx(no_samples_wanted,no_repeats,repeat_ix_receive,Xout,sample_rate)
%
%%%%%%% Before running the function.
% Start code-composer studio.
% Load the release version of DSK6713_rxtx. Start the program (Debug->Run).
% Start the host program DSK6713_Host_rxtx.exe in a command window.
% Change the directory of matlab to the directory of DSK6713_Host_rxtx.exe.
% If the program hangs: Stop DSK6713_Host_rxtx.exe, reload and re-start
% DSK6713_rxtx.out restart DSK6713_Host_rxtx.exe, stop and re-start
% DSK6713_rxtx.m .
%
%%%%%%% Inputs:
% no_samples_wanted: Select the number of samples you want. The number of samples you get is no_samples_delivered
% which is no_samples_wanted rounded downwards to a multiple of buffer_size.
% no_repeats: The signal Xout(:,1:no_samples_delivered) is sent no_repeats times on the D/A converters.
% repeat_ix_receive: Determines the index of the repeat under which the data in from the A/D converters is sent to matlab in Xin.
% Xout : A 2xno_samples_wanted dimensional matrix with rows corresponding to the outputs to be sent on the D/A converters.
% sample_rate : The selected sample rate for both A/D and D/A converters. Must be 96000,88200,44100,32000,8021 or
% 8000. If not 48000 is selected.
% AIC23control : Not implemented yet. But control of all parameters of the aic23 can be easily achieved by just manipulating this file.
if ~((size(Xout,1)==2) & (size(Xout,2)==no_samples_wanted))
error('The size of Xout shall be 2xno_samples_wanted')
end;
if ~( (min(Xout(:))>(-2^15-1)) & (max(Xout(:))<2^15))
error('The elements of Xout shall be in the range [-2^15,2^15-1]')
end;
config=zeros(13,1); %% 10 AIC23 registers + 3 custom parameters.
config(1+0)=hex2int('0017'); % 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume
config(1+1)=hex2int('0017'); % 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume
config(1+2)=hex2int('01f9'); % 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume
config(1+3)=hex2int('01f9'); % 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume
config(1+4)=hex2int('0011'); % 4 DSK6713_AIC23_ANAPATH Analog audio path control
config(1+5)=hex2int('0000'); % 5 DSK6713_AIC23_DIGPATH Digital audio path control
config(1+6)=hex2int('0000'); % 6 DSK6713_AIC23_POWERDOWN Power down control
config(1+7)=hex2int('0043'); % 7 DSK6713_AIC23_DIGIF Digital audio interface format
config(1+8)=hex2int('0001'); % 8 DSK6713_AIC23_SAMPLERATE Sample rate control
config(1+9)=hex2int('0001'); % 9 DSK6713_AIC23_DIGACT Digital interface activation
config(1+10)=no_samples_wanted;
config(1+11)=no_repeats;
config(1+12)=repeat_ix_receive;
switch sample_rate
case 96000,
config(1+8)=sum([32,16,8,4,2].*[0,1,1,1,0])+1;
case 88200,
config(1+8)=sum([32,16,8,4,2].*[1,1,1,1,1])+1;
case 44100,
config(1+8)=sum([32,16,8,4,2].*[1,0,0,0,1])+1;
case 32000,
config(1+8)=sum([32,16,8,4,2].*[0,1,1,0,0])+1;
case 8021,
config(1+8)=sum([32,16,8,4,2].*[1,0,1,1,1])+1;
case 8000,
config(1+8)=sum([32,16,8,4,2].*[0,0,1,1,0])+1;
otherwise,
%Keep default.
end;
disp('Wait');
fid=fopen('config_in.dat','w');
fwrite(fid,config,'int');
fclose(fid);
DACRawBuffer=kron(Xout(1,:),[1,0])+kron(Xout(2,:),[0,1]);
fid=fopen('data_in.dat','w');
fwrite(fid,DACRawBuffer,'short');
fclose(fid);
fid=fopen('use_counter.dat','r');
[use_counter,dummy]=fread(fid,1,'int');
fclose(fid);
use_counter=use_counter+1;
fid=fopen('use_counter.dat','w');
fwrite(fid,use_counter,'int');
fclose(fid);
done_counter=-1;
while ~(done_counter==use_counter)
pause(2);
fid=fopen('done_counter.dat','r');
[done_counter,dummy]=fread(fid,1,'int');
fclose(fid);
end;
fid=fopen('config_out.dat','r');
[temp,dummy]=fread(fid,2,'int');
no_samples_delivered=temp(1);
buffer_size=temp(2);
n_buffers_tot=no_samples_delivered/buffer_size;
fclose(fid);
fid=fopen('data_out.dat','r');
[ADCRawBuffer,dummy]=fread(fid,2*no_samples_delivered,'short');
fclose(fid);
Xin=[ADCRawBuffer(1:2:(no_samples_delivered*2)),...
ADCRawBuffer(2:2:(no_samples_delivered*2))]';
disp('Done');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -