=== Subject: Re: [pygame] write sound to file for fast loading? you may or may not get better results with the process you describe - the resulting sound file will most likely be much much larger (like orders of magnitude larger) which increases the time it takes to load it from disk, so if disk is the bottleneck (as opposed to cpu decoding), the trick would make things slower. Also, the problem you are experiencing is precisely what pygame.mixer.music is for - it uses SDL's underlying feature for streaming a song from disk, so the loading time is amortized over the game play time: http://www.pygame.org/docs/ref/music.html So what kind of sound file are you loading? mp3? ogg? wav? can you share one of the problem files? What does your sound loading code look like? Are you loading by filename or file-like object? ... and to the poster who mentioned pyglet - why do you think it would help? pyglet and pygame are very similar in music loading. Both pygame and pyglet offer streaming music options that only help if you use them, and unless you distribute avbin with your game, pyglet loads sounds with pure python code, while pygame always uses mature decoding libraries. > I have a problem I've been studying a while and I can't figure out a > solution. Pygame or SDL--not sure which--is pretty slow at loading sounds. > For large sounds, like songs, this means significant pauses in your game; or > very long loading times at startup if you have a few of them to load. > > I tried using a thread to load a song, but as expected that only resulted > in a very laggy game for the duration. > > So I was thinking it might be faster to pre-process a song: load it via the > mixer, write the buffer to a data file, then later load it into an array and > feed the array to the mixer. I can see that part of that idea is implemented > in _sndarray.py, but I didn't really want to require numpy and I couldn't > see how to convert that module's code to my purpose anyhow. > > I'm strikin' out. Is this even feasible, or is it a hair-brained scheme > doomed to failure? Has anyone solved this problem, and would s/he be willing > to share? :) > Subject: Re: [pygame] write sound to file for fast loading? Tried pygame music? http://www.pygame.org/docs/ref/music.html Subject: Re: [pygame] write sound to file for fast loading? Well I just asumed music was being streamed from disc in pygame.music: import pygame pygame.init() pygame.music.load('some_file.ogg') pygame.music.play() I have never used pygame.music with .ogg files larger than 5 mb, so I cannot say whether my assumption is valid or not. Subject: Re: [pygame] write sound to file for fast loading? These are .ogg loading from disk using pygame.mixer.Sound('filename.ogg'), the largest of which is 7 MB. I can't believe I overlooked pygame.mixer.music. Pardon me while I flog myself. This does exactly what I want. Thanks, Brian and Olof, for suggesting it! Works like a charm. Subject: Re: [pygame] write sound to file for fast loading? Of course the big downside to mixer.music, is that you can only have one file loaded at once. This is bad if you want to mix :) Then you have to use sounds, and suffer the loading issues. === Subject: Re: [pygame] pygame.mixer.init(frequency=?) On Thu, Feb 25, 2010 at 10:37:36AM -0800, James Paige wrote: > On Thu, Feb 25, 2010 at 10:31:12AM -0800, B W wrote: > > I have two songs. One has a bitrate of 48000, the other 44100. If I = allow > > Pygame (SDL mixer) to use the default frequency, the playback speed = of the > > songs is distorted. If I explicitly set the mixer frequency to match= a > > song so it sounds good, the other sounds distorted. > >=20 > > Reinitializing the mixer is not a good option. There are other sound= s that > > need to play, and would be interrupted by a reinit. Resampling the s= ongs > > is not ideal, either, as Vorbis is a lossy format and sound quality = is > > obviously lost in re-sampling. Is that a theoretical observation, or can you actually hear the difference? > > Does anyone have a recommendation? Are all sounds in an implementati= on > > expected to have the same bitrate? >=20 > Even if SDL_mixer was capable of handling this situation, it would still= =20 > have to handle it by resampling. Unless I am greatly mistaken, there is= =20 > no way to avoid resambling in this situation, so it will be better to=20 > resample in advance, rather than to expect the library to do it at=20 > runtime. If SDL resampled the sound on load, you'd end up with: decode vorbis -> resample (mostly lossless) -> play. If you resample it in advance, you end up with decode vorbis -> resample (mostly lossless) -> reencode vorbis (lossy!) =3D> decode vorbis -> play It's not the resampling that B W is trying to avoid, it's the lossy reencoding. === Subject: [pygame] play sound delay My function is press keyboard then in the event "KEYDOWN" play the sound (*.midi *.wav ...) I need the sound play immediately but it seems always has about 1 second delay how to solve these? my code like these: pickUpSound = pygame.mixer.Sound('/home/yu/work/symphony/pickup.wav') #pygame.mixer.music.load('/home/yu/work/symphony/background.mid') #pygame.mixer.music.play(-1, 0.0) # run the game loop while True: # check for the QUIT event for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: # change the keyboard variables if event.key == K_LEFT or event.key == ord('a'): pickUpSound.play() Subject: Re: [pygame] play sound delay Add the following line: pygame.mixer.pre_init(frequency=22050, size=-16, channels=8, buffer=256) Immediately after these lines at the beginning of your file: import pygame from pygame.locals import * And before: pygame.init() So: import pygame from pygame.locals import * pygame.mixer.pre_init(frequency=22050, size=-16, channels=8, buffer=256) pygame.init() #Rest of your code Subject: Re: [pygame] play sound delay Also, it's a good idea to design the main loop to share time with other processes. I recommend that you put pygame.time.wait(5) in the loop. You won't be able to notice the delay, but your processor usage will decrease. Subject: Re: [pygame] play sound delay now I know the key is the size of buffer, The smaller, the less latency it will ... I'm new to the coding of sound ... :( > Add the following line: > pygame.mixer.pre_init(frequency=22050, size=-16, channels=8, buffer=256) === Subject: Re: [pygame] Info on writing pygame game for iPodTouch / iPhone? Cydia is for jail broken iphones. You can't use python in the app store until someone makes a static version that compiles into the app. which should theoretically be possible since there are static ruby and .net apps in the app store... but afaik there have been no python ones. Otherwise you need objective-c, at least for the the interfacing with the iphone libraries, but the compiler can link and compile c++ after the intial glue/setup code. > There's PyObj-C in Cydia > > > Phil, I know you've made a couple ports to the iPhone. > > How much work / how hard it is to write an iphone app? > > > > Do I have to use c++, or can it be completely in python / tinypy? [ I > have > > experience in c++, but it's a been a while. ) > > === Subject: Re: [pygame] pygame music Pygame uses the SDL_mixer library for music playback. So it all depends on how SDL_mixer was built and which other libraries are present. The possible formats are listed in the SDL_mixer documentation here: http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_frame.html > What are the supported file formats for the music module? > > How big a deal would it be to add seek support or at least rewind( > milliseconds ) instead of rewind() which returns to the start? > > Right now I'm stuck working with wxPython's media module that uses > windows media player on windows.. ugh. > === Subject: [pygame] ANNOUNCE: pygame 1.9.1 released. *_______** _ _ _____ _ ___ _ _____ || \ \\ / / \ //\ ||\ /| /| \ || | \\ / || // \ || \ / | || |------/ \\_/ || == //____\ || \/ | ||====| **|**| || || || // \ || | || **|**| || \____/ // \ || | \=====/ *. *o* *1.9.1* *r* *g* (note, 1.9.1 release was made because setuptools based installs were failing with the 1.9.0 tarball that was released a couple of days ago) What's new (heaps of things since 1.8.1): http://www.pygame.org/whatsnew.shtml Summary of changes: - many, many fixes and improvements. The largest amount of changes has gone into this release than any other pygame release. - bug fixes for backwards compatibility issues introduced in pygame 1.8.x series. old games like solarwolf and libraries like PGU work again. - experimental *camera* webcam module (still in development). - experimental midi module based on portmidi and pyportmidi (99% complete). - experimental gfxdraw module based on SDL_gfx (including AA circles, textured polygons and other goodness). - python3, and python3.1 support mostly completed. Some modules still remain to be completed - but mostly it's working. - nokia mobile phone s60 support. - improved OSX support (dropped pyobjc dependency, improved installer, sysfont now works on OSX). - pygame.examples + pygame.tests included with pygame. This makes testing easier, and also makes learning pygame more fun and easy. - cleanup of examples, and addition of new examples. - new tools to aid in development of pygame itself, better compilation documentation. - py2app, and py2exe support improved. Source code release (binaries at bottom of announcement): http://pygame.org/ftp/pygame-1.9.1release.tar.gz (2.2MB) http://pygame.org/ftp/pygame-1.9.1release.zip (2.0MB) Compilation instructions for different platforms: http://www.pygame.org/wiki/Compilation See a list of examples... python -c "import pygame.examples;help(pygame.examples)" Run one of the 30 examples included... python -m pygame.examples.aliens You can do a self test of pygame with: python -m pygame.tests (or on python2.6 do python -m pygame.tests.__main__ ) The latest docs are bundled with pygame. To open them in your web browser run: python -m pygame.docs Binary builds for win/mac from the "The Spectacularly Adequate Automated Pygame Build Page". OSX 10.4/10.5/10.6 universal(intel and ppc): http://pygame.org/ftp/pygame-1.9.1release-py2.6-macosx10.5.zip 10.3MB http://pygame.org/ftp/pygame-1.9.1release-py2.5-macosx10.5.zip 10.3MB http://pygame.org/ftp/pygame-1.9.1release-py2.4-macosx10.5.zip 10.3MB Windows: http://pygame.org/ftp/pygame-1.9.1release.win32-py2.4.exe 3MB http://pygame.org/ftp/pygame-1.9.1release.win32-py2.5.exe 3MB http://pygame.org/ftp/pygame-1.9.1.win32-py2.5.msi 3MB http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi 3MB http://pygame.org/ftp/pygame-1.9.1.win32-py3.1.msi 3MB 1c4cdc708d17c8250a2d78ef997222fc pygame-1.9.1release.tar.gz 01824b893d1d910fa3fa8bb37740f580 pygame-1.9.1release.zip 827f2d4c17db3921ad84319bca141a6b pygame-1.9.1release-py2.4-macosx10.5.zip f12f1ede9f8bb6e85e655ee0ba02fa98 pygame-1.9.1release-py2.5-macosx10.5.zip e479130494caf6ebf4d9d7f547995fc3 pygame-1.9.1release-py2.6-macosx10.5.zip 8f5a0358e5dc56a8582cd2a7e6d6ad4f pygame-1.9.1release.win32-py2.4.exe 0a39cdcc9e2d002d34b264635598b22f pygame-1.9.1release.win32-py2.5.exe 1d2c33f8560c77f0a15d78c54334d536 pygame-1.9.1.win32-py2.5.msi 9ddf40c1ef6ab7fbdc0fb2395d2a66b9 pygame-1.9.1.win32-py2.6.msi b6ce5c559549d27a3b3fb40577b6234c pygame-1.9.1.win32-py3.1.msi ===