* limitations under the License.
*/
-//#define LOG_NDEBUG 0
+/* #define LOG_NDEBUG 0 */
#define LOG_TAG "audio_utils_format"
#include <cutils/log.h>
#include <audio_utils/format.h>
void memcpy_by_audio_format(void *dst, audio_format_t dst_format,
- void *src, audio_format_t src_format, size_t count) {
- if (dst_format == src_format
- && (dst_format == AUDIO_FORMAT_PCM_16_BIT
- || dst_format == AUDIO_FORMAT_PCM_FLOAT
- || dst_format == AUDIO_FORMAT_PCM_24_BIT_PACKED)) {
- memcpy(dst, src, count * audio_bytes_per_sample(dst_format));
- return;
+ void *src, audio_format_t src_format, size_t count)
+{
+ /* default cases for error falls through to fatal log below. */
+ if (dst_format == src_format) {
+ switch (dst_format) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ case AUDIO_FORMAT_PCM_FLOAT:
+ case AUDIO_FORMAT_PCM_24_BIT_PACKED:
+ case AUDIO_FORMAT_PCM_32_BIT:
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ memcpy(dst, src, count * audio_bytes_per_sample(dst_format));
+ return;
+ default:
+ break;
+ }
}
switch (dst_format) {
case AUDIO_FORMAT_PCM_16_BIT:
case AUDIO_FORMAT_PCM_24_BIT_PACKED:
memcpy_to_i16_from_p24((int16_t*)dst, (uint8_t*)src, count);
return;
+ case AUDIO_FORMAT_PCM_32_BIT:
+ memcpy_to_i16_from_i32((int16_t*)dst, (int32_t*)src, count);
+ return;
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ memcpy_to_i16_from_q8_23((int16_t*)dst, (int32_t*)src, count);
+ return;
default:
break;
}
case AUDIO_FORMAT_PCM_24_BIT_PACKED:
memcpy_to_float_from_p24((float*)dst, (uint8_t*)src, count);
return;
+ case AUDIO_FORMAT_PCM_32_BIT:
+ memcpy_to_float_from_i32((float*)dst, (int32_t*)src, count);
+ return;
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ memcpy_to_float_from_q8_23((float*)dst, (int32_t*)src, count);
+ return;
default:
break;
}
break;
}
break;
+ case AUDIO_FORMAT_PCM_32_BIT:
+ switch (src_format) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ memcpy_to_i32_from_i16((int32_t*)dst, (int16_t*)src, count);
+ return;
+ case AUDIO_FORMAT_PCM_FLOAT:
+ memcpy_to_i32_from_float((int32_t*)dst, (float*)src, count);
+ return;
+ default:
+ break;
+ }
+ break;
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ switch (src_format) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ memcpy_to_q8_23_from_i16((int32_t*)dst, (int16_t*)src, count);
+ return;
+ case AUDIO_FORMAT_PCM_FLOAT:
+ memcpy_to_q8_23_from_float_with_clamp((int32_t*)dst, (float*)src, count);
+ return;
+ default:
+ break;
+ }
+ break;
default:
break;
}
* src_format Source buffer format
* count Number of samples to copy
*
- * Permitted format types for dst_format and src_format are as follows:
+ * Allowed format conversions are given by either case 1 or 2 below:
+ *
+ * 1) One of src_format or dst_format is AUDIO_FORMAT_PCM_16_BIT or
+ * AUDIO_FORMAT_PCM_FLOAT, and the other format type is one of:
+ *
* AUDIO_FORMAT_PCM_16_BIT
- * AUDIO_FORMAT_PCM_24_BIT_PACKED
* AUDIO_FORMAT_PCM_FLOAT
+ * AUDIO_FORMAT_PCM_24_BIT_PACKED
+ * AUDIO_FORMAT_PCM_32_BIT
+ * AUDIO_FORMAT_PCM_8_24_BIT
+ *
+ * 2) Both dst_format and src_format are identical and of the list given
+ * in (1). This is a straight copy.
*
* The destination and source buffers must be completely separate if the destination
* format size is larger than the source format size. These routines call functions
* in primitives.h, so descriptions of detailed behavior can be reviewed there.
*
- * Logs a fatal error if dst or src format is not one of the permitted types.
+ * Logs a fatal error if dst or src format is not allowed by the conversion rules above.
*/
void memcpy_by_audio_format(void *dst, audio_format_t dst_format,
void *src, audio_format_t src_format, size_t count);