What's the meaning of instrucment sound in Matlab?

4 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2019-11-10
"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.

请先登录,再进行评论。

回答(1 个)

John D'Errico
John D'Errico 2019-11-10
编辑:John D'Errico 2019-11-10
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.

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by