[MPlayer-dev-eng] [BUG] surround audio plugin broken

Anders Johansson ajh at watri.uwa.edu.au
Thu Jan 9 03:31:22 CET 2003


Hi,

> > > rewrite the innermost loops in af_resample.h & mmx optimize them, perhaps
> > > SSE for the float stuff, i assume they are the most timeconsuming part
> > > but ill check that
> >
> > Sounds great, a starting point for the mmx can be found in
> > libao2/fir.h, also I think the optimized fir code should be moved to a
> > separate file (af_fir.h) since it will be used elewhere (see
> > af_surround for example).
> >
> > BTW before you start rewriting take a look at the compiler output. I
> > did some optimization of the C-code by looking at the assembly output
> > when I first wrote the code, so it compiles quite well. Another thing
> > which would be great would be to combine up and downsampling into one
> > routine.
> 
> hmm, seems its a bit more tricky to optimize
> the problem:
> the circular buffer is filled 1 sample at a time and then these are immediatly 
> used in the FIR filter, this makes MMX&SSE useless as there are large 
> penalties for reading something which was written with a different size 
> immedeately before, i ll try to use a larger buffer and prefill it before 
> running the FIR filter over it ...

Make sure it still works if there is only 1 new input sample.

> btw, is 
> #define ADDQUE(xi,xq,in)\
>   xq[xi]=xq[xi+L]=(*in);\
>   xi=(xi-1)&(L-1);
> correct?
> shouldnt it be
> #define ADDQUE(xi,xq,in)\
>   xi=(xi-1)&(L-1);\
>   xq[xi]=xq[xi+L]=(*in);
> ?

Yes I think so. I'll apply the matlab script I used to develope the
algorithm. 

> Michael

//Anders
-------------- next part --------------
% Matlab version of resampling 

clear all;

fin=48000;   % Input frequency will change if read from disk
fout=44100;  % Output frequency 


% Generate test vectors or load from disk
t=25;          % Test vector time [s]
%in=randn(1,t*fin);
in=sin(440*2*pi*(1:t*fin)/fin);
% in=chirp(0:21/fin:t,0,20,fin);
% [in,fin]=wavread('../data/toilet11025.wav');
in=round(32768*(in(:)')./max(abs(in)))/32768;
wavwrite(in./(1.0001*max(abs(in))),fin,'../data/in.wav');

N=length(in);

% up/down constants
%[up,dn]=rat((fix(fout/100)*100)/(fix(fin/100)*100),1e-12);
up=172;
dn=round(fin/fout*up);

BZ = 128;     % Block size
L  = 16;       % Filter length  

% Resulting frequency
disp(sprintf('down = %i, up = %i',dn,up)); 
disp(sprintf('Resulting frequency: %6.1f kHz \n',fin*up/dn));

% Run sample rate conversion
cb=zeros(1,L);                  % Circular buffer 
out=zeros(1,ceil(up/dn*N));     % Out data vector 
wup=zeros(up,L);                % Polyphase filter bank
wup(:)=fir1(L*up-1,1/up,kaiser(L*up,10));
% wup(:)=remez(L*up-1,linspace(0,1,up*L),[ones(1,L) zeros(1,up*L-L)]);
wup=wup./max(abs(wup(:)));
wup=round(wup*32768)/32768;
l=1;
k=1;
outbl=zeros(1,BZ);
for i = 1:floor(length(out)/BZ)-1

  for j=1:BZ
    k=rem(k+dn,up);             % Calculate which pholyphase component to use
    if k < rem(dn,up)
      l=l+ceil(dn/up);
    else
      l=l+floor(dn/up);
    end
    
    outbl(j)=sum(wup(1+k,:).*in(l+L-1:-1:l)); % Run filter
  end
  
  out((1:BZ)+(i-1)*BZ)=outbl;
end

out=fix(32768*out)/32768;
% Show results 
showperf(fin,fout,in,out);

wavwrite(out./(1.0001*max(abs(out))),fout,'../data/out.wav');
wavwrite(in./(1.0001*max(abs(in))),fin,'../data/in.wav');
% soundsc(in,fin);
% soundsc(out,fout);






More information about the MPlayer-dev-eng mailing list