如何合成声音?

编程入门 行业动态 更新时间:2024-10-19 13:24:02
本文介绍了如何合成声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想产生类似于真实乐器音频的声音.问题是我几乎不知道该怎么做.

I'd like to produce sounds that would resemble audio from real instruments. The problem is that I have very little clue how to get that.

我与真正的乐器相比,我所知道的是它们输出的声音很少干净.但是如何产生这种不干净的声音呢?

What I know this far from real instruments is that sounds they output are rarely clean. But how to produce such unclean sounds?

到目前为止,我已经做到了,它会产生非常清晰的声音,我不确定它是否正确使用了alsa.

This far I've gotten to do this, it produces quite plain sound from which I'm not sure it's even using the alsa correctly.

import numpy from numpy.fft import fft, ifft from numpy.random import random_sample from alsaaudio import PCM, PCM_NONBLOCK, PCM_FORMAT_FLOAT_LE pcm = PCM()#mode=PCM_NONBLOCK) pcm.setrate(44100) pcm.setformat(PCM_FORMAT_FLOAT_LE) pcm.setchannels(1) pcm.setperiodsize(4096) def sine_wave(x, freq=100): sample = numpy.arange(x*4096, (x+1)*4096, dtype=numpy.float32) sample *= numpy.pi * 2 / 44100 sample *= freq return numpy.sin(sample) for x in xrange(1000): sample = sine_wave(x, 100) pcm.write(sample.tostring())

推荐答案

兴高采烈,如果您想(从头开始)生成听起来确实是有机"的东西,即像一个物理对象,那么您最好是学习一下关于这些声音是如何产生的.对于扎实的介绍,您可以看看Fletcher和Rossings之类的书乐器物理学.网络上也有很多东西,您可能想看看James Clark的入门书此处

Cheery, if you want to generate (from scratch) something that really sounds "organic", i.e. like a physical object, you're probably best off to learn a bit about how these sounds are generated. For a solid introduction, you could have a look at a book such as Fletcher and Rossings The Physics of Musical Instruments. There's lots of stuff on the web too, you might want to have a look at a the primer James Clark has here

至少对这些内容有所了解,可以使您大致了解要面对的问题.准确地建模物理仪器非常困难!

Having at least a skim over this sort of stuff will give you an idea of what you are up against. Modeling physical instruments accurately is very difficult!

如果您想要做的是听起来很物理的东西,而不是听起来像乐器X的东西,那么您的工作就容易一些.您可以很容易地建立频率并将它们堆叠在一起,增加一点噪音,并且您会得到至少听起来不像纯音的东西.

If what you want to do is have something that sounds physical, rather something that sounds like instrument X, your job is a bit easier. You can build up frequencies quite easily and stack them together, add a little noise, and you'll get something that at least doesn't sound anything like a pure tone.

通读一些有关傅立叶分析的知识,以及调频(FM)技术,都会有所帮助.

Reading a bit about Fourier analysis in general will help, as will Frequency Modulation (FM) techniques.

玩得开心!

更多推荐

如何合成声音?

本文发布于:2023-11-07 06:07:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!