How to mix multiple audio signals in Matlab?
39 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am trying to mix 3 audiofiles in matlab.
The code is as follows.
[guitar, fs_g] = audioread('guitar.wav');
[bass, fs_b] = audioread('bass.wav');
[drums, fs_d] = audioread('drums.wav');
guitar_10s = guitar(1:fs_g*10);
bass_10s = bass(1:fs_b*10);
drums_10s = drums(1:fs_d*10);
mix = guitar_10s + bass_10s + drums_10s;
sound(mix, 44100)
I read in 3 audio files which are 16 bit 44.1kHz wav files.
They are stored as matrices with datatype: double precision normalized.
I cut them at 10 seconds from the beginning.
When I simply add 3 files that are cut, I see something strange when I look into 'mix'.
I see data that exceed 1 or -1.
Is it okay to just arithmetically add audio data that is normalized to make a summed mix?
Also, when I look into the data, It does not look precise at all compared to the data when I read the audiofiles in 'native' datatype. The data -1 <= y <= 1 in double precision doesn't seem like it actually is. Is there something wrong?
0 Kommentare
Antworten (1)
Star Strider
am 17 Okt. 2020
It is somewhat difficult to follow your code (and I cannot run it since my version of MATLAB can only run actual code, not images of code). However if you want to be certain that the sound remains between [-1 1], the easiest way would be to normalise it.
Example —
t = linspace(0,1,44100);
y = sin(2*pi*t*500)*2;
figure
plot(t,y)
y = y/max(abs(y)); % Normalise
sound(y, 44100)
Here, ‘y’ is originally ±2, however when normalised, it is ±1. That is likely the easiest way I can think of to be certain it meets that criterion.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Simulation, Tuning, and Visualization finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!