+ Reply to Thread
Results 1 to 7 of 7

Thread: SDL_mixer initialization failure on Win7

  1. #1

    Question SDL_mixer initialization failure on Win7

    I've had reports from several people that my latest game, Dirk Dashing 2, doesn't have audio on Windows 7 with various onboard chipsets. From the log file, it appears the call to Mix_OpenAudio fails. Has anyone else seen this problem with SDL_mixer?

    Here's my code:

    Code:
       std_error_type err = SUCCESS;
    
       if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) != 0)
       {
          // Failed to initialize SDL_mixer library at CD quality (44.1 KHz)
          // Trying the more standard 22050 Hz instead...
    
          if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) != 0)
          {
             DEBUG("Failed to initialize SDL_mixer library");
    
             err = FAILED;
          }
       }
    Are there different parameters I should use that would work better for low end audio chipsets?

  2. #2
    Senior Member
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    258

    Default

    First thought: Most current CODECs are hardwired at 48 kHz; not 44.1 - but doesn't Windows resample automatically? (Not entirely sure about that, as SDL will normally try to use a "raw" shared memory based I/O setup where possible, and that typically means the sound chip is DMAing data directly from the buffer.)

    Doesn't SDL_mixer set a proper error message that you can print out?
    David Olofson - Free/Open Source developer and aspiring indie game developer
    Olofson Arcade
    http://olofson.net

  3. #3
    Senior Member
    Join Date
    May 2005
    Location
    Warsaw, Poland
    Posts
    2,707

    Default

    Use Mix_GetError to find the error reason and check for < 0 instead of != 0.

    Also you shouldn't need to do the second check since SDL_mixer is supposed to do the conversion for you if the requested format is not supported.

  4. #4

    Default

    Doing < 0 instead of != 0 is a good catch. Still didn't fix the problem, though. It still failed to initialize.

    I did finally get it to work. I basically added one more attempt, using a low sample rate and mono instead of stereo:

    Code:
       std_error_type err = SUCCESS;
    
       if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) != 0)
       {
          // Failed to initialize SDL_mixer library at CD quality (44.1 KHz)
          // Trying the more standard 22050 Hz instead...
    
          if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024) != 0)
          {
             // Try cheapest quality
    
             if (Mix_OpenAudio(11025, MIX_DEFAULT_FORMAT, 1, 1024) != 0)
             {
                err = FAILED;
             }
          }
       }
    It was the mono vs stereo that got it working. Apparently some cheaper audio chipsets can't handle stereo output. Changing the channels from 2 to 1 got it working.

  5. #5
    Senior Member
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    258

    Default

    Seriously...!? I thought only ancient cell phones had mono sound these days... o.O
    David Olofson - Free/Open Source developer and aspiring indie game developer
    Olofson Arcade
    http://olofson.net

  6. #6
    Senior Member
    Join Date
    May 2005
    Location
    Warsaw, Poland
    Posts
    2,707

    Default

    Yeah, looking at SDL_mixer's code it seems that they ask SDL for the "real" settings, which makes SDL to not do the conversion itself if the settings were not found. In theory you could modify SDL_mixer's Mix_OpenAudio function (in mixer.c) to pass a NULL in the "obtained" parameter (which says to SDL to do whatever is possible to get *that* format, even if conversion has to take place) and fill the "obtained" structure with the values of the "requested" structure (so the rest of the library won't freak out).

    Of course i haven't tried that and since you found a workaround, this doesn't matter really :-)

  7. #7

    Default

    Quote Originally Posted by Olofson View Post
    Seriously...!? I thought only ancient cell phones had mono sound these days... o.O
    I was surprised too! Who would have thought a modern PC running Windows 7 would have MONO sound! #EpicFail

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts