本文整理汇总了Python中Math.frequency_to_semitone方法的典型用法代码示例。如果您正苦于以下问题:Python Math.frequency_to_semitone方法的具体用法?Python Math.frequency_to_semitone怎么用?Python Math.frequency_to_semitone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Math
的用法示例。
在下文中一共展示了Math.frequency_to_semitone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyze_overtones
# 需要导入模块: import Math [as 别名]
# 或者: from Math import frequency_to_semitone [as 别名]
def analyze_overtones(self,semitone,overtones=None):
""" calculates power and peak center for each overtone and yields tuples (overtone, frequency, power, peak_center, difference_in_semitones) """
frequency = Math.semitone_to_frequency(semitone)
peak_radius = self.get_peak_radius()
overtone=0
while overtones==None or overtone<overtones:
f = frequency*(overtone+1)
s = Math.frequency_to_semitone(f)
lower_frequency = f - peak_radius*1.65
upper_frequency = f + peak_radius*1.65
lower_frequency = min(lower_frequency, Math.semitone_to_frequency(s-0.5))
upper_frequency = max(upper_frequency, Math.semitone_to_frequency(s+0.5))
power = self.get_power_in_frequency_range(lower_frequency,upper_frequency)
peak_center = self.get_powerfreq_spline().integral(lower_frequency,upper_frequency) / power
difference_in_semitones = Math.frequency_to_semitone(peak_center) - s
yield overtone, f, power, peak_center, difference_in_semitones
overtone += 1
示例2: overtones_to_equalizer
# 需要导入模块: import Math [as 别名]
# 或者: from Math import frequency_to_semitone [as 别名]
def overtones_to_equalizer(self, control, semitone, overtones=10):
if not self.project:
return
x = self.project.pipeline.eq.frequencies
y = self.project.pipeline.eq.props.transmission
fundamental_frequency = Math.semitone_to_frequency(semitone)
for overtone in xrange(overtones + 1):
frequency = fundamental_frequency * (overtone + 1)
semitone = Math.frequency_to_semitone(frequency)
lower = Math.semitone_to_frequency(semitone - 0.5)
upper = Math.semitone_to_frequency(semitone + 0.5)
if lower > x[-1]:
break
for i in xrange(len(x)):
if x[i] > upper:
break
if lower <= x[i]:
y[i] = 1.0
self.project.pipeline.eq.props.transmission = y
示例3: analyze_semitone
# 需要导入模块: import Math [as 别名]
# 或者: from Math import frequency_to_semitone [as 别名]
def analyze_semitone(self, control, semitone):
if not self.project:
return
if not control.has_data:
return
text = ""
for overtone, frequency, power, peak_center, difference_in_semitones in control.analyze_overtones(semitone, 10):
s = Math.frequency_to_semitone(frequency)
position = control.start + control.duration / 2.0
lower = Math.semitone_to_frequency(s - 0.5)
upper = Math.semitone_to_frequency(s + 0.5)
onset_min, onset_max = self.project.appsinkpipeline.find_onset(lower, upper, position, limit=5)
text += "%d. overtone: %f Hz (semitone %f; near %s)\n" % (overtone, frequency, s, Math.note_name(s))
text += "\tPower: %f (%f dB)\n" % (power, Math.power_to_magnitude(power))
text += "\tPosition: %f Hz (off by %f semitones)\n" % (peak_center, difference_in_semitones)
text += "\tOnset: between %fs and %fs\n" % (onset_min, onset_max)
text += "\n"
w = gtk.Window()
w.set_size_request(500, 400)
w.set_title("Info on %s (%f)" % (Math.note_name(semitone), semitone))
sw = gtk.ScrolledWindow()
w.add(sw)
tv = gtk.TextView()
tv.get_buffer().set_text(text)
tv.set_editable(False)
sw.add(tv)
w.show_all()
示例4: analyze_semitone
# 需要导入模块: import Math [as 别名]
# 或者: from Math import frequency_to_semitone [as 别名]
def analyze_semitone(self,semitone,overtones=10, undertones=2, undertone_limit=80.):
""" calculate total power, inharmonicity and independence coefficients """
analysis = self.analyze_overtones(semitone,overtones)
# fundamental tone
overtone, fundamental_frequency, power, peak_center, difference_in_semitones = analysis.next()
fundamental_power = power
fundamental_diff_square = power * difference_in_semitones**2.
fundamental_diff = power * difference_in_semitones
# overtones
overtone_power = 0
overtone_diff_squares = 0
overtone_diffs = 0
for overtone, frequency, power, peak_center, difference_in_semitones in analysis:
overtone_power += power
overtone_diff_squares += power * difference_in_semitones**2.
overtone_diffs += power * difference_in_semitones
total_power = fundamental_power + overtone_power
diff_squares = fundamental_diff_square + overtone_diff_squares
diffs = fundamental_diff + overtone_diffs
center = diffs/total_power
variance = diff_squares/total_power - center**2.
standard_deviation = numpy.sqrt(variance)
# calculate upper_dependence
# if fundamental_frequency<150.: fp = fundamental_power*15. # exception for low-pitched tones
# else: fp = fundamental_power
# alien_power = max(0, overtone_power - 0.5*fp)
alien_power = max(0, overtone_power - 0.5*fundamental_power)
upper_dependence = alien_power / total_power
print "upperdependence of %d is %f" % (semitone, upper_dependence)
# calculate lower_dependence
peak_radius = self.get_peak_radius()
undertone_power = 0
for undertone in xrange(2,undertones+2):
undertone_frequency = fundamental_frequency / undertone
if undertone_frequency < undertone_limit: break
s = Math.frequency_to_semitone(undertone_frequency)
lower_frequency = undertone_frequency - peak_radius*1.65
upper_frequency = undertone_frequency + peak_radius*1.65
lower_frequency = min(lower_frequency, Math.semitone_to_frequency(s-0.5))
upper_frequency = max(upper_frequency, Math.semitone_to_frequency(s+0.5))
power = self.get_power_in_frequency_range(lower_frequency,upper_frequency)
power /= undertone**2.
# if undertone_frequency>150.: power *= 15
undertone_power += power
lower_dependence = undertone_power / total_power
print "lowerdependence of %d is %f (%f/%f)" % (semitone, lower_dependence, undertone_power, total_power)
return fundamental_power, total_power, center, standard_deviation, upper_dependence, lower_dependence
示例5: get_semitone
# 需要导入模块: import Math [as 别名]
# 或者: from Math import frequency_to_semitone [as 别名]
def get_semitone(self):
if self.semitone==None: self.semitone = Math.frequency_to_semitone(self.frequency)
return self.semitone