コード例 #1
0
ファイル: kcm_instance.c プロジェクト: sesc4mt/mvcdecoder
/* Function: al_play_sample_instance
 */
bool al_play_sample_instance(ALLEGRO_SAMPLE_INSTANCE *spl)
{
    ASSERT(spl);

    return al_set_sample_instance_playing(spl, true);
}
コード例 #2
0
ファイル: kcm_instance.c プロジェクト: BorisCarvajal/allegro5
/* Function: al_set_sample
 */
bool al_set_sample(ALLEGRO_SAMPLE_INSTANCE *spl, ALLEGRO_SAMPLE *data)
{
    sample_parent_t old_parent;
    bool need_reattach;

    ASSERT(spl);

    /* Stop the sample if it is playing. */
    if (spl->is_playing) {
        if (!al_set_sample_instance_playing(spl, false)) {
            /* Shouldn't happen. */
            ASSERT(false);
            return false;
        }
    }

    if (!data) {
        if (spl->parent.u.ptr) {
            _al_kcm_detach_from_parent(spl);
        }
        spl->spl_data.buffer.ptr = NULL;
        return true;
    }

    /* Have data. */

    need_reattach = false;
    if (spl->parent.u.ptr != NULL) {
        if (spl->spl_data.frequency != data->frequency ||
                spl->spl_data.depth != data->depth ||
                spl->spl_data.chan_conf != data->chan_conf) {
            old_parent = spl->parent;
            need_reattach = true;
            _al_kcm_detach_from_parent(spl);
        }
    }

    spl->spl_data = *data;
    spl->spl_data.free_buf = false;
    spl->pos = 0;
    spl->loop_start = 0;
    spl->loop_end = data->len;
    /* Should we reset the loop mode? */

    if (need_reattach) {
        if (old_parent.is_voice) {
            if (!al_attach_sample_instance_to_voice(spl, old_parent.u.voice)) {
                spl->spl_data.buffer.ptr = NULL;
                return false;
            }
        }
        else {
            if (!al_attach_sample_instance_to_mixer(spl, old_parent.u.mixer)) {
                spl->spl_data.buffer.ptr = NULL;
                return false;
            }
        }
    }

    return true;
}