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

2 visualizzazioni (ultimi 30 giorni)
Rizwan il 7 Apr 2023
Risposto: 埃博拉酱 il 7 Apr 2023
% 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 CommentiMostra NessunoNascondi Nessuno
KALYAN ACHARJYA il 7 Apr 2023
Provide those audio data, so that we can try?
Rizwan il 7 Apr 2023
Pleases find the attached audio files

Accedi per commentare.

### Risposte (1)

Your audio_signal is an 1×n row vector but you're trying to get its start_index:end_index rows.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Audio and Video Data in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by