Пример #1
0
const void *
pcm_convert(struct pcm_convert_state *state,
	    const struct audio_format *src_format,
	    const void *src, size_t src_size,
	    const struct audio_format *dest_format,
	    size_t *dest_size_r,
	    GError **error_r)
{
	switch (dest_format->format) {
	case SAMPLE_FORMAT_S16:
		return pcm_convert_16(state,
				      src_format, src, src_size,
				      dest_format, dest_size_r,
				      error_r);

	case SAMPLE_FORMAT_S24:
		return pcm_convert_24_packed(state,
					     src_format, src, src_size,
					     dest_format, dest_size_r,
					     error_r);

	case SAMPLE_FORMAT_S24_P32:
		return pcm_convert_24(state,
				      src_format, src, src_size,
				      dest_format, dest_size_r,
				      error_r);

	case SAMPLE_FORMAT_S32:
		return pcm_convert_32(state,
				      src_format, src, src_size,
				      dest_format, dest_size_r,
				      error_r);

	default:
		g_set_error(error_r, pcm_convert_quark(), 0,
			    "PCM conversion to %s is not implemented",
			    sample_format_to_string(dest_format->format));
		return NULL;
	}
}
Пример #2
0
const void *
pcm_convert(struct pcm_convert_state *state,
	    const struct audio_format *src_format,
	    const void *src, size_t src_size,
	    const struct audio_format *dest_format,
	    size_t *dest_size_r,
	    GError **error_r)
{
	if (src_format->reverse_endian) {
		/* convert to host byte order, because all of our
		   conversion libraries assume host byte order */

		src = pcm_byteswap(&state->byteswap_buffer, src_format->format,
				   src, src_size);
		if (src == NULL) {
			g_set_error(error_r, pcm_convert_quark(), 0,
				    "PCM byte order change of format '%s' is not implemented",
				    sample_format_to_string(src_format->format));
			return NULL;
		}
	}

	struct audio_format float_format;
	if (src_format->format == SAMPLE_FORMAT_DSD ||
	    src_format->format == SAMPLE_FORMAT_DSD_LSBFIRST) {
		size_t f_size;
		const bool lsbfirst =
			src_format->format == SAMPLE_FORMAT_DSD_LSBFIRST;
		const float *f = pcm_dsd_to_float(&state->dsd,
						  src_format->channels,
						  lsbfirst, src, src_size,
						  &f_size);
		if (f == NULL) {
			g_set_error_literal(error_r, pcm_convert_quark(), 0,
					    "DSD to PCM conversion failed");
			return NULL;
		}

		float_format = *src_format;
		float_format.format = SAMPLE_FORMAT_FLOAT;

		src_format = &float_format;
		src = f;
		src_size = f_size;
	}

	switch (dest_format->format) {
	case SAMPLE_FORMAT_S16:
		return pcm_convert_16(state,
				      src_format, src, src_size,
				      dest_format, dest_size_r,
				      error_r);

	case SAMPLE_FORMAT_S24:
		return pcm_convert_24_packed(state,
					     src_format, src, src_size,
					     dest_format, dest_size_r,
					     error_r);

	case SAMPLE_FORMAT_S24_P32:
		return pcm_convert_24(state,
				      src_format, src, src_size,
				      dest_format, dest_size_r,
				      error_r);

	case SAMPLE_FORMAT_S32:
		return pcm_convert_32(state,
				      src_format, src, src_size,
				      dest_format, dest_size_r,
				      error_r);

	case SAMPLE_FORMAT_FLOAT:
		return pcm_convert_float(state,
					 src_format, src, src_size,
					 dest_format, dest_size_r,
					 error_r);

	default:
		g_set_error(error_r, pcm_convert_quark(), 0,
			    "PCM conversion to %s is not implemented",
			    sample_format_to_string(dest_format->format));
		return NULL;
	}
}