Please help to solve: Index in position 1 exceeds array bounds. Index must not exceed 1.
1 回表示 (過去 30 日間)
古いコメントを表示
% Define drum sounds
open_hihat = audioread('open_hihat.wav');
closed_hihat = audioread('closed_hihat.wav');
snare_drum = audioread('snare_drum.wav');
bass_drum = audioread('bass_drum.wav');
tom_toms = audioread('tom_toms.wav');
cymbals = audioread('cymbals_sound.wav');
% Load the drum sounds into a cell array
drum_sounds = {open_hihat, closed_hihat, snare_drum, bass_drum, tom_toms, cymbals};
% Define the bpm and the number of beats in the song
fs=44100;
bpm = 130;
num_beats = 457;
% Calculate the period between two beats in seconds
period = 130 / bpm;
% Load the drum table from Table 1
drum_table = [0 1 1 1 0 0 0 1 1;
0 0 0 1 0 1 1 0 1;
0 1 0 1 1 0 0 1 1;
1 1 1 1 1 0 0 0 1;
0 0 0 1 0 1 1 0 1;
0 0 0 1 0 1 1 0 1;];
% Initialize the audio signal
audio_signal = zeros(1, num_beats * fs * period);
% Loop through each beat in the song and add the corresponding drum sounds
for i = 1:num_beats
for j = 1:6
if drum_table(j,i) == 1
start_index = round((i-1) * fs * period) + 1;
end_index = start_index + size(drum_sounds{j}) - 1;
audio_signal(start_index:end_index,:) = audio_signal(start_index:end_index,:) + drum_sounds{j};
end
end
end
% Normalize the audio signal
audio_signal = audio_signal / max(abs(audio_signal));
% Write the audio signal to a wave file
audiowrite('assign_drum_beats.wav', audio_signal, fs);
2 件のコメント
回答 (1 件)
埃博拉酱
2023 年 4 月 7 日
Your audio_signal is an 1×n row vector but you're trying to get its start_index:end_index rows.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Audio and Video Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!