Changeset 536


Ignore:
Timestamp:
Apr 23, 2011, 12:48:41 AM (7 years ago)
Author:
Sam Hocevar
Message:

sdlport: add some error reporting to the new SDL_Mixer features.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/sdlport/sound.cpp

    r534 r536  
    6969};
    7070
     71#ifndef USE_SDL_MIXER
    7172static effect_handle * fx_list = NULL;
     73#endif
    7274extern flags_struct flags;
    7375static int sound_enabled = 0;
     
    121123int sound_init( int argc, char **argv )
    122124{
    123     SDL_AudioSpec audioWanted;
    124125    char *sfxdir, *datadir;
    125126    FILE *fd = NULL;
     
    129130    {
    130131        // User requested that sound be disabled
    131         printf( "Sound : Disabled (-nosound)\n" );
     132        printf( "Sound: Disabled (-nosound)\n" );
    132133        return 0;
    133134    }
     
    140141    {
    141142        // Didn't find the directory, so disable sound.
    142         printf( "Sound : Disabled (couldn't find the sfx directory)\n" );
     143        printf( "Sound: Disabled (couldn't find the sfx directory)\n" );
    143144        return 0;
    144145    }
     
    148149    if (Mix_OpenAudio(11025, AUDIO_U8, 2, 128) < 0)
    149150    {
    150         printf( "Sound : Unable to open audio - %s\nSound : Disabled (error)\n", SDL_GetError() );
     151        printf( "Sound: Unable to open audio - %s\nSound: Disabled (error)\n", SDL_GetError() );
    151152        return 0;
    152153    }
     
    159160
    160161    sound_enabled = SFX_INITIALIZED | MUSIC_INITIALIZED;
    161 #else
     162
     163    printf( "Music: Enabled\n" );
     164#else
     165    SDL_AudioSpec audioWanted;
    162166    audioWanted.freq = 11025;
    163167    audioWanted.format = AUDIO_U8;
     
    170174    if( SDL_OpenAudio( &audioWanted, &audioObtained ) < 0 )
    171175    {
    172         printf( "Sound : Unable to open audio - %s\nSound : Disabled (error)\n", SDL_GetError() );
     176        printf( "Sound: Unable to open audio - %s\nSound: Disabled (error)\n", SDL_GetError() );
    173177        return 0;
    174178    }
     
    179183#endif
    180184
    181     printf( "Sound : Enabled\n" );
     185    printf( "Sound: Enabled\n" );
    182186
    183187    // It's all good
     
    299303        if( fx_list == NULL )
    300304        {
    301             printf( "Sound : ERROR - Failed to create new effect.\n" );
     305            printf( "Sound: ERROR - Failed to create new effect.\n" );
    302306            SDL_UnlockAudio();
    303307            return;
     
    361365// Play music using SDL_Mixer
    362366
    363 song::song( char const * filename )
     367song::song(char const * filename)
    364368{
    365369    data = NULL;
     
    378382    data = load_hmi(realname, data_size);
    379383
    380     if (data)
    381     {
    382         rw = SDL_RWFromMem(data, data_size);
    383         music = Mix_LoadMUS_RW(rw);
     384    if (!data)
     385    {
     386        printf("Music: ERROR - could not load %s\n", realname);
     387        return;
     388    }
     389
     390    rw = SDL_RWFromMem(data, data_size);
     391    music = Mix_LoadMUS_RW(rw);
     392
     393    if (!music)
     394    {
     395        printf("Music: ERROR - %s while loading %s\n",
     396               Mix_GetError(), realname);
     397        return;
    384398    }
    385399#endif
     
    388402song::~song()
    389403{
    390     if( playing() )
    391     {
     404    if(playing())
    392405        stop();
    393     }
    394     if( data )
    395     {
    396         free( data );
    397     }
    398     free( Name );
    399 
    400 #ifdef USE_SDL_MIXER
    401     Mix_FreeMusic(this->music);
    402     SDL_FreeRW(this->rw);
     406    free(data);
     407    free(Name);
     408
     409#ifdef USE_SDL_MIXER
     410    Mix_FreeMusic(music);
     411    SDL_FreeRW(rw);
    403412#endif
    404413}
Note: See TracChangeset for help on using the changeset viewer.