Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c57cccc0 authored by Clemens Ladisch's avatar Clemens Ladisch Committed by Jaroslav Kysela
Browse files

[ALSA] oxygen: optimize snd_pcm_hardware structures



Add one more indirection to the lookup of the snd_pcm_hardware
structures so that we can save the space of the duplicate ones.

Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 7f0b8946
Loading
Loading
Loading
Loading
+79 −150
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@
#include <sound/pcm_params.h>
#include "oxygen.h"

static struct snd_pcm_hardware oxygen_hardware[PCM_COUNT] = {
	[PCM_A] = {
static const struct snd_pcm_hardware oxygen_stereo_hardware = {
	.info = SNDRV_PCM_INFO_MMAP |
		SNDRV_PCM_INFO_MMAP_VALID |
		SNDRV_PCM_INFO_INTERLEAVED |
@@ -50,86 +49,8 @@ static struct snd_pcm_hardware oxygen_hardware[PCM_COUNT] = {
	.period_bytes_max = 128 * 1024,
	.periods_min = 2,
	.periods_max = 2048,
	},
	[PCM_B] = {
		.info = SNDRV_PCM_INFO_MMAP |
			SNDRV_PCM_INFO_MMAP_VALID |
			SNDRV_PCM_INFO_INTERLEAVED |
			SNDRV_PCM_INFO_PAUSE |
			SNDRV_PCM_INFO_SYNC_START,
		.formats = SNDRV_PCM_FMTBIT_S16_LE |
			   SNDRV_PCM_FMTBIT_S32_LE,
		.rates = SNDRV_PCM_RATE_32000 |
			 SNDRV_PCM_RATE_44100 |
			 SNDRV_PCM_RATE_48000 |
			 SNDRV_PCM_RATE_64000 |
			 SNDRV_PCM_RATE_88200 |
			 SNDRV_PCM_RATE_96000 |
			 SNDRV_PCM_RATE_176400 |
			 SNDRV_PCM_RATE_192000,
		.rate_min = 32000,
		.rate_max = 192000,
		.channels_min = 2,
		.channels_max = 2,
		.buffer_bytes_max = 256 * 1024,
		.period_bytes_min = 128,
		.period_bytes_max = 128 * 1024,
		.periods_min = 2,
		.periods_max = 2048,
	},
	[PCM_C] = {
		.info = SNDRV_PCM_INFO_MMAP |
			SNDRV_PCM_INFO_MMAP_VALID |
			SNDRV_PCM_INFO_INTERLEAVED |
			SNDRV_PCM_INFO_PAUSE |
			SNDRV_PCM_INFO_SYNC_START,
		.formats = SNDRV_PCM_FMTBIT_S16_LE |
			   SNDRV_PCM_FMTBIT_S32_LE,
		.rates = SNDRV_PCM_RATE_32000 |
			 SNDRV_PCM_RATE_44100 |
			 SNDRV_PCM_RATE_48000 |
			 SNDRV_PCM_RATE_64000 |
			 SNDRV_PCM_RATE_88200 |
			 SNDRV_PCM_RATE_96000 |
			 SNDRV_PCM_RATE_176400 |
			 SNDRV_PCM_RATE_192000,
		.rate_min = 32000,
		.rate_max = 192000,
		.channels_min = 2,
		.channels_max = 2,
		.buffer_bytes_max = 256 * 1024,
		.period_bytes_min = 128,
		.period_bytes_max = 128 * 1024,
		.periods_min = 2,
		.periods_max = 2048,
	},
	[PCM_SPDIF] = {
		.info = SNDRV_PCM_INFO_MMAP |
			SNDRV_PCM_INFO_MMAP_VALID |
			SNDRV_PCM_INFO_INTERLEAVED |
			SNDRV_PCM_INFO_PAUSE |
			SNDRV_PCM_INFO_SYNC_START,
		.formats = SNDRV_PCM_FMTBIT_S16_LE |
			   SNDRV_PCM_FMTBIT_S32_LE,
		.rates = SNDRV_PCM_RATE_32000 |
			 SNDRV_PCM_RATE_44100 |
			 SNDRV_PCM_RATE_48000 |
			 SNDRV_PCM_RATE_64000 |
			 SNDRV_PCM_RATE_88200 |
			 SNDRV_PCM_RATE_96000 |
			 SNDRV_PCM_RATE_176400 |
			 SNDRV_PCM_RATE_192000,
		.rate_min = 32000,
		.rate_max = 192000,
		.channels_min = 2,
		.channels_max = 2,
		.buffer_bytes_max = 256 * 1024,
		.period_bytes_min = 128,
		.period_bytes_max = 128 * 1024,
		.periods_min = 2,
		.periods_max = 2048,
	},
	[PCM_MULTICH] = {
};
static const struct snd_pcm_hardware oxygen_multichannel_hardware = {
	.info = SNDRV_PCM_INFO_MMAP |
		SNDRV_PCM_INFO_MMAP_VALID |
		SNDRV_PCM_INFO_INTERLEAVED |
@@ -154,8 +75,8 @@ static struct snd_pcm_hardware oxygen_hardware[PCM_COUNT] = {
	.period_bytes_max = 256 * 1024,
	.periods_min = 2,
	.periods_max = 16384,
	},
	[PCM_AC97] = {
};
static const struct snd_pcm_hardware oxygen_ac97_hardware = {
	.info = SNDRV_PCM_INFO_MMAP |
		SNDRV_PCM_INFO_MMAP_VALID |
		SNDRV_PCM_INFO_INTERLEAVED |
@@ -172,7 +93,15 @@ static struct snd_pcm_hardware oxygen_hardware[PCM_COUNT] = {
	.period_bytes_max = 128 * 1024,
	.periods_min = 2,
	.periods_max = 2048,
	},
};

static const struct snd_pcm_hardware *const oxygen_hardware[PCM_COUNT] = {
	[PCM_A] = &oxygen_stereo_hardware,
	[PCM_B] = &oxygen_stereo_hardware,
	[PCM_C] = &oxygen_stereo_hardware,
	[PCM_SPDIF] = &oxygen_stereo_hardware,
	[PCM_MULTICH] = &oxygen_multichannel_hardware,
	[PCM_AC97] = &oxygen_ac97_hardware,
};

static inline unsigned int
@@ -189,7 +118,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
	int err;

	runtime->private_data = (void *)(uintptr_t)channel;
	runtime->hw = oxygen_hardware[channel];
	runtime->hw = *oxygen_hardware[channel];
	if (chip->model->pcm_hardware_filter)
		chip->model->pcm_hardware_filter(channel, &runtime->hw);
	err = snd_pcm_hw_constraint_step(runtime, 0,