在 MATLAB 中创建淡入/淡出函数?
我希望创建一个函数,可以在 .wav 文件上创建五秒内的淡入/淡出功能。
我在 MATLAB 论坛上找到了这段代码,但似乎实现略有错误,尽管正确的想法是存在的。它适用于 300 毫秒的 .WAV 文件,淡入/淡出时间为 10 毫秒:
tenmssamples = length(soundfile)*10/300;
fade1 = linspace(0,1,tenmssamples);
fadedsound = soundfile .* ...
[fade1, ones(1,length(soundfile)-2*tenmssamples), fliplr(fade1)];
tenmssamples = length(soundfile)*10/300;
fade2 = sin(linspace(0,2*pi/4,tenmssamples));
fadedsound2 = soundfile .* ...
[fade2, ones(1,length(soundfile)-2*tenmssamples), fliplr(fade2)];
我可以通过尝试使用 linspace 缩放由递增函数读取的波形的前 10 个样本来了解他试图做什么,但我尝试过修补并修改它,但我无法让它工作。
请问有人有什么建议吗?谢谢。
I am looking to create a function that could create a fade-in/fade-out function on a .wav file over a period of five seconds.
I found this code on the MATLAB forums but it seems the implementation was slightly wrong, although the right idea is there. It was for .WAV files of 300ms with a 10ms fade-in/out:
tenmssamples = length(soundfile)*10/300;
fade1 = linspace(0,1,tenmssamples);
fadedsound = soundfile .* ...
[fade1, ones(1,length(soundfile)-2*tenmssamples), fliplr(fade1)];
tenmssamples = length(soundfile)*10/300;
fade2 = sin(linspace(0,2*pi/4,tenmssamples));
fadedsound2 = soundfile .* ...
[fade2, ones(1,length(soundfile)-2*tenmssamples), fliplr(fade2)];
I can see what he was trying to do by trying to scale the first 10 samples of the waveform read by an increasing function using linspace, but I have tried to tinker and modify it but I cannot get it to work.
Does anyone have any suggestions please? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你遇到的问题是什么,但我会做这样的事情:
当然你可以用 sigmoid 等其他东西替换 linspace,并使用相同的想法进行淡出...
编辑:要淡出,请尝试
I'm not sure what the problem you are encountering is, but I would do something like this:
of course you can replace the linspace by something else like a sigmoid, and use the same idea to do a fade out...
EDIT: to do the fade out, try