audioconvert: add converstion to and from alaw/ulaw

This commit is contained in:
Wim Taymans 2021-08-17 17:32:25 +02:00
parent d0d7f2f20b
commit df9f79d869
4 changed files with 2235 additions and 0 deletions

View file

@ -31,6 +31,7 @@
#include <spa/param/audio/format-utils.h>
#include "fmt-ops.h"
#include "law.h"
void
conv_copy8d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
@ -210,6 +211,34 @@ conv_s8d_to_f32_c(struct convert *conv, void * SPA_RESTRICT dst[], const void *
}
}
void
conv_alaw_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
uint32_t n_samples)
{
const int8_t *s = src[0];
float **d = (float **) dst;
uint32_t i, j, n_channels = conv->n_channels;
for (j = 0; j < n_samples; j++) {
for (i = 0; i < n_channels; i++)
d[i][j] = alaw_to_f32(*s++);
}
}
void
conv_ulaw_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
uint32_t n_samples)
{
const int8_t *s = src[0];
float **d = (float **) dst;
uint32_t i, j, n_channels = conv->n_channels;
for (j = 0; j < n_samples; j++) {
for (i = 0; i < n_channels; i++)
d[i][j] = ulaw_to_f32(*s++);
}
}
void
conv_s16d_to_f32d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
uint32_t n_samples)
@ -617,6 +646,34 @@ conv_f32d_to_s8_c(struct convert *conv, void * SPA_RESTRICT dst[], const void *
}
}
void
conv_f32d_to_alaw_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
uint32_t n_samples)
{
const float **s = (const float **) src;
int8_t *d = dst[0];
uint32_t i, j, n_channels = conv->n_channels;
for (j = 0; j < n_samples; j++) {
for (i = 0; i < n_channels; i++)
*d++ = f32_to_alaw(s[i][j]);
}
}
void
conv_f32d_to_ulaw_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
uint32_t n_samples)
{
const float **s = (const float **) src;
int8_t *d = dst[0];
uint32_t i, j, n_channels = conv->n_channels;
for (j = 0; j < n_samples; j++) {
for (i = 0; i < n_channels; i++)
*d++ = f32_to_ulaw(s[i][j]);
}
}
void
conv_f32d_to_s16d_c(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
uint32_t n_samples)