Exemple #1
0
action_gui GUI_whichbutton(int x, int y, SDL_Surface * pscreen, struct vdIn *videoIn)
{
    int nbutton, retval;
    FIXED scaleh = TO_FIXED(pscreen->h) / (videoIn->height + 32);
    int nheight = FROM_FIXED(scaleh * videoIn->height);
    if (y < nheight)
        return (A_VIDEO);
    nbutton = FROM_FIXED(scaleh * 32);
    /* 8 buttons across the screen, corresponding to 0-7 extand to 16*/
    retval = (x * 16) / (pscreen->w);
    /* Bottom half of the button denoted by flag|0x10 */
    if (y > (nheight + (nbutton / 2)))
        retval |= 0x10;
    return ((action_gui) retval);
}
void Effects_Buffer::mix_effects( blip_sample_t* out_, int pair_count )
{
    typedef fixed_t stereo_fixed_t [stereo];

    // add channels with echo, do echo, add channels without echo, then convert to 16-bit and output
    int echo_phase = 1;
    do
    {
        // mix any modified buffers
        {
            buf_t* buf = bufs;
            int bufs_remain = bufs_size;
            do
            {
                if ( buf->non_silent() && ( buf->echo == (bool)echo_phase ) )
                {
                    stereo_fixed_t* BLIP_RESTRICT out = (stereo_fixed_t*) &echo [echo_pos];
                    int const bass = BLIP_READER_BASS( *buf );
                    BLIP_READER_BEGIN( in, *buf );
                    BLIP_READER_ADJ_( in, mixer.samples_read );
                    fixed_t const vol_0 = buf->vol [0];
                    fixed_t const vol_1 = buf->vol [1];

                    int count = unsigned (echo_size - echo_pos) / stereo;
                    int remain = pair_count;
                    if ( count > remain )
                        count = remain;
                    do
                    {
                        remain -= count;
                        BLIP_READER_ADJ_( in, count );

                        out += count;
                        int offset = -count;
                        do
                        {
                            fixed_t s = BLIP_READER_READ( in );
                            BLIP_READER_NEXT_IDX_( in, bass, offset );

                            out [offset] [0] += s * vol_0;
                            out [offset] [1] += s * vol_1;
                        }
                        while ( ++offset );

                        out = (stereo_fixed_t*) echo.begin();
                        count = remain;
                    }
                    while ( remain );

                    BLIP_READER_END( in, *buf );
                }
                buf++;
            }
            while ( --bufs_remain );
        }

        // add echo
        if ( echo_phase && !no_echo )
        {
            fixed_t const feedback = s.feedback;
            fixed_t const treble   = s.treble;

            int i = 1;
            do
            {
                fixed_t low_pass = s.low_pass [i];

                fixed_t* echo_end = &echo [echo_size + i];
                fixed_t const* BLIP_RESTRICT in_pos = &echo [echo_pos + i];
                blargg_long out_offset = echo_pos + i + s.delay [i];
                if ( out_offset >= echo_size )
                    out_offset -= echo_size;
                assert( out_offset < echo_size );
                fixed_t* BLIP_RESTRICT out_pos = &echo [out_offset];

                // break into up to three chunks to avoid having to handle wrap-around
                // in middle of core loop
                int remain = pair_count;
                do
                {
                    fixed_t const* pos = in_pos;
                    if ( pos < out_pos )
                        pos = out_pos;
                    int count = blargg_ulong ((char*) echo_end - (char const*) pos) /
                                unsigned (stereo * sizeof (fixed_t));
                    if ( count > remain )
                        count = remain;
                    remain -= count;

                    in_pos  += count * stereo;
                    out_pos += count * stereo;
                    int offset = -count;
                    do
                    {
                        low_pass += FROM_FIXED( in_pos [offset * stereo] - low_pass ) * treble;
                        out_pos [offset * stereo] = FROM_FIXED( low_pass ) * feedback;
                    }
                    while ( ++offset );

                    if (  in_pos >= echo_end )  in_pos -= echo_size;
                    if ( out_pos >= echo_end ) out_pos -= echo_size;
                }
                while ( remain );

                s.low_pass [i] = low_pass;
            }
            while ( --i >= 0 );
        }
    }
    while ( --echo_phase >= 0 );

    // clamp to 16 bits
    {
        stereo_fixed_t const* BLIP_RESTRICT in = (stereo_fixed_t*) &echo [echo_pos];
        typedef blip_sample_t stereo_blip_sample_t [stereo];
        stereo_blip_sample_t* BLIP_RESTRICT out = (stereo_blip_sample_t*) out_;
        int count = unsigned (echo_size - echo_pos) / (unsigned) stereo;
        int remain = pair_count;
        if ( count > remain )
            count = remain;
        do
        {
            remain -= count;
            in  += count;
            out += count;
            int offset = -count;
            do
            {
                fixed_t in_0 = FROM_FIXED( in [offset] [0] );
                fixed_t in_1 = FROM_FIXED( in [offset] [1] );

                BLIP_CLAMP( in_0, in_0 );
                out [offset] [0] = (blip_sample_t) in_0;

                BLIP_CLAMP( in_1, in_1 );
                out [offset] [1] = (blip_sample_t) in_1;
            }
            while ( ++offset );

            in = (stereo_fixed_t*) echo.begin();
            count = remain;
        }
        while ( remain );
    }
}