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

조회 수: 1 (최근 30일)
Rizwan 2023년 4월 7일
답변: 埃博拉酱 2023년 4월 7일
% Define drum sounds
% 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없음 표시없음 숨기기
KALYAN ACHARJYA 2023년 4월 7일
Provide those audio data, so that we can try?
Rizwan 2023년 4월 7일
Pleases find the attached audio files

댓글을 달려면 로그인하십시오.

### 답변 (1개)

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