- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
#Sine wave calculations by vegaseat.
#The program will take in the current time that the computer has, and turn that into a
#tone that is unique to that moment in time. It then makes an accompaning graph to
#view for easier comparison of the sound and an interesting view of the sound heard.
from Tkinter import *
from struct import pack
from math import sin, pi
import math
import time
import os
def wave():
#time based variables
t = time.strftime("%S", time.localtime())
ti = time.strftime("%M", time.localtime())
tis = float(t)
tis = tis / 100
tim = float(ti)
tim = tim / 100
root = Tk()
root.title("The moment")
#variables for canvas
width = 800
height = 600
center = height//2
x_increment = 2
# width stretch
x_factor1 = tis
x_factor2 = tim
# height stretch
y_amplitude = 50
#new canvas
c = Canvas(width=width, height=height, bg="black")
c.pack()
str1 = "sin(x)=white"
c.create_text(10, 20, anchor=SW, text=str1)
center_line = c.create_line(0, center, width, center, fill="red")
# create the coordinate list for the sin() curve, have to be integers
xy1 = []
xy2 = []
for x in range(400):
# x coordinates
xy1.append(x * x_increment)
xy2.append(x * x_increment)
# y coordinates
xy1.append(int(math.sin(x * x_factor1) * y_amplitude) + center)
xy2.append(int(math.sin(x * x_factor2) * y_amplitude) + center)
#create the lines
sinS_line = c.create_line(xy1, fill="white")
sinM_line = c.create_line(xy2, fill="yellow")
root.mainloop()
def au_file(name, freq, freq1, dur, vol):
fout = open(name, "wb")
# header needs size, encoding=2, sampling_rate=8000, channel=1
fout.write(".snd" + pack(">5L", 24, 8*dur, 2, 8000, 1))
factor = 2 * pi * freq/8000
factor1 = 2 * pi * freq1/8000
# write data
for seg in range(8 * dur):
# sine wave calculations
sin_seg = sin(seg * factor) + sin(seg * factor1)
fout.write(pack("b", vol * 64 * sin_seg))
fout.close()
#time based variables
t = time.strftime("%S", time.localtime())
ti = time.strftime("%M", time.localtime())
tis = float(t)
tis = tis * 100
tim = float(ti)
tim = tim * 100
os.startfile("timeSound.au")
#running it using main.
def main():
au_file(name="timeSound.au", freq=tim, freq1=tis, dur=1000, vol=1.0)
wave()
main()
这是我的程序,它会记录分钟并让它们根据时间(某种程度)产生正弦波音调。它创建声音文件然后播放它。我想要的是实时流式传输正弦波,其影响时间可低至毫秒,以获得恒定的波动音调。那可能吗?如果是这样,我可以使用什么来让声音实时播放,如何将变量连接到时间并使其本身实时播放?
最佳答案
以下是您可以采用的连续变化频率的方法:
def gen_scale(samples_per_wave, samples_per_change):
pi2 = 2 * math.pi
rad = 0
while (samples_per_wave > 1):
for i in range(0, samples_per_change):
yield math.sin(rad)
rad = rad + pi2 / samples_per_wave
if (rad > pi2):
rad = rad - pi2
samples_per_wave = samples_per_wave - 1
samples_per_wave
基本上是 Hz
测量值的倒数(此声音的频率会增加)。 samples_per_change
是生成器在增量调整频率之前生成的样本数量。
关于python - 根据时间相关变量不断变化的正弦音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8372980/
我写的函数有问题。想法是使用 taylor 展开而不是 js 数学对象来计算 sin 和 cosin 值(在 radians 上运行) .这些是方程式: sin(x) = (x^1)/1! - (x^
我不知道这是编程还是数学问题,但我整理了一些FFT的简短示例。我加载了440hz的波并在顶部添加了一些正弦波,但是由于某种原因,频谱中存在一个我不理解的“波”。 据我了解,频谱应该具有相同的| Y(f
这个问题在这里已经有了答案: Java Math.cos(Math.toRadians()) returns weird values (4 个答案) 关闭 10 年前。 我正在编写一个程序,我必须
我想在 ios4 中实现一个正弦和余弦计算器: if([operation isEqual:@"sin"]){ operand = (operand*M_PI/180.0); oper
我使用 256 个元素为 VHDL 制作了一个正弦 LUT。 我使用 MIDI 输入,因此值范围为 8.17Hz(注 #0)到 12543.85z(注 #127)。 我有另一个 LUT 计算必须发送到
我想在ios4中实现一个正弦和余弦计算器: if([operation isEqual:@"sin"]){ operand = (operand*M_PI/180.0); operan
我是一名优秀的程序员,十分优秀!