예제 #1
0
int dumb_source_update(audio_source *src, char *buffer, int len) {
    dumb_source *local = source_get_userdata(src);

    // Get deltatime and bitrate
    float delta = 65536.0f / source_get_frequency(src);
    int bps = source_get_channels(src) * source_get_bytes(src);

    // If looping is off, and if we have played the whole file, stop here.
    long pos = duh_sigrenderer_get_position(local->renderer);
    if(pos < local->vpos && !src->loop) {
        return 0;
    }
    local->vpos = pos;

    // ... otherwise get more data.
    int ret = duh_render_int(
            local->renderer,
            &local->sig_samples,
            &local->sig_samples_size,
            source_get_bytes(src) * 8, // Bits
            0,  // Unsign
            1.0f, // Volume
            delta,
            len / bps, // Size
            buffer
        ) * bps;
    return ret;
}
예제 #2
0
파일: dumbplay.c 프로젝트: codefoco/dumb
// This is called from SDL2, and should read data from a source and hand it over
// to SDL2 via the stream buffer.
void stream_audio(void *userdata, Uint8 *stream, int len) {
    streamer_t *streamer = (streamer_t *)userdata;

    // Read samples from libdumb save them to the SDL buffer. Note that we are
    // reading SAMPLES, not bytes!
    int r_samples = len / streamer->sbytes;
    int got =
        duh_render_int(streamer->renderer, &streamer->sig_samples,
                       &streamer->sig_samples_size, streamer->bits, 0,
                       streamer->volume, streamer->delta, r_samples, stream);
    if (got == 0) {
        streamer->ended = true;
    }

    // Get current position from libdumb for the playback display. If we get
    // position that is 0, it probably means that the song ended and
    // duh_sigrenderer_get_position points to the start of the file.
    streamer->spos = duh_sigrenderer_get_position(streamer->renderer);
    if (streamer->spos == 0) {
        streamer->spos = streamer->ssize;
    }
}