我是Python的新手其他来源。我的目的是在给定频率下创建一个具有振幅调制的棕色噪声的波浪文件。我想产生棕色噪声并调节它。
我打算使用Python Acoustics软件包,不幸的是,我不明白如何使用这些功能创建彩色噪声。我查看了示例,但我看不到彩色噪音功能的示例。
有人可以帮助我解决这个问题吗?谢谢。
这是我的代码:
""" This file proposes to modulate a given wav file"""
import wave
import struct
import time
import math
import random
import acoustics
###########################################
# General variables
outputName = "waveXP.wav"
frequencyModulation = 40
period = 1/frequencyModulation
duration = 1
maxVolume = 23000.0
framerate = 44100
###########################################
# Ask the user about the output file name
temp = ""
temp = input("Name of the output wave file to import (with extension):")
if temp != "":
outputName = str(temp)
# Ask the user about the modulation frequency wanted
temp = ""
temp = input("Modulation frequency wanted (in hertz):")
if temp != "":
frequencyModulation = int(temp)
period = 1/frequencyModulation
# Ask the user about the duration wanted
temp = ""
temp = input("Duration wanted (in seconds):")
if temp != "":
duration = int(temp)
print("------------------------")
###########################################
# Create the output wave file
newWaveFile = wave.open(outputName, "w")
# Define parameters of the wave file
# nchannels = 1 for mono; sampwidth = 2 for 2 bytes per sample; framerate = 44100 for wave file;
# comptype = "NONE" for no compression support; compname = 'not compressed' for no compression support
newWaveFile.setparams([1, 2, framerate, duration, 'NONE', 'not compressed'])
# Generate noise
newWaveFile.writeframes(struct.pack('h'*framerate*duration, *int(maxVolume*0.7*acoustics.generator.brown(framerate*duration))))
# Close wave files
originalWaveFile.close()
newWaveFile.close()
看起来您所提出的库已经有一个棕色的噪声生成器:
http://python-acoustics.github.io/python-acoustics/generator.html
假设您只想将单个调制作为振幅增益应用于整个信号,那么您需要以信号的采样速率采样调制,然后将调制(时间某个比例因子(添加到棕色噪声信号。另外,您可以将信号乘以调制,但这将是一个更加极端的效果。