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

Re: [pygame] Pygame Mixer Crackle noise not an SDL_Mixer problem



Hi Rene,
I did have it working with the Sushi plate from chapter 2 as background and the ball from chapter 10 bouncing around with the code I have listed below. It was working without the crackling noises, just like it did when there was no graphics. I could have many bounce sounds going and the music playing, while the ball moved around the screen and the sushi plate filled the background. No crackling.

I got carried away and tried to clean up the animation and caused a bug somewhere that I am having difficulty trying to track down. It is 2:00 am here in Arizona. So I am going to bed now. I will fix my code bug in the morning and post my code to the mailing list. I hope you'll be around to look at it.
Thanks for your help so far.
Ethan


----- Original Message ----- From: "René Dudfield" <renesd@xxxxxxxxx>
To: <pygame-users@xxxxxxxx>
Sent: Friday, April 18, 2008 12:23 AM
Subject: Re: [pygame] Pygame Mixer Crackle noise not an SDL_Mixer problem


hi,

I think from our testing that it's the combination of using video with
the sound.

Are you able to play any of the SDL test programs with video and sound
to see if there is crackling?


cheers,



On Fri, Apr 18, 2008 at 5:20 PM, etrek <etrek@xxxxxxx> wrote:
Hi,
I didn't use any graphics in my SDL program. Just the SDL_Mixer. Here is a short example of SDL program that plays the files without noise/crackles.
This was compiled with DEV-C++ and MinGW.
 #include <stdlib.h>
 #include <SDL.h>
 #include <SDL_Mixer.h>

 Mix_Chunk* bounce = NULL;  // bounce.wav from Book chapter 10
Mix_Chunk* msg = NULL; // Please put some .ogg files in the folder.ogg Book
chapter 10
 Mix_Music *music = NULL;  // getout.ogg   example from the IrrKlang music
library

 SDL_Surface* createScreen()
 { SDL_Surface *screen;

   screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
   if ( screen == NULL ) {
fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
       exit(1);
   }
   return screen;

 }

 void quit() {
   Mix_FreeChunk(bounce) ;
   Mix_FreeChunk(msg);
   Mix_FreeMusic(music);
   Mix_CloseAudio();
   SDL_Quit();
 }

 int main(int argc, char *argv[])
 {
   if ( SDL_Init(SDL_INIT_EVERYTHING) < 0 ) {
       fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
       exit(1);
   }

   SDL_Surface* screen = createScreen();
   SDL_WM_SetCaption( "Hello World", NULL );
       //Update the screen
   if( SDL_Flip( screen ) == -1 )  { return 1; }

   // initialize SDL mixer
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) //tried
these values in Pygame
   {
       return false;
   }
   Mix_AllocateChannels(8);

   bounce = Mix_LoadWAV( "bounce.wav" );
   msg = Mix_LoadWAV("please.ogg");
   music = Mix_LoadMUS( "getout.ogg" );
       //If there was a problem loading the sound effects
   if( bounce == NULL ) { return false;  }

   SDL_Event event;
   while(true) {
       while(SDL_PollEvent(&event)) {
           if(event.type == SDL_QUIT) {
               quit();
           }
           if(event.type == SDL_KEYDOWN) {
               if(event.key.keysym.sym == SDLK_1) {
                   if(Mix_PlayChannel(-1, bounce, 0) < 0) {
                       quit();
                   }
               }
               else if(event.key.keysym.sym == SDLK_2) {
                    if(Mix_PlayChannel(-1, msg, 0) < 0) {
                        quit();
                    }
               }
               else if(event.key.keysym.sym == SDLK_3) {
                       if( Mix_PlayMusic( music, -1 ) < 0 ) {
                           quit();
                       }
               }
           }
       }
   }
   return 0;
 }



 ----- Original Message ----- From: "René Dudfield" <renesd@xxxxxxxxx>
 To: <pygame-users@xxxxxxxx>
 Sent: Thursday, April 17, 2008 11:15 PM
 Subject: Re: [pygame] Pygame Mixer Crackle noise not an SDL_Mixer problem





> hi,
>
> did your rewritten scripts use video?  Or just sound?
>
> Do you have a url for your scripts somewhere?
>
>
> cheers,
>
>
>
> On Fri, Apr 18, 2008 at 4:03 PM, etrek <etrek@xxxxxxx> wrote:
>
> >
> >
> > Hello Pygame developers:  Please read entire message before assuming
you've
> > heard this before:)
> >
> > I am a new user of Pygame.  I have the book "Beginning Game Dev with
Python
> > and Pygame". So far I am very impressed with Pygame;  It has excellent
> > graphics response and input capabilities.  The sound Mixer library has
> > problems though.
> >
> > When I tried the examples in Chapter 10 "Making Things Go Boom",  I
noticed
> > a "Crackling" noise when playing sound effects (short wav files) and
music
> > (long Ogg files).
> >
> > I have searched the archives at Seul.org  and searched on Google for
fixes
> > to this problem.  The solutions suggested basically amount to changing
> > arguments passed into:  pygame.mixer.pre_init(...)
> > I tried many different settings:
> > pygame.mixer.pre_init(44100, -16, 2, 4096)
> > pygame.mixer.pre_init(22050, -16, 2, 4096)
> > pygame.mixer.pre_init(22050, 16, 2, 1024 * some_number)
> > Too many to keep listing.
> > I also tried leaving the settings at default, which actually produces
the
> > least amount to crackling.
> >
> > I played the music/sound files with Windows Media Player to rule out > > my
> > system or bad files.  There was no crackling there.
> >
> > On some of the Google searches, I saw that people were pointing to the
> > problem being in the actual SDL_Mixer.
> >
> >
> > So I downloaded SDL/SDL_Mixer extension and re-wrote the example > > scripts
in
> > SDL/C++, using the same music/sound files.
> > To my surprise, there was NO Crackling noise.
> >
> >
> > So,  the problem is NOT my system, it's not the arguments I'm passing
into
> > pygame.mixer, and it's not SDL_Mixer.
> > The problem has to be somewhere in the Pygame Sound/Music libraries.
> >
> > I even tried swapping out the SDL_Mixer libs that came with Pygame for
the
> > ones that came with SDL_Mixer, and still got the crackling in Pygame.
> >
> > It would be nice if this could be fixed.  Because the crackling is
> > essentially making the library unuseable.  Which would be a shame,
because
> > Pygame is a terrific library/tool.
> >
> > Thanks,
> > Ethan D.
> > Systems Programmer, SR.
> > Planetary Lab, Univ Arizona
> >
> > My System:
> > Windows Vista 32bit home premium
> > IP35-Pro mobo, integrated sound, latest drivers
> > 4 Gig RAM
> > Intel Quad core
> >
> >
>