[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Problem loading 48 sounds?



Hello Gilga,

 

I tried out your code and I was able to get 60 FPS on my dual-core 3GHz machine with a very basic Radeon graphics card. But Iâm running Kubuntu Linux 15.04 with OpenGL 3.0 / Mesa 10.5.2. I didnât experience any crash either, although Iâm not a piano player so I didnât do a lot with it.

 

By the way, I had to modify your code to get it to run. Iâm wondering if you havenât checked in your latest code?

 

Anyway, I had to add

 

# -*- coding: utf-8 -*-

 

as the 2nd line because the Python 2 parser wouldnât start without it. Yes, Iâm using Python 2, and on Linux. Are you using Windows?

 

In your Key.update() function, I had to change the directory name to pythonpiano_pictures instead of pictures.

 

I also commented out

 

self.background = "">

 

because I donât see how itâs necessary to change the format of the screen buffer to what it already has. I think that function is more for sprite images that you load in and that you want to have as the same format as the screen buffer.

 

I just looked at your update function for the Key class. That needs attention. And now I can see why it is causing your frame rate to be artificially lower that it needs to be; it could be causing your crashes; and is something that no one tells you but you find out the hard way.

 

In your update function, you need it to be as fast as possible. I see that youâre *loading* the appropriate key image from disk every time it needs to *draw* the image. Not good. Very slow. Think fast.

 

Instead, preload all game assets--images and sound--before the main update loop begins.

 

Good luck and let us know how it goes!

 

~ Michael

 


On Wed : Jul 29, 2015 4:36:00 AM you wrote:

> Hi!

> I've created a simple 2D graphic program to play the piano thanks to a computer keyboard: see https://github.com/gustavklopp/pypiano

> (you can clone it, it's only 2 files and the sound ressource)

>

> Even if setting the FPS to 40, I can't even get that with my not so weak laptop (AMD A4-5000 1.5 GHz, AMD Radeon HD 8330, RAM 4096MB), and I'm stuck to just 30FPS. Sometimes, if I play a little longer than a few minutes, the program even crash (no more sound and I can't exit without Ctrl+Alt+Sup).

> For a music program, at 30FPS, you can detect the delay between the typing and the playing of the sound...

>

> I think the problem is with loading my 48 OGG sounds (48-key keyboard) at the beginning: I'm using:

> `pygame.mixer.pre_init(44100, -16, 2, 4096)`

>

> Is there some solutions to have this program not crashing when trying to play the sounds and improve the FPS?

> Maybe if you try it on your computer, the FPS are better and it's a problem with my OpenGL and Radeon Driver (known to be quite touchy)?

>

> Thanks a lot for your help!

>

>

>