我对python完全陌生,所以我试着阅读并学习我能做的事情,但我似乎不能做我想做的事情,而且我还没有在堆栈溢出或其他源上找到解决方案。我的目标是创建一个布朗噪声的波形文件,并在给定的频率上进行调幅。我想产生棕色噪音并对其进行调制。
我打算使用python声学软件包,不幸的是,我不明白如何使用这些函数来创建有色噪声。我看了这些例子,但我没有看到彩色噪声函数使用的例子。
有人能帮我解决这个问题吗?谢谢。
这是我的代码:
""" 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()发布于 2020-06-03 21:18:54
看起来您的建议库已经有了一个棕色噪声发生器:
http://python-acoustics.github.io/python-acoustics/generator.html
假设您只想将单个调制应用于整个信号的幅度增益,那么您将希望以信号的采样速率对您的调制进行采样,并将调制(乘以某个尺度因子)添加到棕色噪声信号中。或者,你可以将信号乘以调制,但这将是一个更极端的影响。
https://stackoverflow.com/questions/49515144
复制相似问题