bool
audio_check_sample_rate(unsigned long sample_rate, GError **error_r)
{
	if (!audio_valid_sample_rate(sample_rate)) {
		g_set_error(error_r, audio_format_quark(), 0,
			    "Invalid sample rate: %lu", sample_rate);
		return false;
	}

	return true;
}
示例#2
0
static bool
sndfile_scan_file(const char *path_fs,
		  const struct tag_handler *handler, void *handler_ctx)
{
	SNDFILE *sf;
	SF_INFO info;
	const char *p;

	info.format = 0;

	sf = sf_open(path_fs, SFM_READ, &info);
	if (sf == NULL)
		return false;

	if (!audio_valid_sample_rate(info.samplerate)) {
		sf_close(sf);
		g_warning("Invalid sample rate in %s\n", path_fs);
		return false;
	}

	tag_handler_invoke_duration(handler, handler_ctx,
				    info.frames / info.samplerate);

	p = sf_get_string(sf, SF_STR_TITLE);
	if (p != NULL)
		tag_handler_invoke_tag(handler, handler_ctx,
				       TAG_TITLE, p);

	p = sf_get_string(sf, SF_STR_ARTIST);
	if (p != NULL)
		tag_handler_invoke_tag(handler, handler_ctx,
				       TAG_ARTIST, p);

	p = sf_get_string(sf, SF_STR_DATE);
	if (p != NULL)
		tag_handler_invoke_tag(handler, handler_ctx,
				       TAG_DATE, p);

	sf_close(sf);

	return true;
}
static struct tag *
sndfile_tag_dup(const char *path_fs)
{
	SNDFILE *sf;
	SF_INFO info;
	struct tag *tag;
	const char *p;

	info.format = 0;

	sf = sf_open(path_fs, SFM_READ, &info);
	if (sf == NULL)
		return NULL;

	if (!audio_valid_sample_rate(info.samplerate)) {
		sf_close(sf);
		g_warning("Invalid sample rate in %s\n", path_fs);
		return NULL;
	}

	tag = tag_new();
	tag->time = info.frames / info.samplerate;

	p = sf_get_string(sf, SF_STR_TITLE);
	if (p != NULL)
		tag_add_item(tag, TAG_TITLE, p);

	p = sf_get_string(sf, SF_STR_ARTIST);
	if (p != NULL)
		tag_add_item(tag, TAG_ARTIST, p);

	p = sf_get_string(sf, SF_STR_DATE);
	if (p != NULL)
		tag_add_item(tag, TAG_DATE, p);

	sf_close(sf);

	return tag;
}