extractMelody.m
Go to the documentation of this file.
1 function [y] = extractMelody(x,w,N,melodyFile)
2 %e.g. y = extractMelody(x,hamming(2025),4096,'baby.txt');
3 
4 
5 % Initialize
6 M = length(w); % analysis window size
7 Ns = 1024; % FFT size for synthesis
8 H = 256; % hop size for analysis and synthesis
10 hNs = Ns/2; % half synthesis window size
11 hM = (M-1)/2; % half analysis window size
12 pin = max(hNs+1,1+hM); % initialize sound pointer to middle of analysis window
14 fftbuffer = zeros(N,1); % initialize buffer for FFT
15 y = zeros(soundlength+Ns/2,1); % output sine component
16 w = w/sum(w); % normalize analysis window
17 sw = zeros(Ns,1);
18 ow = triang(2*H-1); % overlapping window
19 ovidx = Ns/2+1-H+1:Ns/2+H; % overlap indexes
20 sw(ovidx) = ow(1:2*H-1);
21 bh = blackmanharris(Ns); % synthesis window
22 bh = bh ./ sum(bh); % normalize synthesis window
23 sw(ovidx) = sw(ovidx) ./ bh(ovidx);
24 
25 
26 % Load melody file
27 melody = loadMelodyFile(melodyFile);
28 melody = [melody zeros(2,1000)];
29 i=0;
30 
31 % For each segment
32 while pin<pend
33 
34  i=i+1;
35 
36  % Find predominant pitch for segment
37  melody_seg = melody(:,ceil((pin-hM)/128):round((pin+hM)/128));
38  ind = find(melody_seg(2,:)>150); % Find pitches larger than 150Hz
39  medpitch = median(melody_seg(2,ind)); % Median pitch in segment
40 
41 
42  % Compute FFT for segment
43  xw = x(pin-hM:pin+hM).*w(1:M); % window the input sound
44  fftbuffer(1:(M+1)/2) = xw((M+1)/2:M); % zero-phase window in fftbuffer
45  fftbuffer(N-(M-1)/2+1:N) = xw(1:(M-1)/2);
46  X = fft(fftbuffer); % compute the FFT
47 
48  % Keep only the melody for each segment
49  if(isempty(ind)) % if there is no melody in segment, then silence segment
50  X = zeros(N,1);
51  else % if there is melody, then mask everything else
52 
53  melodyBinsStart = (medpitch/10.6568) * [1:40];
54  melodyBinsEnd = N + 2 - ((medpitch/10.6568) * [1:40]);
55  melodyBins = round([melodyBinsStart melodyBinsEnd]);
56  melodyBins = [melodyBins (melodyBins-1) (melodyBins+1) (melodyBins-2) (melodyBins+2) (melodyBins-3) (melodyBins+3) (melodyBins-4) (melodyBins+4) (melodyBins-5) (melodyBins+5) (melodyBins-6) (melodyBins+6)];
57 
58  C = setdiff(1:N,melodyBins);
59 
60  X(C) = 0;
61 
62  end;
63 
64 
65  ri= pin-hNs; % input sound pointer for residual analysis
66  yw = ifft(X);
67  y(ri:ri+Ns-1) = y(ri:ri+Ns-1)+yw(1:Ns).*sw;
68  pin = pin+H;
69 
70 end
71 
72 y = (max(x)/max(y))*y; % scale y to original amplitude
73 
74 %wavwrite(y,44100,'test.wav');
Definition: start.py:1
#define C
ow
Definition: extractMelody.m:18
if max(w)>1 w=0.9 *w/max(w)
half synthesis window size hM
Definition: extractMelody.m:11
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()
FFT size for synthesis(even) H
bh
Definition: extractMelody.m:21
#define sample
length of input sound array hNs
Definition: extractMelody.m:10
Load melody file melody
Definition: extractMelody.m:27
end end
#define N
Definition: vf_pp7.c:200
analysis window size Ns
Definition: extractMelody.m:7
last sample to start a frame fftbuffer
Definition: extractMelody.m:14
frame
Definition: stft.m:14
Discrete Time axis x
wavwrite(y, Fs3,'__RealRhodesSounds_D4.wav')
static const uint16_t mask[17]
Definition: lzw.c:37
#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
static av_always_inline av_const double round(double x)
Definition: libm.h:162
overlapping window(triangular window to avoid too much overlapping) ovidx
initialize buffer for FFT yw
Definition: gong.m:13
int size
half analysis window size pin
Definition: extractMelody.m:12
Definition: hls.c:58
initialize buffer for FFT y
Definition: extractMelody.m:15
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 file
Definition: fate.txt:34
Sampled sinusoid X
sound(x3, Fs)
i
Definition: extractMelody.m:29
initialize sound pointer to middle of analysis window pend
Definition: extractMelody.m:13
fftbuffer, N fft()
hop size for analysis and synthesis soundlength
Definition: extractMelody.m:9
overlapping window ovidx
Definition: extractMelody.m:19
output sine component w
Definition: extractMelody.m:16
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()
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
Same thing on a dB scale
FFT size for synthesis H
Definition: extractMelody.m:8
normalize analysis window sw
Definition: extractMelody.m:17
The official guide to swscale for confused that is
Definition: swscale.txt:2
Initialize M
Definition: extractMelody.m:6
const char int length
Definition: avisynth_c.h:668