如何合成声音? [英] How to synthesize sounds?

查看:215
本文介绍了如何合成声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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之类的书

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.

玩得开心!

这篇关于如何合成声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆