Ejemplo n.º 1
0
static const int32_t *
pcm_convert_24(struct pcm_convert_state *state,
	       const struct audio_format *src_format,
	       const void *src_buffer, size_t src_size,
	       const struct audio_format *dest_format, size_t *dest_size_r,
	       GError **error_r)
{
	const int32_t *buf;
	size_t len;

	assert(dest_format->format == SAMPLE_FORMAT_S24_P32);

	buf = pcm_convert_to_24(&state->format_buffer, src_format->format,
				src_buffer, src_size, &len);
	if (buf == NULL) {
		g_set_error(error_r, pcm_convert_quark(), 0,
			    "Conversion from %s to 24 bit is not implemented",
			    sample_format_to_string(src_format->format));
		return NULL;
	}

	if (src_format->channels != dest_format->channels) {
		buf = pcm_convert_channels_24(&state->channels_buffer,
					      dest_format->channels,
					      src_format->channels,
					      buf, len, &len);
		if (buf == NULL) {
			g_set_error(error_r, pcm_convert_quark(), 0,
				    "Conversion from %u to %u channels "
				    "is not implemented",
				    src_format->channels,
				    dest_format->channels);
			return NULL;
		}
	}

	if (src_format->sample_rate != dest_format->sample_rate) {
		buf = pcm_resample_24(&state->resample,
				      dest_format->channels,
				      src_format->sample_rate, buf, len,
				      dest_format->sample_rate, &len,
				      error_r);
		if (buf == NULL)
			return NULL;
	}

	if (dest_format->reverse_endian) {
		buf = pcm_byteswap_32(&state->byteswap_buffer, buf, len);
		assert(buf != NULL);
	}

	*dest_size_r = len;
	return buf;
}
Ejemplo n.º 2
0
static const void *
pcm_convert_channels(struct pcm_buffer *buffer, enum sample_format format,
		     uint8_t dest_channels,
		     uint8_t src_channels, const void *src,
		     size_t src_size, size_t *dest_size_r,
		     GError **error_r)
{
	const void *dest = NULL;

	switch (format) {
	case SAMPLE_FORMAT_UNDEFINED:
	case SAMPLE_FORMAT_S8:
	case SAMPLE_FORMAT_S24:
	case SAMPLE_FORMAT_FLOAT:
	case SAMPLE_FORMAT_DSD:
	case SAMPLE_FORMAT_DSD_LSBFIRST:
		g_set_error(error_r, pcm_convert_quark(), 0,
			    "Channel conversion not implemented for format '%s'",
			    sample_format_to_string(format));
		return NULL;

	case SAMPLE_FORMAT_S16:
		dest = pcm_convert_channels_16(buffer, dest_channels,
					       src_channels, src,
					       src_size, dest_size_r);
		break;

	case SAMPLE_FORMAT_S24_P32:
		dest = pcm_convert_channels_24(buffer, dest_channels,
					       src_channels, src,
					       src_size, dest_size_r);
		break;

	case SAMPLE_FORMAT_S32:
		dest = pcm_convert_channels_32(buffer, dest_channels,
					       src_channels, src,
					       src_size, dest_size_r);
		break;
	}

	if (dest == NULL) {
		g_set_error(error_r, pcm_convert_quark(), 0,
			    "Conversion from %u to %u channels "
			    "is not implemented",
			    src_channels, dest_channels);
		return NULL;
	}

	return dest;
}