Added example file for pitch shifting

This commit is contained in:
The Cheaterman 2016-06-05 16:55:17 +02:00
parent a2d394e580
commit 333ee9c5b4
1 changed files with 44 additions and 0 deletions

44
examples/audio/pitch.py Normal file
View File

@ -0,0 +1,44 @@
# encoding: utf8
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.core.audio import SoundLoader
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from sys import version_info
NOTES = (
('Do', 1),
('', 9/8.),
('Mi', 5/4.),
('Fa', 4/3.),
('Sol', 3/2.),
('La', 5/3.),
('Si', 15/8.),
)
class Test(App):
def build(self):
self.sound = SoundLoader.load(
'/usr/lib64/python{}.{}/test/audiodata/pluck-pcm32.wav'
.format(*version_info[0:2])
)
print(self.sound.source)
root = BoxLayout()
for octave in range(3):
for note, pitch in NOTES:
button = Button(text=note)
button.pitch = pitch * 2 ** octave
button.bind(on_release=self.play_note)
root.add_widget(button)
return root
def play_note(self, button):
print(button.text, button.pitch)
self.sound.pitch = button.pitch
self.sound.play()
Test().run()