What's the meaning of instrucment sound in Matlab?

3 Ansichten (letzte 30 Tage)
dachui wang
dachui wang am 9 Nov. 2019
Bearbeitet: John D'Errico am 10 Nov. 2019
I am super confused about how to add an instrument sound to a voice in Matlab? Literally, I don't know what the instrument sound is. Thanks in advance!
  1 Kommentar
Walter Roberson
Walter Roberson am 10 Nov. 2019
"instrument sound" is related to the characteristics that make one music instrument sound different from another kind of instrument. But in your particular case, you just need to read in a the sound of some musical instruments playing, and mix them with the sound of a human voice that you read in from a different file.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

John D'Errico
John D'Errico am 10 Nov. 2019
Bearbeitet: John D'Errico am 10 Nov. 2019
Let me just answer this as if you asked for an explanation of what a sound is in the world of MATLAB. For example, if we try:
load handel
what do we get?
whos
Name Size Bytes Class Attributes
Fs 1x1 8 double
y 73113x1 584904 double
We get a simple vector of numbers, as well as the number Fs. If we then type:
sound(y,Fs)
then as long s your speakers are turned on, we will hear almost 9 seconds of a rendition of Handel's Hallelujah Chorus. Since Fs is the sample frequency in Hz, it should be 8.9249 seconds.
73113/8192
ans =
8.9249
The vector is a string of bits, representing a monaural representation. (If it were stored as a stereo repreentation, then y would have been an Nx2 array, for the left and right channels respectively.) The vector y is scaled in the interval [-1,1], representing the mono audio signal.
So what is that audio signal? Sound would be seen as a pressure wave in the air, in this case, sampled at a rate of 8192 samples per second.
If we were to try
t = linspace(0,2*pi,8192);
soundsc(sin(1000*t))
then we would hear one second of a pure tone at 1000 Hz, sampled at 8192 Hz.
But we can actually add two such sounds, now hearing a slightly more complicated sound. Soundsc will automatically scale the result to [-1,1].
soundsc(sin(1000*t) + sin(500*t))
So, if you had two tracks of sound, one from someone singing and one of a guitar playing the same song and sampled at the same rate for the same length of time, then you could literally add the two tracks together.
Thus, while I don't have 8.9 seconds of an instrumental recording, I might do this:
S1 = load('handel');
S2 = load('gong');
soundsc(S1.y(1:42028) + S2.y)
and the result would be a few seconds of the chorus, with now a gong in the background.

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by