简体   繁体   English

如何在 MATLAB 中连接/合并两个声音以同时播放?

[英]How to concatenate/merge two sounds to play simultaneously in MATLAB?

I am required to make a song in MATLAB that features sampled noises and tones playing simultaneously, from research and what I was given it looked like it should be as simple as summing the two sounds, however I have been unable to figure it out.我需要在 MATLAB 中制作一首歌曲,该歌曲具有同时播放的采样噪声和音调,根据研究,我得到的似乎应该像将两种声音相加一样简单,但我一直无法弄清楚。 This is the code I've tried, I am new to coding so it may be inefficient.这是我尝试过的代码,我是编码新手,所以它可能效率低下。 The length of 'snare' and 'A' are equal, both 1025. 'snare' 和 'A' 的长度相等,都是 1025。

load splat; y_splat = y;
Fs = 8192;             % the sampling rate
t = 0:1/Fs:0.125;      % an array of t values equally spaced from 0 to 0.125
f1 = 220;
A = sin(2*pi*f1*t);
snare = y_splat(7400:8424);

A_new = A + snare;
soundsc(A_new)

This code results in an error message: Only one- and two-channel audio supported.此代码导致错误消息:仅支持单声道和双声道音频。 What am I doing wrong?我究竟做错了什么? Any help would be appreciated.任何帮助,将不胜感激。

You have a dimension mismatch, snare is 1025x1 and A is 1x1025.您的尺寸不匹配, snare为 1025x1, A为 1x1025。 Solve it by transpose one of them eg A_new = A + snare';通过转置其中一个来解决它,例如A_new = A + snare';

I realised shortly after posting that the dimensions were mismatched.我在发布后不久意识到尺寸不匹配。 A simple apostrophe fixed the issue.一个简单的撇号解决了这个问题。 Thank you for your responses.谢谢你的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM