int32_t buffered_reader_enable_cache(buffered_reader_t * reader, int32_t enabled)
{
	int32_t prev;

	prev = reader->cache_enabled;

	if (!prev && enabled) {
		buffered_reader_reset_buffer(reader, buffered_reader_position(reader));
	} else if (prev && !enabled) {
		long long result;

		sceIoWaitAsync(reader->handle, &result);
		sceIoLseek32(reader->handle, buffered_reader_position(reader), PSP_SEEK_SET);
	}

	reader->cache_enabled = enabled;

	return prev;
}
Beispiel #2
0
static int mp3_seek_seconds_offset(double npt)
{
	int new_pos;

	if (npt < 0) {
		npt = 0;
	} else if (npt > g_info.duration) {
		__end();
		return -1;
	}

	new_pos = npt * mp3info.average_bitrate / 8;

	if (new_pos < 0) {
		new_pos = 0;
	}

	if (mp3_data.use_buffer)
		buffered_reader_seek(mp3_data.r, new_pos);
	else
		xrIoLseek(mp3_data.fd, new_pos, PSP_SEEK_SET);

	mad_stream_finish(&stream);
	mad_stream_init(&stream);

	if (seek_valid_frame() == -1) {
		__end();
		return -1;
	}

	if (g_info.filesize > 0) {
		long cur_pos;

		if (mp3_data.use_buffer)
			cur_pos = buffered_reader_position(mp3_data.r);
		else
			cur_pos = xrIoLseek(mp3_data.fd, 0, PSP_SEEK_CUR);
		g_play_time = g_info.duration * cur_pos / g_info.filesize;
	} else {
		g_play_time = npt;
	}

	if (g_play_time < 0)
		g_play_time = 0;

	return 0;
}