www.gusucode.com > 声音的处理有:LPC,FFT,共振峰,频谱源码程序 > siganlandsystemusingMatlab/SSUM/birds/old/randbird.m
function signal = randbird(num_notes) %------------------------------------------------------- % MATLAB code created for MAT201a: Signals and Systems % Bob L. Sturm and Dr. Jerry Gibson % Copyright University of California, Santa Barbara %------------------------------------------------------- % ranbird.m % This code is a demonstration of additive synthesis % to synthesize random bird calls. Input a number of % notes. % % Author: Bob L. Sturm 20030707 %------------------------------------------------------- if (nargin == 1) num_birds = 1; end global Fs; Fs = 44100; % General purpose envelopes amp = [.00 .00 .25 1.00 .60 .70 .75 1.00 1.00 .0]; tap = [.00 .00 .01 1.00 .99 1.00 1.00 .0]; bird_amp = [.00 .00 .25 1.00 .75 1.00 1.00 .0]; partial = [1 1]; % Yellow Warbler yellow_up = [.00 .00 .60 1.00 1.0 0.5]; yellow_swirl= [.00 1.00 .05 1.00 .60 .00 .80 .30 1.0 0.1]; yellow_down = [.00 1.00 1.00 0]; yellow_last = [.00 .00 .30 .20 .80 .70 1.0 1.0]; swirl_amp = [.00 .00 .90 1.00 1.00 .0]; % Western_Meadowlark no_skw = [.00 .00 1.00 .0]; down_skw = [.00 1.00 .40 .40 1.00 .0]; fas_down = [.00 1.00 1.00 .0]; amp = [.00 .00 .25 1.00 .60 .70 .75 1.00 1.00 .0]; partials = [1 1 2 .04]; % 'Orchard_Oriole'; oriup = [.00 .00 1.00 1.0]; oridwn = [.00 1.00 1.00 .0]; oriupdwna = [.00 .00 .60 1.00 1.00 .60 ]; oriupdwnb = [.00 .50 .30 1.00 1.00 .0]; oribiga = [.00 .90 .15 1.00 .40 .30 .60 .60 .85 .00 1.00 .0]; orimid = [.00 1.00 .05 .50 .10 1.00 .25 .00 .85 .50 1.00 .0]; oridwnup = [.00 .30 .25 .00 1.00 1.0]; oriamp = [.00 .00 .10 1.00 1.00 .0]; % 'Chipping_Sparrow'; chip_up = [.00 .80 .15 1.00 .75 .30 1.00 .0]; % 'Scissor_Tailed_Flycatcher'; scissor = [.00 .00 .40 1.00 .60 1.00 1.00 .0]; % 'Black_Throated_Gray_Warbler'; grayone = [.00 .50 .02 .60 .04 .45 .06 .62 .08 .40 .10 .65 .12 .35 .14 ... .70 .18 .30 .20 .70 .22 .30 .24 .70 .25 .20 .30 .80 .35 .10 ... .40 .90 .45 .00 .50 1.00 .55 .00 .60 1.00 .65 .00 .70 1.00 ... .75 .00 .80 1.00 .85 .00 .90 1.00 .95 .00 1.00 .50]; graytwo = [.00 .00 .01 .40 .02 .00 .03 .40 .04 .00 .05 .40 .06 .00 .07... .40 .08 .00 .09 .40 .10 .00 .25 .80 .40 .30 .55 1.00 .70 .00 ... .85 .80 1.00 .40]; graythree = [.00 1.00 .01 .60 .02 1.00 .03 .60 .04 1.00 .05 .60 .06... 1.00 .07 .60 .08 1.00 .09 .60 .10 1.00 .11 .60 .12 1.00 .13... .60 .14 1.00 .15 .60 .16 1.00 .17 .60 .18 1.00 .19 .60 .20... 1.00 .21 .55 .22 1.00 .23 .50 .24 1.00 .25 .50 .26 1.00 .27... .50 .28 1.00 .29 .50 .30 1.00 .31 .50 .32 1.00 .33 .50 .34... 1.00 .35 .50 .36 1.00 .37 .50 .38 1.00 .39 .50 .40 1.00 .41... .50 .42 1.00 .43 .50 .44 1.00 .45 .50 .46 1.00 .47 .50 .48... 1.00 .49 .50 .50 1.00 .51 .50 .52 1.00 .53 .50 .54 1.00 .55... .50 .56 1.00 .57 .50 .58 1.00 .59 .50 .60 1.00 1.00 .0]; grayfour = [.00 .00 1.00 1.0]; % 'Cassins_Kingbird'; kingfirst = [.00 .30 .45 1.00 .90 .10 1.00 .0]; kingsecond = [.00 .00 .02 .50 .04 .00 .06 .55 .08 .05 .10 .60 .12... .05 .14 .65 .16 .10 .18 .70 .20 .10 .22 .75 .24 .15 .26... .80 .28 .20 .30 .85 .32 .25 .34 .90 .36 .30 .38 .95 .40... .40 .42 1.00 .44 .50 .46 1.00 .48 .45 .50 1.00 .52 .50... .54 1.00 .56 .40 .58 .95 .60 .40 .62 .90 .64 .40 .66 .85... .68 .35 .70 .80 .72 .30 .74 .75 .76 .25 .78 .70 .80 .20... .82 .65 .84 .10 .86 .60 .88 .00 .90 .55 .92 .00 .94 .50... .96 .00 1.00 .40]; % 'Black_Necked_Stilt'; upamp = [.00 .00 .90 1.00 1.00 .0]; rampup = [.00 .00 .50 1.00 1.00 .20]; % 'Chestnut_Sided_Warbler'; ycurve = [.00 1.00 .30 .50 .60 1.00 .80 .20 1.00 .0]; vcurve = [.00 .20 .50 1.00 1.00 .0]; wcurve = [.00 .50 .15 .00 .45 .10 .60 1.00 .70 .90 1.00 .90]; upcurve = [.00 .00 .95 1.00 1.00 1.0]; downcurve = [.00 1.00 .25 .30 .60 .15 1.00 .0]; louder = [.00 .00 .90 1.00 1.00 .0]; wamp = [.00 .00 .10 1.00 .40 .10 .50 .90 .60 .10 .70 1.00 1.00 .0]; partials = [1 1 2 .1]; % 'Great_Horned_Owl'; owlup = [.00 .00 .30 1.00 1.00 1.0]; owldown = [.00 1.00 1.00 .0]; partials = [1 1 3 .02 7 .01]; % 'Grasshopper_Sparrow'; grassone = [.00 .50 .02 .80 .04 .30 .06 .80 .07 .10 .08 .90 .10 .00 .11... .90 .12 .00 .13 .90 .14 .10 .15 1.00 .16 .10 .17 1.00 .18... .10 .19 1.00 .20 .10 .21 1.00 .22 .10 .23 1.00 .24 .10 .25... 1.00 .26 .10 .27 1.00 .28 .10 .29 1.00 .30 .10 .31 1.00 .32... .10 .33 1.00 .34 .10 .35 1.00 .36 .10 .37 1.00 .38 .10 .39... 1.00 .40 .10 .41 1.00 .42 .10 .43 1.00 .44 .10 .45 1.00 .46... .10 .47 1.00 .48 .10 .49 1.00 .50 .10 .51 1.00 .52 .10 .53... 1.00 .54 .10 .55 1.00 .56 .10 .57 1.00 .58 .10 .59 1.00 .60... .10 .61 1.00 .62 .10 .63 1.00 .64 .10 .65 1.00 .66 .10 .67... 1.00 .68 .10 .69 1.00 .70 .10 .71 1.00 .72 .10 .73 1.00 .74... .10 .75 1.00 .76 .10 .77 1.00 .78 .10 .79 1.00 .80 .10 .81... 1.00 .82 .10 .83 1.00 .84 .10 .85 1.00 .86 .10 .87 1.00 .88... .10 .89 1.00 .90 .10 .91 1.00 .92 .10 .93 1.00 .94 .10 .95... 1.00 .96 .10 .97 1.00 .98 .10 1.00 1.0]; grasstwo = [.00 .00 .10 1.00 .20 .00 .30 1.00 .40 .00 .50 1.00 .60 .00... .70 1.00 .80 .00 .90 1.00 1.00 .0]; % 'Swamp_Sparrow'; swamp_up = [.00 .00 .60 .70 1.00 1.0]; swamp_down = [.00 1.00 .50 .50 .60 .60 1.00 .0]; % 'Golden_Crowned_Sparrow'; goldone = [.00 1.00 .25 .20 1.00 .0]; goldtwo = [.00 .90 .05 1.00 .10 .40 1.00 .0]; goldtrill = [.00 .50 .10 .00 .20 1.00 .30 .00 .40 1.00 .50 .00 .60 1.00 ... .70 .00 .80 1.00 .90 .00 1.00 .50]; % 'Indigo_Bunting'; buntdwn =[.00 1.00 1.00 .0]; buntv =[.00 .00 .50 1.00 1.00 .0]; bunty =[.00 1.00 .50 .00 1.00 .90 ]; buntn =[.00 .80 .30 1.00 .70 .20 1.00 .0]; buntx =[.00 1.00 .10 .50 .25 .90 1.00 .0]; buntup =[.00 .00 1.00 1.0]; % 'Robin'; r_one = [.00 .10 .08 .70 .30 .00 .35 1.00 .40 .30 1.00 .30]; r_two =[.00 .00 .10 1.00 .20 .70 .35 .70 .65 .30 .70 .50 .80 .00... .90 .20 1.00 .0]; r_three =[.00 .20 .25 1.00 .60 .70 .90 .00 1.00 .10]; r_four =[.00 1.00 1.00 .0]; r_five =[.00 .50 .10 .00 .20 1.00 .30 .00 .40 1.00 .50 .00 .60 1.00 ... .70 .50 1.00 .20]; r_six =[.00 .00 .12 .70 .30 .00 .70 1.00 1.00 .50]; partials = [1 1 2 .1]; % 'Nashville_Warbler'; nash_blip = [.00 .60 .35 1.00 1.00 .0]; nash_down =[.00 .90 .05 1.00 .10 .90 .65 .50 1.00 .0]; nash_up =[.00 .00 .15 .20 .25 .05 .90 .95 1.00 1.0]; nash_amp =[.00 .00 .80 1.00 1.00 .0]; % 'Rufous_Sided_Towhee'; towhee_one =[.00 .10 .02 .05 .04 .15 .06 .05 .08 .20 .10 .04 .12... .25 .14 .03 .16 .30 .18 .02 .20 .35 .22 .01 .24 .40 .26... .00 .28 .45 .30 .00 .32 .50 .34 .00 .36 .50 .80 1.00 1.00 .0]; towhee_two =[.00 .00 1.00 1.0]; towhee_three =[.00 1.00 1.00 .0]; freq_envelopes = {yellow_up yellow_swirl yellow_down yellow_last ... no_skw down_skw fas_down oriup oridwn oriupdwna oriupdwnb ... oribiga orimid oridwnup grayone graytwo graythree grayfour ... kingfirst kingsecond rampup ycurve vcurve wcurve upcurve ... downcurve owlup owldown grassone grasstwo swamp_up swamp_down ... goldone goldtwo goldtrill buntdwn buntv bunty buntn buntx ... buntup r_one r_two r_three r_four r_five r_six nash_blip ... nash_down nash_up towhee_one towhee_two towhee_three chip_up}; amp_envelopes = {amp swirl_amp oriamp scissor upamp louder wamp ... nash_amp bird_amp tap}; partials = {[1 1] [1 1 2 .04] [1 1 2 .02 3 .05] [1 1 2 .5 3 0 4 .2] ... [1 1 2 .01 3 0 4 .1] [1 1 2 .1] [1 1 3 .02 7 .01] [1 .03 2 1 3 .03]}; pscore = cell(num_notes,8); beg = 0; dur = 0; for i=1:num_notes, beg = beg + dur + rand*0.2; dur = rand*0.2 + 0.05; freq = 1000 + 2000*rand; freqskew = rand*freq/2; freq_env = freq_envelopes{floor(rand*size(freq_envelopes,2))+1}; amp_env = amp_envelopes{floor(rand*size(amp_envelopes,2))+1}; partial = partials{floor(rand*size(partials,2))+1}; amplitude = rand*0.5/size(partials,2)/2; pscore(i,:) = {beg dur freq freqskew amplitude freq_env amp_env partial}; %fprintf(['\tbeg=%3.2f dur=%3.2f freq=%4.2f freqskew=%4.2f amp=%3.2f\n'],beg,dur,freq,freqskew,amplitude); %fprintf('%d\tamp_env = [',i); %for j=1:size(amp_env,2), % fprintf('%2.2f ',amp_env(j)); %end %fprintf(']\n'); %fprintf('\tfreq_env = ['); %for j=1:size(freq_env,2), % fprintf('%2.2f ',freq_env(j)); %end %fprintf(']\n'); %fprintf('\tpartial = ['); %for j=1:size(partial,2), % fprintf('%2.2f ',partial(j)); %end %fprintf(']\n\n'); end signal = synth(pscore,Fs,'add'); birdname = ['RandBird_' num2str(rand*5280) '_' char(floor(rand*26+65))]; fprintf('%s\n', birdname); %wavwrite(signal,Fs,16,[birdname '.wav']);