hpsmodel.m
Go to the documentation of this file.
1 function [y,yh,ys,fr0] = hpsmodel(x,fs,w,N,t,nH,minf0,maxf0,f0et,maxhd,stocf)
2 %=> analysis/synthesis of a sound using the sinusoidal harmonic model
3 % x: input sound, fs: sampling rate, w: analysis window (odd size),
4 % N: FFT size (minimum 512), t: threshold in negative dB,
5 % nH: maximum number of harmonics, minf0: minimum f0 frequency in Hz,
6 % maxf0: maximim f0 frequency in Hz,
7 % f0et: error threshold in the f0 detection (ex: 5),
8 % maxhd: max. relative deviation in harmonic detection (ex: .2)
9 % stocf: decimation factor of mag spectrum for stochastic analysis
10 % y: output sound, yh: harmonic component, ys: stochastic component
11 
12 %x=tanh(10*x);
13 
14 M = length(w); % analysis window size
15 Ns = 1024; % FFT size for synthesis
16 H = 256; % hop size for analysis and synthesis
17 N2 = N/2+1; % half-size of spectrum
18 soundlength = length(x); % length of input sound array
19 hNs = Ns/2; % half synthesis window size
20 hM = (M-1)/2; % half analysis window size
21 pin = max(hNs+1,1+hM); % initialize sound pointer to middle of analysis window
23 fftbuffer = zeros(N,1); % initialize buffer for FFT
24 yh = zeros(soundlength+Ns/2,1); % output sine component
25 ys = zeros(soundlength+Ns/2,1); % output residual component
26 w = w/sum(w); % normalize analysis window
27 sw = zeros(Ns,1);
28 ow = triang(2*H-1); % overlapping window
29 ovidx = Ns/2+1-H+1:Ns/2+H; % overlap indexes
30 sw(ovidx) = ow(1:2*H-1);
31 bh = blackmanharris(Ns); % synthesis window
32 bh = bh ./ sum(bh); % normalize synthesis window
33 wr = bh; % window for residual
34 sw(ovidx) = sw(ovidx) ./ bh(ovidx);
35 sws = H*hanning(Ns); % synthesis window for stochastic
36 
37 i = 0;
38 while pin<pend
39  i = i+1;
40  %-----analysis-----%
41  xw = x(pin-hM:pin+hM).*w(1:M); % window the input sound
42  fftbuffer(1:(M+1)/2) = xw((M+1)/2:M); % zero-phase window in fftbuffer
43  fftbuffer(N-(M-1)/2+1:N) = xw(1:(M-1)/2);
44  X = fft(fftbuffer); % compute the FFT
45  mX = 20*log10(abs(X(1:N2))); % magnitude spectrum
46  pX = unwrap(angle(X(1:N/2+1))); % unwrapped phase spectrum
47  ploc = 1 + find((mX(2:N2-1)>t) .* (mX(2:N2-1)>mX(3:N2)) ...
48  .* (mX(2:N2-1)>mX(1:N2-2))); % find peaks
49  [ploc,pmag,pphase] = peakinterp(mX,pX,ploc); % refine peak values
50  f0 = f0detection(mX,fs,ploc,pmag,f0et,minf0,maxf0); % find f0
51  fr0(i)=f0;
52  hloc = zeros(nH,1); % initialize harmonic locations
53  hmag = zeros(nH,1)-100; % initialize harmonic magnitudes
54  hphase = zeros(nH,1); % initialize harmonic phases
55  hf = (f0>0).*(f0.*(1:nH)); % initialize harmonic frequencies
56  hi = 1; % initialize harmonic index
57  npeaks = length(ploc); % number of peaks found
58  while (f0>0 && hi<=nH && hf(hi)<fs/2) % find harmonic peaks
59  [dev,pei] = min(abs((ploc(1:npeaks)-1)/N*fs-hf(hi))); % closest peak
60  if ((hi==1 || ~any(hloc(1:hi-1)==ploc(pei))) && dev<maxhd*hf(hi))
61  hloc(hi) = ploc(pei); % harmonic locations
62  hmag(hi) = pmag(pei); % harmonic magnitudes
63  hphase(hi) = pphase(pei); % harmonic phases
64  end
65  hi = hi+1; % increase harmonic index
66  end
67  hloc(1:hi-1) = (hloc(1:hi-1)~=0).*((hloc(1:hi-1)-1)*Ns/N+1); % synth. locs
68  ri= pin-hNs; % input sound pointer for residual analysis
69  xr = x(ri:ri+Ns-1).*wr(1:Ns); % window the input sound
70  Xr = fft(fftshift(xr)); % compute FFT for residual analysis
71  Yh = genspecsines(hloc(1:hi-1),hmag,hphase,Ns); % generate sines
72  Yr = Xr-Yh; % get the residual complex spectrum
73  mYr = abs(Yr(1:Ns/2+1)); % magnitude spectrum of residual
74  %mYs = stochenvelope(mYr,stocf);
75  %-----transformations-----%
76  mYsenv = decimate(mYr,stocf,1); % decimate the magnitude spectrum
77  %-----synthesis-----%
78  mYs = interp(mYsenv,stocf,1); % interpolate to original size
79 
80 % n=1:N/2+1;
81 % plot(n/N*Ns,mX); %plotting the original spectrum
82 % hold on;
83 % plot(20*log10(abs(mYs)), 'r'); %plotting the approximation done by the decimate function
84 %
85 % hold on;
86 % plot(hloc, hmag, 'g*');
87 % hold off;
88 % pause
89 
90  roffset = ceil(stocf/2)-1; % interpolated array offset
91  mYs = [ mYs(1)*ones(roffset,1); mYs(1:Ns/2+1-roffset) ];
92  pYs = 2*pi*rand(Ns/2+1,1); % generate phase random values
93  mYs1 = [mYs(1:Ns/2+1); mYs(Ns/2:-1:2)]; % create magnitude spectrum
94  pYs1 = [pYs(1:Ns/2+1); -1*pYs(Ns/2:-1:2)]; % create phase spectrum
95  Ys = mYs1.*cos(pYs1)+1i*mYs1.*sin(pYs1); % compute complex spectrum
96  yhw = fftshift(real(ifft(Yh))); % sines in time domain using IFFT
97  ysw = fftshift(real(ifft(Ys))); % stoc. in time domain using IFFT
98  yh(ri:ri+Ns-1) = yh(ri:ri+Ns-1)+yhw(1:Ns).*sw; % overlap-add for sines
99  ys(ri:ri+Ns-1) = ys(ri:ri+Ns-1)+ysw(1:Ns).*sws; % overlap-add for stoch.
100  pin = pin+H; % advance the sound pointer
101 end
102 
103 %ys=tanh(10*ys);
104 y= yh+ys; % sum sines and stochastic
static struct ResampleContext * create(struct ResampleContext *c, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff, enum AVSampleFormat format, enum SwrFilterType filter_type, int kaiser_beta, double precision, int cheby)
Definition: soxr_resample.c:32
Definition: start.py:1
output sine component ys
Definition: hpsmodel.m:25
FFT size for synthesis H
Definition: hpsmodel.m:16
magnitude spectrum pX
Definition: stft_peak.m:24
analysis window size Ns
Definition: hpsmodel.m:15
function f0et
Definition: harmonicmodel.m:1
if max(w)>1 w=0.9 *w/max(w)
normalize synthesis window wr
Definition: hpsmodel.m:33
output residual component w
Definition: hpsmodel.m:26
normalize analysis window sw
Definition: hpsmodel.m:27
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
N, 1 zeros()
plot(ejex, abs(X3),'*')
function ploc
Interpolated time axis hold on
FFT size for synthesis(even) H
bh
Definition: hpsmodel.m:31
#define sample
function maxhd
Definition: harmonicmodel.m:1
Inicial output npeaks
Definition: stpt.m:6
FFT of current buffer mX
Definition: stft_peak.m:23
pphase
Definition: stft_peak.m:27
synthesis window for stochastic i
Definition: hpsmodel.m:37
M
Definition: hpsmodel.m:14
end end
function magnitudes and phases
#define N
Definition: vf_pp7.c:200
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:280
Plot spectral magnitude
function f0
return end harmonic
Definition: extra/TWM.m:29
frame
Definition: stft.m:14
Discrete Time axis x
function nH
Definition: harmonicmodel.m:1
#define zero
Definition: regdef.h:64
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an input
half analysis window size pin
Definition: hpsmodel.m:21
phase spectrum(unwrapped) ploc
overlapping window(triangular window to avoid too much overlapping) ovidx
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
int size
clear max peak[Mmag2, Mloc2]
Definition: extra/TWM.m:16
last sample to start a frame fftbuffer
Definition: hpsmodel.m:23
use a maximum of peaks[f0, f0error]
Sampled sinusoid X
overlapping window ovidx
Definition: hpsmodel.m:29
t
Definition: genspecsines3.m:6
sws
Definition: hpsmodel.m:35
size of positive spectrum soundlength
Definition: gong.m:8
sound(x3, Fs)
function maxf0
initialize sound pointer to middle of analysis window pend
Definition: hpsmodel.m:22
mag
Definition: lab5.m:14
int index
Definition: gxfenc.c:89
pause
Definition: plot_peaks.m:14
static const int factor[16]
Definition: vf_pp7.c:202
function pmag
half synthesis window size hM
Definition: hpsmodel.m:20
fftbuffer, N fft()
FFmpeg Automated Testing Environment ************************************Table of Contents *****************FFmpeg Automated Testing Environment Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass target exec to configure or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script tests fate sh from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at doc fate_config sh template Create a configuration that suits your based on the configuration template The slot configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern< arch >< os >< compiler >< compiler version > The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the fate_recv variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ssh command with one or more v options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory FATE makefile targets and variables *************************************Makefile can be set to
Definition: fate.txt:142
1:W2 xw()
function fs
the buffer and buffer reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFilterBuffer structures They must not be accessed but through references stored in AVFilterBufferRef structures Several references can point to the same buffer
these buffered frames must be flushed immediately if a new input produces new output(Example:frame rate-doubling filter:filter_frame must(1) flush the second copy of the previous frame, if it is still there,(2) push the first copy of the incoming frame,(3) keep the second copy for later.) If the input frame is not enough to produce output
function y
Definition: D.m:1
hop size for analysis and synthesis N2
Definition: hpsmodel.m:17
function minf0
length of input sound array hNs
Definition: hpsmodel.m:19
x length()
float min
for(j=16;j >0;--j)
ow
Definition: hpsmodel.m:28
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return values
initialize buffer for FFT yh
Definition: hpsmodel.m:24