* PySFML now compiles and runs with python3 (and still compiles and runs
with python 2.5) * Improved support for unicode * Fixed a mysterious bug with the opengl sample * Code clean up git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1024 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
af3dd7c630
commit
39f4805a98
14 changed files with 306 additions and 140 deletions
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from PySFML import *
|
||||
from PySFML import sf
|
||||
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLUT import *
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from PySFML import *
|
||||
from PySFML import sf
|
||||
|
||||
def Main():
|
||||
# Check that the device can capture audio
|
||||
|
|
67
python/samples/sound_capture_py3.py
Normal file
67
python/samples/sound_capture_py3.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from PySFML import sf
|
||||
|
||||
def Main():
|
||||
# Check that the device can capture audio
|
||||
if sf.SoundRecorder.CanCapture() == False:
|
||||
print("Sorry, audio capture is not supported by your system")
|
||||
return
|
||||
|
||||
# Choose the sample rate
|
||||
SampleRate = int(input("Please choose the sample rate for sound capture (44100 is CD quality) : "))
|
||||
|
||||
# Wait for user input...
|
||||
print("Press enter to start recording audio")
|
||||
input()
|
||||
|
||||
# Here we'll use an integrated custom recorder, which saves the captured data into a sfSoundBuffer
|
||||
Recorder = sf.SoundBufferRecorder()
|
||||
|
||||
# Audio capture is done in a separate thread, so we can block the main thread while it is capturing
|
||||
Recorder.Start(SampleRate)
|
||||
print("Recording... press enter to stop")
|
||||
input()
|
||||
Recorder.Stop()
|
||||
|
||||
# Get the buffer containing the captured data
|
||||
Buffer = Recorder.GetBuffer()
|
||||
|
||||
# Display captured sound informations
|
||||
print("Sound information :")
|
||||
print(" " + str(Buffer.GetDuration()) + " seconds")
|
||||
print(" " + str(Buffer.GetSampleRate()) + " samples / seconds")
|
||||
print(" " + str(Buffer.GetChannelsCount()) + " channels")
|
||||
|
||||
# Choose what to do with the recorded sound data
|
||||
Choice = str(input("What do you want to do with captured sound (p = play, s = save) ? "))
|
||||
|
||||
if Choice == 's':
|
||||
# Choose the filename
|
||||
Filename = str(input("Choose the file to create : "))
|
||||
|
||||
# Save the buffer
|
||||
Buffer.SaveToFile(Filename);
|
||||
else:
|
||||
# Create a sound instance and play it
|
||||
Sound = sf.Sound(Buffer)
|
||||
Sound.Play()
|
||||
|
||||
# Wait until finished
|
||||
while Sound.GetStatus() == sf.Sound.Playing:
|
||||
# Display the playing position - I don't know how to do this in python
|
||||
# std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";
|
||||
|
||||
# Leave some CPU time for other threads
|
||||
sf.Sleep(0.1)
|
||||
|
||||
# Finished !
|
||||
print("Done !")
|
||||
|
||||
# Wait until the user presses 'enter' key
|
||||
print("Press enter to exit...")
|
||||
input()
|
||||
|
||||
return
|
||||
|
||||
Main()
|
49
python/samples/sound_stream_py3.py
Executable file
49
python/samples/sound_stream_py3.py
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from PySFML import sf
|
||||
|
||||
class MyCustomStream(sf.SoundStream):
|
||||
|
||||
def Open(self, Filename):
|
||||
# Load the sound data into a sound buffer
|
||||
self.SoundData = sf.SoundBuffer()
|
||||
if not self.SoundData.LoadFromFile(Filename):
|
||||
return False
|
||||
# Initialize the stream with the sound parameters
|
||||
self.Initialize(self.SoundData.GetChannelsCount(), self.SoundData.GetSampleRate())
|
||||
# Copy the audio samples into our internal array
|
||||
self.myBuffer = self.SoundData.GetSamples()
|
||||
return True
|
||||
|
||||
def OnStart(self):
|
||||
self.myOffset = 0
|
||||
self.myBufferSize = 80000
|
||||
return True
|
||||
|
||||
def OnGetData(self):
|
||||
# Check if there is enough data to stream
|
||||
if self.myOffset > len(self.myBuffer):
|
||||
# Returning something else than a string means that we want to stop playing the stream
|
||||
return False
|
||||
# Data contains the string of samples we will return
|
||||
if self.myOffset + self.myBufferSize >= len(self.myBuffer):
|
||||
print("End of audio data reached")
|
||||
Data = self.myBuffer[self.myOffset:]
|
||||
else:
|
||||
Data = self.myBuffer[self.myOffset:self.myOffset+self.myBufferSize]
|
||||
# Update the offset
|
||||
self.myOffset = self.myBufferSize + self.myOffset
|
||||
return Data
|
||||
|
||||
def Main():
|
||||
Stream = MyCustomStream()
|
||||
Stream.Open("./data/fart.wav")
|
||||
Stream.Play()
|
||||
print("Playing 5 seconds of audio data...")
|
||||
sf.Sleep(5)
|
||||
Stream.Stop()
|
||||
print("Press enter to exit...")
|
||||
input()
|
||||
|
||||
Main()
|
||||
|
|
@ -44,7 +44,8 @@ class Apple(sf.Sprite):
|
|||
def __init__(self):
|
||||
apple_img = sf.Image() # Apple's image
|
||||
if not apple_img.LoadFromFile("./data/apple.png"):
|
||||
print "Could not load data/apple.png"
|
||||
pass
|
||||
# print "Could not load data/apple.png"
|
||||
sf.Sprite.__init__(self, apple_img)
|
||||
self.SetCenter(apple_img.GetWidth()/2, apple_img.GetHeight()/2)
|
||||
self.size = apple_img.GetWidth()
|
||||
|
@ -109,7 +110,8 @@ class Worm(list):
|
|||
self.rond = sf.Image()
|
||||
self.level_completed = False
|
||||
if not self.rond.LoadFromFile("./data/rond2.png"):
|
||||
print "Could not load data/rond2.png"
|
||||
pass
|
||||
# print "Could not load data/rond2.png"
|
||||
|
||||
def reset(self, arena):
|
||||
self.targeted_length, self.angle, self.direction = 30, 0, 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue