Example #1
0
int audio_close(snd_type snd)
{
    int i;
    MMRESULT er;
    buffer_state *bs = (buffer_state *) snd->u.audio.descriptor;
    if (snd->write_flag == SND_READ) {
        if (er = waveInReset(bs->u.h_in)) {
            mm_error_handler(snd, er, snd_fail);
            return !SND_SUCCESS;
        }
        if (er = waveInClose(bs->u.h_in)) {
            mm_error_handler(snd, er, snd_fail);
            return !SND_SUCCESS;
        }
    } else { // SND_WRITE
        if (er = waveOutReset(bs->u.h_out)) {
            mm_error_handler(snd, er, snd_fail);
            return !SND_SUCCESS;
        }
        if (er = waveOutClose(bs->u.h_out)) {
            mm_error_handler(snd, er, snd_fail);
            return !SND_SUCCESS;
        }
    }
    for (i = 0; i < bs->numofbuffers; i++) {
        snd_free(bs->whdr[i].lpData);
    }
    snd_free(bs->whdr);
    snd_free(bs);
    if (rt_devices_open) {
        timeEndPeriod(1);
        rt_devices_open--;
    }
    return SND_SUCCESS;
}
Example #2
0
void *audio_descr_build(snd_type snd)
{    
    int i, j;
    buffer_state *bufstate;
    double bufsize_in_frames;

    bufstate = (buffer_state *) snd_alloc(sizeof(buffer_state));

    if (snd->u.audio.protocol == SND_REALTIME){
        bufstate->numofbuffers = 3;        
    }
    else { 
        if (snd->u.audio.protocol != SND_COMPUTEAHEAD)
            snd_fail("Invalid protocol identifier. COMPUTEAHEAD method used instead");
        bufstate->numofbuffers = 2;    
    }
    

    if (NULL == (bufstate->whdr = 
                (LPWAVEHDR)snd_alloc(bufstate->numofbuffers * sizeof(WAVEHDR)))){
        snd_fail("Not enough memory, or similar");
        snd_free(bufstate);
        return NULL;
    }
    bufsize_in_frames = max(Audio_out_min_buffersize, 
                            snd->format.srate * snd->u.audio.latency);
    if (bufsize_in_frames > snd->format.srate * snd->u.audio.latency)
        snd->u.audio.latency = bufsize_in_frames / snd->format.srate;
    for (i=0; i<bufstate->numofbuffers; i++){
        bufstate->whdr[i].dwBufferLength = (long)(bufsize_in_frames + 0.5) * snd_bytes_per_frame(snd); 
        if (NULL == (bufstate->whdr[i].lpData = (char *) snd_alloc(bufstate->whdr[i].dwBufferLength))){
            snd_fail("Not enough memory, or similar");
            for (j=0; j<i-1; j++){
                snd_free(bufstate->whdr[j].lpData);
            }
            snd_free(bufstate);
            return NULL;
        }
        bufstate->whdr[i].dwUser = bufstate->whdr[i].dwLoops = 0;    //idrk, what's that
        bufstate->whdr[i].dwFlags = WHDR_DONE;
    }

    bufstate->pollee = 0;
    bufstate->posinbuffer = 0;

    if (snd->u.audio.protocol == SND_REALTIME){
        bufstate->sync_buffer = 0;
        bufstate->prev_time = timeGetTime();
        bufstate->sync_time = bufstate->prev_time - (long)(2 * 1000 * snd->u.audio.latency + .5);
    }


    return (void *) bufstate;
}
Example #3
0
/* check which player won and free all unnneded data */
void
game_end ()
{
    int i;
    int cnt_left = 0;

    gfx_free_players ();
    tileset_free ();
	fire_clear ();
    snd_music_stop ();
    snd_free ();

    /* count the wins for the player, and if only one player
     * left count the points too */
    cnt_left = 0;
    for (i = 0; i < MAX_PLAYERS; i++) {
        // Update player statistics
        players[i].gamestats.killed += players[i].nbrKilled;
        if (PS_IS_used (players[i].state)) {
            if (PS_IS_alife (players[i].state)) {
                bman.lastwinner = i;
                cnt_left++;
                if ( GT_MP_PTPM )
                    players[i].wins++;
            }
        }
    }

    if (cnt_left == 1 && GT_MP_PTPM ) {
        players[bman.lastwinner].points += 1; // Bonus for victory
        players[bman.lastwinner].points += players[bman.lastwinner].nbrKilled;
    } else
        bman.lastwinner = -1;

    /* check which team was alife */
    if (bman.gametype == GT_team) {
        int t_nr;

        bman.lastwinner = -1;
        cnt_left = 0;

        for (t_nr = 0; t_nr < MAX_TEAMS; t_nr++)
            for (i = 0; i < MAX_PLAYERS; i++) {
                if (teams[t_nr].players[i] != NULL)
                    if (PS_IS_alife (teams[t_nr].players[i]->state)) {
                        if (bman.lastwinner != t_nr) {
                            teams[t_nr].wins++;
                            cnt_left++;
                            bman.lastwinner = t_nr;
                        }
                    }
            }

        if (cnt_left == 1) {
            /* set the points */
            cnt_left = 0;
            for (t_nr = 0; t_nr < MAX_TEAMS; t_nr++) {
                for (i = 0; (i < MAX_PLAYERS && teams[t_nr].players[i] != NULL); i++);
                if (i < MAX_PLAYERS && teams[t_nr].players[i] != NULL)
                    cnt_left++;
            }
            teams[bman.lastwinner].points += cnt_left;
        } else
            bman.lastwinner = -1;
    }

    if (GT_SP)
        game_showresult ();

    /* check which player is now free,i.e. disconnected during the game and was playing */
    for (i = 0; i < MAX_PLAYERS; i++)
        if ((players[i].state & PSF_used) == 0)
            players[i].state = 0;
}