const void * pcm_byteswap(struct pcm_buffer *buffer, enum sample_format format, const void *src, size_t size) { switch (format) { case SAMPLE_FORMAT_UNDEFINED: case SAMPLE_FORMAT_S24: case SAMPLE_FORMAT_FLOAT: /* not implemented */ return NULL; case SAMPLE_FORMAT_S8: case SAMPLE_FORMAT_DSD: case SAMPLE_FORMAT_DSD_LSBFIRST: return src; case SAMPLE_FORMAT_S16: return pcm_byteswap_16(buffer, src, size); case SAMPLE_FORMAT_S24_P32: case SAMPLE_FORMAT_S32: return pcm_byteswap_32(buffer, src, size); } /* unreachable */ assert(false); return NULL; }
static const int32_t * pcm_convert_32(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_S32); buf = pcm_convert_to_32(&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_32(&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_32(&state->resample, dest_format->channels, src_format->sample_rate, buf, len, dest_format->sample_rate, &len, error_r); if (buf == NULL) return buf; } if (dest_format->reverse_endian) { buf = pcm_byteswap_32(&state->byteswap_buffer, buf, len); assert(buf != NULL); } *dest_size_r = len; return buf; }