Changeset 552


Ignore:
Timestamp:
Apr 29, 2011, 1:15:09 AM (7 years ago)
Author:
Sam Hocevar
Message:

sdlport: use SDL_Mixer to read samples, and get rid of imlib's readwav.

Location:
abuse/trunk/src
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/Makefile.am

    r541 r552  
    1818    dprint.cpp dprint.h \
    1919    status.cpp status.h \
    20     readwav.cpp readwav.h \
    2120    pmenu.cpp pmenu.h \
    2221    scroller.cpp scroller.h \
  • abuse/trunk/src/sdlport/sound.cpp

    r551 r552  
    2828#include "sound.h"
    2929#include "hmi.h"
    30 #include "readwav.h"
    3130#include "specs.h"
    3231#include "setup.h"
     
    9291void sound_uninit()
    9392{
    94     if (sound_enabled)
    95     {
    96         Mix_CloseAudio();
    97     }
     93    if (!sound_enabled)
     94        return;
     95
     96    Mix_CloseAudio();
    9897}
    9998
     
    103102// Read in the requested .wav file.
    104103//
    105 sound_effect::sound_effect( char * filename )
    106 {
    107     if( sound_enabled )
    108     {
    109         int sample_speed;
    110 
    111         void* temp_data = (void *)read_wav( filename, sample_speed, size );
    112 
    113         SDL_AudioCVT audiocvt;
    114 
    115         SDL_BuildAudioCVT( &audiocvt, AUDIO_U8, 1, 11025, audioObtained.format, audioObtained.channels, audioObtained.freq );
    116         data = malloc( size * audiocvt.len_mult );
    117 
    118         memcpy( data, temp_data, size );
    119         audiocvt.buf = (Uint8*)data;
    120         audiocvt.len = size;
    121         SDL_ConvertAudio( &audiocvt );
    122         size = (Uint32)((double)size * audiocvt.len_ratio);
    123 
    124         free(temp_data);
    125 
    126         this->chunk = Mix_QuickLoad_RAW((Uint8*)data, size);
    127     }
     104sound_effect::sound_effect(char const *filename)
     105{
     106    if (!sound_enabled)
     107        return;
     108
     109    jFILE fp(filename, "rb");
     110    if (fp.open_failure())
     111        return;
     112
     113    void *temp_data = malloc(fp.file_size());
     114    fp.read(temp_data, fp.file_size());
     115    SDL_RWops *rw = SDL_RWFromMem(temp_data, fp.file_size());
     116    m_chunk = Mix_LoadWAV_RW(rw, 1);
     117    free(temp_data);
    128118}
    129119
     
    135125sound_effect::~sound_effect()
    136126{
    137     if( sound_enabled )
    138     {
    139         // Sound effect deletion only happens on level load, so there
    140         // is no problem in stopping everything. But the original playing
    141         // code handles the sound effects and the "playlist" differently.
    142         // Therefore with SDL_mixer, a sound that has not finished playing
    143         // on a level load will cut off in the middle. This is most noticable
    144         // for the button sound of the load savegame dialog.
    145         Mix_FadeOutGroup(-1, 100);
    146         while (Mix_Playing(-1))
    147             SDL_Delay(10);
    148         Mix_FreeChunk(this->chunk);
    149 
    150         if( data )
    151         {
    152             free( data );
    153         }
    154     }
     127    if(!sound_enabled)
     128        return;
     129
     130    // Sound effect deletion only happens on level load, so there
     131    // is no problem in stopping everything. But the original playing
     132    // code handles the sound effects and the "playlist" differently.
     133    // Therefore with SDL_mixer, a sound that has not finished playing
     134    // on a level load will cut off in the middle. This is most noticable
     135    // for the button sound of the load savegame dialog.
     136    Mix_FadeOutGroup(-1, 100);
     137    while (Mix_Playing(-1))
     138        SDL_Delay(10);
     139    Mix_FreeChunk(m_chunk);
    155140}
    156141
     
    164149//   255 - Completely to the left.
    165150//
    166 void sound_effect::play( int volume, int pitch, int panpot )
    167 {
    168     if (sound_enabled)
    169     {
    170         int channel = Mix_PlayChannel(-1, this->chunk, 0);
    171         if (channel > -1)
    172         {
    173             Mix_Volume(channel, volume);
    174             Mix_SetPanning(channel, panpot, 255 - panpot);
    175         }
     151void sound_effect::play(int volume, int pitch, int panpot)
     152{
     153    if (!sound_enabled)
     154        return;
     155
     156    int channel = Mix_PlayChannel(-1, m_chunk, 0);
     157    if (channel > -1)
     158    {
     159        Mix_Volume(channel, volume);
     160        Mix_SetPanning(channel, panpot, 255 - panpot);
    176161    }
    177162}
  • abuse/trunk/src/sdlport/sound.h

    r551 r552  
    2626{
    2727public:
    28     sound_effect(char *filename);
    29     void play(int volume = 127, int pitch = 128, int panpot = 128);
     28    sound_effect(char const *filename);
    3029    ~sound_effect();
    3130
     31    void play(int volume = 127, int pitch = 128, int panpot = 128);
     32
    3233private:
    33     void *data;
    34     Mix_Chunk* chunk;
    35     int size;
     34    Mix_Chunk* m_chunk;
    3635};
    3736
Note: See TracChangeset for help on using the changeset viewer.