简体   繁体   中英

Matlab - Double duration of .wav

I'm creating individual notes from a single note thats read in using the wavread function.

I'm using the resample function to create these notes. eg:

    f5  = resample(a,440,698); %creates note.
    f5_short  = f5(dur:Hz);    %creates duration of note (ie 1 sec)
    f5_hf  = f5_short(dur:Hz/2); %creates note of half duration

The above code seems to work well. Unfortunately i'm having trouble creating a "double note"... I don't want to just play the same note twice and i've tried the following:

    f5_db  = f5_short(dur*2:Hz); %exceeds size of matrix
    f5_db  = f5_short(dur:Hz*2); %exceeds size of matrix
    f5_db  = resample(f5_short,Hz*2,330); %tried upSampling it and although lengths it, note becomes deeper.

Whats the easiest why to double the length of a not/wav without changing the note? (stretch but maintain the correct note?) Thanks.

You need to double the size of f5_short , not to index it:

f5_db = repmat(f5_short, 2, 1);

or just

f5_db = [f5_short; f5_short];

If you have pause in the beginning and in the end of f5_short , but the middle sequence is constant, you can reproduce the middle to get double note. Something like this:

f5_short_len = length(f5_short);
f5_short_mid = floor(f5_short_len/2);
f5_db = [f5_short(1:f5_short_mid,:); ...
         repmat(f5_short(f5_short_mid,:),f5_short_len,1); ...
         f5_short(f5_short_mid+1:f5_short_len,:)];

If you want to remove the pauses;

f5_short = repmat(f5_short(f5_short_mid),f5_short_len,1);
f5_db = repmat(f5_short, 2, 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM