diff --git a/src/audio/alsa.c b/src/audio/alsa.c index 46911b2..89a593c 100644 --- a/src/audio/alsa.c +++ b/src/audio/alsa.c @@ -20,6 +20,8 @@ #include "audio.h" #include +#include + #include #include @@ -27,26 +29,23 @@ static snd_pcm_t *handle; static OpusMSDecoder* decoder; -static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT]; +static short pcmBuffer[FRAME_SIZE * AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; static int alsa_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, void* context, int arFlags) { int rc; - unsigned char alsaMapping[MAX_CHANNEL_COUNT]; + unsigned char alsaMapping[AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; /* The supplied mapping array has order: FL-FR-C-LFE-RL-RR-SL-SR * ALSA expects the order: FL-FR-RL-RR-C-LFE-SL-SR * We need copy the mapping locally and swap the channels around. */ - alsaMapping[0] = opusConfig->mapping[0]; - alsaMapping[1] = opusConfig->mapping[1]; + memcpy(alsaMapping, opusConfig->mapping, sizeof(alsaMapping)); if (opusConfig->channelCount >= 6) { alsaMapping[2] = opusConfig->mapping[4]; alsaMapping[3] = opusConfig->mapping[5]; alsaMapping[4] = opusConfig->mapping[2]; alsaMapping[5] = opusConfig->mapping[3]; } - alsaMapping[6] = opusConfig->mapping[6]; - alsaMapping[7] = opusConfig->mapping[7]; decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, alsaMapping, &rc); diff --git a/src/audio/audio.h b/src/audio/audio.h index 4d39519..470c307 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -21,7 +21,6 @@ #include -#define MAX_CHANNEL_COUNT 8 #define FRAME_SIZE 240 #define FRAME_BUFFER 12 diff --git a/src/audio/omx.c b/src/audio/omx.c index 3652fd5..21cec30 100644 --- a/src/audio/omx.c +++ b/src/audio/omx.c @@ -29,18 +29,18 @@ static OpusMSDecoder* decoder; ILCLIENT_T* handle; COMPONENT_T* component; static OMX_BUFFERHEADERTYPE *buf; -static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT]; +static short pcmBuffer[FRAME_SIZE * AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; static int channelCount; static int omx_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, void* context, int arFlags) { int rc, error; OMX_ERRORTYPE err; - unsigned char omxMapping[MAX_CHANNEL_COUNT]; + unsigned char omxMapping[AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; char* componentName = "audio_render"; channelCount = opusConfig->channelCount; - /* The supplied mapping array has order: FL-FR-C-LFE-RL-RR - * OMX expects the order: FL-FR-LFE-C-RL-RR + /* The supplied mapping array has order: FL-FR-C-LFE-RL-RR-SL-SR + * OMX expects the order: FL-FR-LFE-C-RL-RR-SL-SR * We need copy the mapping locally and swap the channels around. */ memcpy(omxMapping, opusConfig->mapping, sizeof(omxMapping)); diff --git a/src/audio/pulse.c b/src/audio/pulse.c index 0b86d4d..c10c57b 100644 --- a/src/audio/pulse.c +++ b/src/audio/pulse.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -28,7 +29,7 @@ static OpusMSDecoder* decoder; static pa_simple *dev = NULL; -static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT]; +static short pcmBuffer[FRAME_SIZE * AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; static int channelCount; bool audio_pulse_init(char* audio_device) { @@ -49,7 +50,7 @@ bool audio_pulse_init(char* audio_device) { static int pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, void* context, int arFlags) { int rc, error; - unsigned char alsaMapping[MAX_CHANNEL_COUNT]; + unsigned char alsaMapping[AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; channelCount = opusConfig->channelCount; @@ -57,16 +58,13 @@ static int pulse_renderer_init(int audioConfiguration, POPUS_MULTISTREAM_CONFIGU * ALSA expects the order: FL-FR-RL-RR-C-LFE-SL-SR * We need copy the mapping locally and swap the channels around. */ - alsaMapping[0] = opusConfig->mapping[0]; - alsaMapping[1] = opusConfig->mapping[1]; + memcpy(alsaMapping, opusConfig->mapping, sizeof(alsaMapping)); if (opusConfig->channelCount >= 6) { alsaMapping[2] = opusConfig->mapping[4]; alsaMapping[3] = opusConfig->mapping[5]; alsaMapping[4] = opusConfig->mapping[2]; alsaMapping[5] = opusConfig->mapping[3]; } - alsaMapping[6] = opusConfig->mapping[6]; - alsaMapping[7] = opusConfig->mapping[7]; decoder = opus_multistream_decoder_create(opusConfig->sampleRate, opusConfig->channelCount, opusConfig->streams, opusConfig->coupledStreams, alsaMapping, &rc); diff --git a/src/audio/sdl.c b/src/audio/sdl.c index 15a9ee0..34633ea 100644 --- a/src/audio/sdl.c +++ b/src/audio/sdl.c @@ -26,7 +26,7 @@ #include static OpusMSDecoder* decoder; -static short pcmBuffer[FRAME_SIZE * MAX_CHANNEL_COUNT]; +static short pcmBuffer[FRAME_SIZE * AUDIO_CONFIGURATION_MAX_CHANNEL_COUNT]; static SDL_AudioDeviceID dev; static int channelCount;