[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] BUG in make_sound()?
- To: "pygame-users@xxxxxxxx" <pygame-users@xxxxxxxx>
- Subject: [pygame] BUG in make_sound()?
- From: Brian Brown <brobab@xxxxxxxxx>
- Date: Thu, 7 May 2009 15:31:09 -0700
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 07 May 2009 18:31:11 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=8S3OsIIVhoSgVdu9/4MvyASOOt1aEq0jGVn0o6PIKKM=; b=MKhoZooz8IeRkhsINuo1Y1WG6uLaRAHG5x7d5eQKXYbmNntEIGVetR+ysFn5yPd/Hg sywN5hAs1xbZVG1TL0vkCAn6hPycbNn3V1QqnwYZwgIBBq0QSguQiCuGQ3Pau7TWQoS1 dPylrMZotkgzDhcb65WS5bDD1jI0hoywP7dr4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=bMQXtnCz/DDgdriadJ+6VS+dEawmrKK3UFVKo0Uqj5C6wdYbeglDn9zCYj+IyWsBkY 2AejOtEfbOjHUIsPxh1W0PKYRC96APvogJlF68Wy5y3zhVm/g7M94AzD2CR/jrgPccAC WCWSPYqPQVgJ5bZXRq2ndo/ISCaeeqPDv+jOE=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
###################################################################################################
# A Pygame BUG Report: (Bug found about May 2009)
#
# To Pygame People:
#
# (Best when viewed with a monospaced font.)
#
# I think I found a glitch/bug . . .
#
# pygame.sndarray.make_sound() sometimes returns a "channel"?
#
# Below is a program that can possibley re-do the glitch.
#
###################################################################################################
#
# requirements to run:
# (python 2.5 or higher)?
# and: (pygame 2.8.0 or pygame 2.8.1)?
# and: (numpy)?
#
###################################################################################################
#
# On my computer:
#
# The glitch was found with: (python 2.5.2 + pygame 2.8.0 + numpy
1.2.1) and: (python 2.6.2 + pygame 2.8.1 + numpy 1.3.0 ).
#
#
# after a while of running (About 2 to 10 minutes), this program
closes and give one of these errors?:
#
# This one: TypeError: argument 1 must be
pygame.mixer.Sound, not Channel <--(common)
#
# Or this one: Fatal Python error: (pygame parachute)
Segmentation Fault <--(rare)
# This application has requested the Runtime
to terminate in an unusual way.
# . . .
#
# (I did a google search to see if anybody else had discovered this glitch--
# But-- I didn't find any pages about it . . . )
#
###################################################################################################
# My computer stats:
#
# Windows Vista Home Premium
# Service Pack 1
# win32/32-bit Operating System
# Processor: Intel(R) Pentium(R) Dual CPU E2180 @ 2.00GHz 2.00 GHz
# RAM/memmory: 3.00 GB
#
###################################################################################################
#
# Here's the program:
#
def HE_HE_init():
global screen
global screen_x_size
global screen_y_size
global channel_max
if sys.platform == 'win32' or sys.platform == 'win64':
os.environ['SDL_VIDEO_CENTERED'] = '1'
# init the pygame.mixer according to the pygame version number:
versiony_numbery = pygame.version.vernum
numby = int(str(versiony_numbery[0]) + str(versiony_numbery[1]) +
str(versiony_numbery[2]))
if numby >= 181: pygame.mixer.init(44100, -16, 1)
else: pygame.mixer.init(22050, -16, 2)
pygame.init()
random.seed()
channel_max = 5
pygame.mixer.set_num_channels(channel_max)
screen_x_size = 640
screen_y_size = 480
screen = pygame.display.set_mode((screen_x_size, screen_y_size))
pygame.mouse.set_visible(1)
pygame.display.set_caption('BUG? --> pygame.sndarray.make_sound() <-- BUG?')
pygame.display.flip()
def Lets_ROLL():
previous_channel = None
# Some frequencies/Hz/Cycles-per-second: (ABCDEFGs)
noteyish = (440, 493.883, 261.626, 293.665, 329.628, 349.228, 391.995,
440*2.0, 493.883*2.0, 261.626*2.0, 293.665*2.0,
329.628*2.0, 349.228*2.0, 391.995*2.0,
440/2.0, 493.883/2.0, 261.626/2.0, 293.665/2.0,
329.628/2.0, 349.228/2.0, 391.995/2.0
)
t = time.time()
while True: # <-- Main loop
# Keep program from running/executing "too fast":
while t > time.time(): pass
t = time.time() + 0.10
screen.fill((0, 0, 0))
# Close the window/program if: [Esc is pressed] or: [The
X button is pressed]
key = pygame.key.get_pressed()
if key[K_ESCAPE]: END()
for event in pygame.event.get():
if event.type == QUIT: END()
##### generate/create and display/draw numpy_sound_data: #####
total_duration_in_seconds = .25
samples_per_second = 22050
total_amount_of_samples = total_duration_in_seconds *
samples_per_second
cicles_per_every_second = noteyish[int(random.random() * ((7 *
3) - 1) )] #440.0
numpy_sound_data = array([0] * int(total_amount_of_samples))
# setup some variables for drawing/displaying numpy_sound_data
x = 0
y = 200
x_dividey = 10
y_dividey = 1000
y_addy = 200
x2 = 0
y2 = 400
x2_dividey = 2
y2_addy_addy = 200
# yyygr should cause a "slight" "waver" in the
frequencies/Hz/Cycles-per-second
yyygr = 0.00001
yyygr_speed = 0.0
#yyygr_speed = (0.0005 / 2.0) - random.random() * 0.0005
specialy = len(numpy_sound_data) - 1
specialyy2 = specialy - 1000
specialyy3 = 0 + 300
if specialy > 2000: specialy -= 2000
for n in range(0, len(numpy_sound_data)):
if yyygr < 0:
yyygr_speed -= 0.0000005
elif yyygr > 0:
yyygr_speed += 0.0000005
yyygr += yyygr_speed
wavey_gurgy = ( float(n) * float(cicles_per_every_second +
yyygr) / float(samples_per_second) )
numpy_sound_data[n] = int( math.sin( wavey_gurgy *
radians(360) ) * 20000.0 )
# This "pinches" the ends of the "numpy_sound_data":
if n >= specialyy2:
numpy_sound_data[n] *= (1.0 - (n - specialyy2) / 1000.0)
if n <= specialyy3:
numpy_sound_data[n] *= (n / 300.0)
# Draw/plot two stretched versions of the "numpy_sound_data":
xa = x
ya = y
x = n / x_dividey
y = numpy_sound_data[n] / y_dividey + y_addy
xa2 = x2
ya2 = y2
x2 = n / x2_dividey
y2 = y + y2_addy_addy
pygame.draw.line(screen, (200, 200, 200), (x, y), (xa, ya))
pygame.draw.line(screen, (200, 200, 200), (x2, y2), (xa2, ya2))
pygame.display.flip()
###### convert "numpy_sound_data" to pygame.mixer.Sound and
play it: #######
sound_thing = pygame.sndarray.make_sound( numpy_sound_data )
# <-- This should always return a sound, right?
if previous_channel != None: previous_channel.fadeout(300) #
<-- Fade out previous sound. (if any)
print type(sound_thing) #
<-- Should print: <type 'pygame.mixer.Sound'>
previous_channel =
pygame.mixer.find_channel(True).play(sound_thing, 0) # <-- This line
is where the program "should" give an error.
def END():
print ''
print 'Program ended?'
print "###############################################################################"
print "###############################################################################"
print ''
pygame.quit()
raise SystemExit, ''
import os
import sys
import math
import random
import time
#import gc
#import copy as pythoncopy
#import string
#import struct
#from time import strftime, localtime
#import wave
print ""
print "###############################################################################"
print "###############################################################################"
print "Program started? "
print ""
print ""
print ""
print ""
print ""
try:
import pygame
from
pygame.locals import *
if not
pygame.font: print '?? "pygame.font" not "found" ??'
if not
pygame.mixer: print '?? "pygame.mixer" not "found" ??'
from
pygame import scrap
except: print
'"pygame" not "found"???'
try:
import
numpy; from numpy import *
except: print
'"numpy" not "found"??? (Oh well! Who cares!)'
#try:
# import
numarray; from numarray import *
#except: print
'"numarray" not "found"??? (Oh well! Who cares!)'
#try:
# import
Numeric; from Numeric import *
#except: print
'"numeric" not "found"??? (Oh well! Who cares!)'
HE_HE_init()
Lets_ROLL()
END()
# Thanks for your effort! I hope the bug will be fixed!