Skip to content

Commit

Permalink
ALSA: hdspm - Simplify with snd_pcm_hw_constraint_pow2()
Browse files Browse the repository at this point in the history
Refactoring the code using snd_pcm_hw_constraint_pow2() helper function.

Tested-by: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Aug 15, 2011
1 parent 3fa9e3d commit d877681
Showing 1 changed file with 25 additions and 51 deletions.
76 changes: 25 additions & 51 deletions sound/pci/rme9652/hdspm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5705,19 +5705,6 @@ static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
return 0;
}

static unsigned int period_sizes_old[] = {
64, 128, 256, 512, 1024, 2048, 4096, 8192
};

static unsigned int period_sizes_new[] = {
64, 128, 256, 512, 1024, 2048, 4096, 32
};

/* RayDAT and AIO always have a buffer of 16384 samples per channel */
static unsigned int raydat_aio_buffer_sizes[] = {
16384
};

static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
.info = (SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
Expand Down Expand Up @@ -5768,24 +5755,6 @@ static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
.fifo_size = 0
};

static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = {
.count = ARRAY_SIZE(period_sizes_old),
.list = period_sizes_old,
.mask = 0
};

static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = {
.count = ARRAY_SIZE(period_sizes_new),
.list = period_sizes_new,
.mask = 0
};

static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = {
.count = ARRAY_SIZE(raydat_aio_buffer_sizes),
.list = raydat_aio_buffer_sizes,
.mask = 0
};

static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
Expand Down Expand Up @@ -5986,23 +5955,25 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
spin_unlock_irq(&hdspm->lock);

snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);

switch (hdspm->io_type) {
case AIO:
case RayDAT:
snd_pcm_hw_constraint_list(runtime, 0,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
&hw_constraints_period_sizes_new);
snd_pcm_hw_constraint_list(runtime, 0,
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
&hw_constraints_raydat_io_buffer);

snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
32, 4096);
/* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
16384, 16384);
break;

default:
snd_pcm_hw_constraint_list(runtime, 0,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
&hw_constraints_period_sizes_old);
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
64, 8192);
break;
}

if (AES32 == hdspm->io_type) {
Expand Down Expand Up @@ -6059,21 +6030,24 @@ static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
spin_unlock_irq(&hdspm->lock);

snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);

switch (hdspm->io_type) {
case AIO:
case RayDAT:
snd_pcm_hw_constraint_list(runtime, 0,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
&hw_constraints_period_sizes_new);
snd_pcm_hw_constraint_list(runtime, 0,
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
&hw_constraints_raydat_io_buffer);
break;
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
32, 4096);
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
16384, 16384);
break;

default:
snd_pcm_hw_constraint_list(runtime, 0,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
&hw_constraints_period_sizes_old);
snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
64, 8192);
break;
}

if (AES32 == hdspm->io_type) {
Expand Down

0 comments on commit d877681

Please sign in to comment.