engine/source/gamelib/soundmix.c
// Speed in percents of normal.
// Returns channel the sample is played on or -1 if not playing.
Speed in percents of normal.
Returns channel the sample is played on or -1 if not playing.
Speed in percents of normal . Returns channel the sample is played on or - 1 if not playing .
int sound_play_sample(int samplenum, unsigned int priority, int lvolume, int rvolume, unsigned int speed)
{
    int i;
    unsigned int prio_low;
    int channel;
    if(!mixing_inited)
    {
        return -1;
    }
    if(samplenum < 0 || samplenum >= sound_cached)
    {
        return -1;
    }
    if(speed < 1)
    {
        speed = 100;
    }
    if(!soundcache[samplenum].sample.sampleptr &&
            !sound_reload_sample(samplenum))
    {
        return -1;
    }
    channel = -1;
    for(i = 0; i < max_channels; i++)
    {
        if(!vchannel[i].active)
        {
            channel = i;
        }
    }
    if(channel == -1)
    {
        for(i = 0, prio_low = 0xFFFFFFFF; i < max_channels; i++)
        {
            if(vchannel[i].priority < prio_low)
            {
                channel = i;
                prio_low = vchannel[i].priority;
            }
        }
        if(prio_low > priority)
        {
            return -1;
        }
    }
    if(lvolume < 0)
    {
        lvolume = 0;
    }
    if(rvolume < 0)
    {
        rvolume = 0;
    }
    if(lvolume > MAXVOLUME)
    {
        lvolume = MAXVOLUME;
    }
    if(rvolume > MAXVOLUME)
    {
        rvolume = MAXVOLUME;
    }
    vchannel[channel].samplenum = samplenum;
    vchannel[channel].fp_samplepos = INT_TO_FIX((channel * 4) % soundcache[samplenum].sample.soundlen);
    vchannel[channel].fp_period = (INT_TO_FIX(1) * speed / 100) * soundcache[samplenum].sample.frequency / playfrequency;
    vchannel[channel].volume[0] = lvolume;
    vchannel[channel].volume[1] = rvolume;
    vchannel[channel].priority = priority;
    vchannel[channel].channels = soundcache[samplenum].sample.channels;
    vchannel[channel].active = CHANNEL_PLAYING;
    vchannel[channel].paused = 0;
    vchannel[channel].playid = ++sample_play_id;
    return channel;
}
int sound_play_sample ( int samplenum , unsigned int priority , int lvolume , int rvolume , unsigned int speed ) { int i ; unsigned int prio_low ; int channel ; if ( ! mixing_inited ) { return -1 ; } if ( samplenum < 0 || samplenum >= sound_cached ) { return -1 ; } if ( speed < 1 ) { speed = 100 ; } if ( ! soundcache [ samplenum ] . sample . sampleptr && ! sound_reload_sample ( samplenum ) ) { return -1 ; } channel = -1 ; for ( i = 0 ; i < max_channels ; i ++ ) { if ( ! vchannel [ i ] . active ) { channel = i ; } } if ( channel == -1 ) { for ( i = 0 , prio_low = 0xFFFFFFFF ; i < max_channels ; i ++ ) { if ( vchannel [ i ] . priority < prio_low ) { channel = i ; prio_low = vchannel [ i ] . priority ; } } if ( prio_low > priority ) { return -1 ; } } if ( lvolume < 0 ) { lvolume = 0 ; } if ( rvolume < 0 ) { rvolume = 0 ; } if ( lvolume > MAXVOLUME ) { lvolume = MAXVOLUME ; } if ( rvolume > MAXVOLUME ) { rvolume = MAXVOLUME ; } vchannel [ channel ] . samplenum = samplenum ; vchannel [ channel ] . fp_samplepos = INT_TO_FIX ( ( channel * 4 ) % soundcache [ samplenum ] . sample . soundlen ) ; vchannel [ channel ] . fp_period = ( INT_TO_FIX ( 1 ) * speed / 100 ) * soundcache [ samplenum ] . sample . frequency / playfrequency ; vchannel [ channel ] . volume [ 0 ] = lvolume ; vchannel [ channel ] . volume [ 1 ] = rvolume ; vchannel [ channel ] . priority = priority ; vchannel [ channel ] . channels = soundcache [ samplenum ] . sample . channels ; vchannel [ channel ] . active = CHANNEL_PLAYING ; vchannel [ channel ] . paused = 0 ; vchannel [ channel ] . playid = ++ sample_play_id ; return channel ; }
Speed in percents of normal.
Speed in percents of normal .
// Try to find unused SFX channel // Find SFX channel with lowest current priority // Prevent samples from being played at EXACT same point