【问题标题】:Cross fading multiple audio files of different lengths together in matlab / octave在matlab / octave中交叉淡化多个不同长度的音频文件
【发布时间】:2016-04-11 09:22:45
【问题描述】:

您好,我正在尝试将多个音频文件交叉淡入淡出(大约 40 个文件,长度大约 30 到 54 秒或更长)。我正在使用 octave 3.8.1(类似于 matlab)。这些文件都有不同的文件长度。我发现一些代码仅在文件具有相同长度并且仅交叉淡入淡出两个文件cross fade code link 时才有效。如何交叉淡化具有不同文件长度的多个文件? 所以 S2 将是 S2=rand(911,1) + 1;或 S3=rand(932,1) + 1;或 S4=rand(654,1);等等……

S1 = rand(1000,1);
S2 = rand(1000,1) + 1; % so S2 would be S2=rand(911,1)

%\\ cross-fade over last 200 elements
n = 200;

W = linspace(1,0,n)';                                    %'

S1(end-n+1:end) = S1(end-n+1:end).*W;
S2(1:n) = S2(1:n).*(1-W);

S12 = zeros(size(S1,1) + size(S2,1) - n, 1);
S12(1:size(S1,1)) = S1;
S12(end-size(S1,1)+1:end) = S12(end-size(S1,1)+1:end) + S2;

【问题讨论】:

    标签: matlab signal-processing octave


    【解决方案1】:

    在这里,我将淡入淡出两个窦。第一个为 1kHz,第二个为 2.2kHz。第一个正弦的长度是 10s,第二个是 15s。

    我将在 6 秒后开始交叉淡入淡出,淡入淡出需要 4 秒,因此结果长度为 6+4+15-4 = 21 秒长

    ## use FS=44800 to hear it
    FS = 44800;
    
    t1 = linspace (0, 10, FS * 10);
    t2 = linspace (0, 15, FS * 15);
    
    ## crossfade in 4s
    cl = 4 * FS;
    c = linspace (0, 1, cl);
    
    a1 = 0.5 * sin (2 * pi * 1e3 * t1); # 1kHz
    a2 = 0.9 * sin (2 * pi * 2.2e3 * t2); # 2.2kHz
    
    ## 100% a1 from 0..6s
    s1 = a1(1:end-cl);
    
    ## crossfade a1 to a2 in 4s
    s2 = a1(end-cl+1:end) .* (1-c) + a2(1:cl) .* c;
    
    ## 100% a2 for 11s
    s3 = a2(cl+1:end);
    
    ## concatenate them
    s = [s1 s2 s3];
    t = linspace (0, numel(s)/FS, numel (s));
    
    subplot (2, 1, 1);
    plot (t , s)
    xlabel ("t [s]")
    grid on
    wavwrite (s, FS, "out.wav");
    
    ## plot the FFT
    f = linspace (0, FS/2, numel (s)/2);
    subplot (2, 1, 2);
    plot (f, abs (fft (s))(1:numel(s)/2));
    grid on
    xlabel ("f [Hz]")
    

    这里是频谱图。你可以清楚地看到淡入淡出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2020-07-12
      • 1970-01-01
      • 2012-04-27
      相关资源
      最近更新 更多