Please help to solve: Index in position 1 exceeds array bounds. Index must not exceed 1.

조회 수: 6 (최근 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);

답변 (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.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by