Don't use SPA_AUDIO_MAX_CHANNELS directly

Make a MAX_CHANNELS define and use that one in code. This makes it
easier to change the constant later.
This commit is contained in:
Wim Taymans 2025-10-20 15:33:17 +02:00
parent eb096bfb62
commit 13b8c23767
30 changed files with 136 additions and 108 deletions

View file

@ -47,10 +47,11 @@ SPA_LOG_TOPIC_DEFINE_STATIC(log_topic, "spa.audioconvert");
#define DEFAULT_RATE 48000
#define DEFAULT_CHANNELS 2
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define MAX_ALIGN FMT_OPS_MAX_ALIGN
#define MAX_BUFFERS 32
#define MAX_DATAS SPA_AUDIO_MAX_CHANNELS
#define MAX_PORTS (SPA_AUDIO_MAX_CHANNELS+1)
#define MAX_DATAS MAX_CHANNELS
#define MAX_PORTS (MAX_CHANNELS+1)
#define MAX_STAGES 64
#define MAX_GRAPH 9 /* 8 active + 1 replacement slot */
@ -62,7 +63,7 @@ SPA_LOG_TOPIC_DEFINE_STATIC(log_topic, "spa.audioconvert");
struct volumes {
bool mute;
uint32_t n_volumes;
float volumes[SPA_AUDIO_MAX_CHANNELS];
float volumes[MAX_CHANNELS];
};
static void init_volumes(struct volumes *vol)
@ -70,7 +71,7 @@ static void init_volumes(struct volumes *vol)
uint32_t i;
vol->mute = DEFAULT_MUTE;
vol->n_volumes = 0;
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
vol->volumes[i] = DEFAULT_VOLUME;
}
@ -91,7 +92,7 @@ struct props {
float max_volume;
float prev_volume;
uint32_t n_channels;
uint32_t channel_map[SPA_AUDIO_MAX_CHANNELS];
uint32_t channel_map[MAX_CHANNELS];
struct volumes channel;
struct volumes soft;
struct volumes monitor;
@ -112,7 +113,7 @@ static void props_reset(struct props *props)
props->min_volume = DEFAULT_MIN_VOLUME;
props->max_volume = DEFAULT_MAX_VOLUME;
props->n_channels = 0;
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
props->channel_map[i] = SPA_AUDIO_CHANNEL_UNKNOWN;
init_volumes(&props->channel);
init_volumes(&props->soft);
@ -241,9 +242,9 @@ struct filter_graph {
struct spa_filter_graph *graph;
struct spa_hook listener;
uint32_t n_inputs;
uint32_t inputs_position[SPA_AUDIO_MAX_CHANNELS];
uint32_t inputs_position[MAX_CHANNELS];
uint32_t n_outputs;
uint32_t outputs_position[SPA_AUDIO_MAX_CHANNELS];
uint32_t outputs_position[MAX_CHANNELS];
uint32_t latency;
bool removing;
bool setup;
@ -1966,7 +1967,7 @@ static int node_set_param_port_config(struct impl *this, uint32_t flags,
return -EINVAL;
if (info.info.raw.channels == 0 ||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
info.info.raw.channels > MAX_CHANNELS)
return -EINVAL;
infop = &info;
@ -2153,7 +2154,7 @@ static void set_volume(struct impl *this)
{
struct volumes *vol;
uint32_t i;
float volumes[SPA_AUDIO_MAX_CHANNELS];
float volumes[MAX_CHANNELS];
struct dir *dir = &this->dir[this->direction];
spa_log_debug(this->log, "%p set volume %f have_format:%d", this, this->props.volume, dir->have_format);
@ -2671,7 +2672,7 @@ static int port_param_enum_formats(struct impl *impl, struct port *port, uint32_
}
spa_pod_builder_add(b,
SPA_FORMAT_AUDIO_channels, SPA_POD_CHOICE_RANGE_Int(
DEFAULT_CHANNELS, 1, SPA_AUDIO_MAX_CHANNELS),
DEFAULT_CHANNELS, 1, MAX_CHANNELS),
0);
*param = spa_pod_builder_pop(b, &f[0]);
}
@ -3064,7 +3065,7 @@ static int port_set_format(void *object,
if (info.info.raw.format == 0 ||
(!this->props.resample_disabled && info.info.raw.rate == 0) ||
info.info.raw.channels == 0 ||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS) {
info.info.raw.channels > MAX_CHANNELS) {
spa_log_error(this->log, "invalid format:%d rate:%d channels:%d",
info.info.raw.format, info.info.raw.rate,
info.info.raw.channels);

View file

@ -142,29 +142,29 @@ static uint32_t mask_to_ch(struct channelmix *mix, uint64_t mask)
}
static void distribute_mix(struct channelmix *mix,
float matrix[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS],
float matrix[MAX_CHANNELS][MAX_CHANNELS],
uint64_t mask)
{
uint32_t i, ch = mask_to_ch(mix, mask);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
matrix[i][ch]= 1.0f;
}
static void average_mix(struct channelmix *mix,
float matrix[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS],
float matrix[MAX_CHANNELS][MAX_CHANNELS],
uint64_t mask)
{
uint32_t i, ch = mask_to_ch(mix, mask);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
matrix[ch][i]= 1.0f;
}
static void pair_mix(float matrix[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS])
static void pair_mix(float matrix[MAX_CHANNELS][MAX_CHANNELS])
{
uint32_t i;
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
matrix[i][i]= 1.0f;
}
static bool match_mix(struct channelmix *mix,
float matrix[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS],
float matrix[MAX_CHANNELS][MAX_CHANNELS],
uint64_t src_mask, uint64_t dst_mask)
{
bool matched = false;
@ -181,7 +181,7 @@ static bool match_mix(struct channelmix *mix,
static int make_matrix(struct channelmix *mix)
{
float matrix[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS] = {{ 0.0f }};
float matrix[MAX_CHANNELS][MAX_CHANNELS] = {{ 0.0f }};
uint64_t src_mask = mix->src_mask, src_paired;
uint64_t dst_mask = mix->dst_mask, dst_paired;
uint32_t src_chan = mix->src_chan;
@ -293,7 +293,7 @@ static int make_matrix(struct channelmix *mix)
keep &= ~STEREO;
} else if (dst_mask & _MASK(MONO)){
spa_log_info(mix->log, "assign FC to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
matrix[i][_CH(FC)]= 1.0f;
normalize = true;
} else {
@ -313,7 +313,7 @@ static int make_matrix(struct channelmix *mix)
keep &= ~FRONT;
} else if ((dst_mask & _MASK(MONO))){
spa_log_info(mix->log, "assign STEREO to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++) {
for (i = 0; i < MAX_CHANNELS; i++) {
matrix[i][_CH(FL)]= 1.0f;
matrix[i][_CH(FR)]= 1.0f;
}
@ -352,7 +352,7 @@ static int make_matrix(struct channelmix *mix)
_MATRIX(FC,RC) += slev * SQRT1_2;
} else if (dst_mask & _MASK(MONO)){
spa_log_info(mix->log, "assign RC to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
matrix[i][_CH(RC)]= 1.0f;
normalize = true;
} else {
@ -398,7 +398,7 @@ static int make_matrix(struct channelmix *mix)
_MATRIX(FC,RR)+= slev * SQRT1_2;
} else if (dst_mask & _MASK(MONO)){
spa_log_info(mix->log, "assign RL+RR to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++) {
for (i = 0; i < MAX_CHANNELS; i++) {
matrix[i][_CH(RL)]= 1.0f;
matrix[i][_CH(RR)]= 1.0f;
}
@ -450,7 +450,7 @@ static int make_matrix(struct channelmix *mix)
_MATRIX(FC,SR) += slev * SQRT1_2;
} else if (dst_mask & _MASK(MONO)){
spa_log_info(mix->log, "assign SL+SR to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++) {
for (i = 0; i < MAX_CHANNELS; i++) {
matrix[i][_CH(SL)]= 1.0f;
matrix[i][_CH(SR)]= 1.0f;
}
@ -471,7 +471,7 @@ static int make_matrix(struct channelmix *mix)
_MATRIX(FC,FRC)+= SQRT1_2;
} else if (dst_mask & _MASK(MONO)){
spa_log_info(mix->log, "assign FLC+FRC to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++) {
for (i = 0; i < MAX_CHANNELS; i++) {
matrix[i][_CH(FLC)]= 1.0f;
matrix[i][_CH(FRC)]= 1.0f;
}
@ -492,7 +492,7 @@ static int make_matrix(struct channelmix *mix)
_MATRIX(FR,LFE) += llev * SQRT1_2;
} else if ((dst_mask & _MASK(MONO))){
spa_log_info(mix->log, "assign LFE to MONO (%f)", 1.0f);
for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++)
for (i = 0; i < MAX_CHANNELS; i++)
matrix[i][_CH(LFE)]= 1.0f;
normalize = true;
} else {
@ -690,7 +690,7 @@ done:
static void impl_channelmix_set_volume(struct channelmix *mix, float volume, bool mute,
uint32_t n_channel_volumes, float *channel_volumes)
{
float volumes[SPA_AUDIO_MAX_CHANNELS];
float volumes[MAX_CHANNELS];
float vol = mute ? 0.0f : volume, t;
uint32_t i, j;
uint32_t src_chan = mix->src_chan;
@ -760,8 +760,8 @@ int channelmix_init(struct channelmix *mix)
{
const struct channelmix_info *info;
if (mix->src_chan > SPA_AUDIO_MAX_CHANNELS ||
mix->dst_chan > SPA_AUDIO_MAX_CHANNELS)
if (mix->src_chan > MAX_CHANNELS ||
mix->dst_chan > MAX_CHANNELS)
return -EINVAL;
info = find_channelmix_info(mix->src_chan, mix->src_mask, mix->dst_chan, mix->dst_mask,

View file

@ -24,6 +24,7 @@
#define BUFFER_SIZE 4096
#define MAX_TAPS 255u
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define CHANNELMIX_OPS_MAX_ALIGN 16
@ -50,8 +51,8 @@ struct channelmix {
#define CHANNELMIX_FLAG_EQUAL (1<<2) /**< all values are equal */
#define CHANNELMIX_FLAG_COPY (1<<3) /**< 1 on diagonal, can be nxm */
uint32_t flags;
float matrix_orig[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS];
float matrix[SPA_AUDIO_MAX_CHANNELS][SPA_AUDIO_MAX_CHANNELS];
float matrix_orig[MAX_CHANNELS][MAX_CHANNELS];
float matrix[MAX_CHANNELS][MAX_CHANNELS];
float freq; /* sample frequency */
float lfe_cutoff; /* in Hz, 0 is disabled */
@ -59,7 +60,7 @@ struct channelmix {
float rear_delay; /* in ms, 0 is disabled */
float widen; /* stereo widen. 0 is disabled */
uint32_t hilbert_taps; /* to phase shift, 0 disabled */
struct lr4 lr4[SPA_AUDIO_MAX_CHANNELS];
struct lr4 lr4[MAX_CHANNELS];
float buffer_mem[2 * BUFFER_SIZE*2 + CHANNELMIX_OPS_MAX_ALIGN/4];
float *buffer[2];

View file

@ -25,7 +25,8 @@ SPA_LOG_IMPL(logger);
extern const struct spa_handle_factory test_source_factory;
#define MAX_PORTS (SPA_AUDIO_MAX_CHANNELS+1)
#define MAX_CHANNELS SPA_AUDIO_MAX_CHANNELS
#define MAX_PORTS (MAX_CHANNELS+1)
struct context {
struct spa_handle *convert_handle;