Skip to content

Commit

Permalink
ALSA: compress: change the way sample rates are sent to kernel
Browse files Browse the repository at this point in the history
The usage of SNDRV_RATES is not effective as we can have rates like 12000 or
some other ones used by decoders. This change the usage of this to use the raw
Hz values to be sent to kernel

Bug: 17398311.

Change-Id: I1a1a68fa1db66a93b054a97b6c03cc1fbe69ed4b
Signed-off-by: Vinod Koul <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
Signed-off-by: Eric Laurent <[email protected]>
  • Loading branch information
Eric Laurent authored and invisiblek committed Jun 6, 2016
1 parent ee8cb5b commit 2745769
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 49 deletions.
2 changes: 1 addition & 1 deletion include/sound/compress_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ union snd_codec_options {

/** struct snd_codec_desc - description of codec capabilities
* @max_ch: Maximum number of audio channels
* @sample_rates: Sampling rates in Hz, use SNDRV_PCM_RATE_xxx for this
* @sample_rates: Sampling rates in Hz, use values like 48000 for this
* @bit_rate: Indexed array containing supported bit rates
* @num_bitrates: Number of valid values in bit_rate array
* @rate_control: value is specified by SND_RATECONTROLMODE defines.
Expand Down
72 changes: 24 additions & 48 deletions sound/soc/msm/qdsp6v2/msm-compress-q6-v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ struct msm_compr_gapless_state {
bool use_dsp_gapless_mode;
};

static unsigned int supported_sample_rates[] = {
8000, 11025, 12000, 16000, 22050, 24000, 32000,
#ifdef CONFIG_HD_AUDIO
44100, 48000, 64000, 88200, 96000, 176400, 192000
#else
44100
#endif
};

struct msm_compr_pdata {
atomic_t audio_ocmem_req;
struct snd_compr_stream *cstream[MSM_FRONTEND_DAI_MAX];
Expand Down Expand Up @@ -1046,58 +1055,17 @@ static int msm_compr_set_params(struct snd_compr_stream *cstream,
struct snd_compr_runtime *runtime = cstream->runtime;
struct msm_compr_audio *prtd = runtime->private_data;
int ret = 0, frame_sz = 0, delay_time_ms = 0;
int i, num_rates;
bool is_format_gapless = false;

pr_debug("%s\n", __func__);

memcpy(&prtd->codec_param, params, sizeof(struct snd_compr_params));

/* ToDo: remove duplicates */
prtd->num_channels = prtd->codec_param.codec.ch_in;

switch (prtd->codec_param.codec.sample_rate) {
case SNDRV_PCM_RATE_8000:
prtd->sample_rate = 8000;
break;
case SNDRV_PCM_RATE_11025:
prtd->sample_rate = 11025;
break;
/* ToDo: What about 12K and 24K sample rates ? */
case SNDRV_PCM_RATE_16000:
prtd->sample_rate = 16000;
break;
case SNDRV_PCM_RATE_22050:
prtd->sample_rate = 22050;
break;
case SNDRV_PCM_RATE_32000:
prtd->sample_rate = 32000;
break;
case SNDRV_PCM_RATE_44100:
prtd->sample_rate = 44100;
break;
case SNDRV_PCM_RATE_48000:
prtd->sample_rate = 48000;
break;
#ifdef CONFIG_HD_AUDIO
case SNDRV_PCM_RATE_64000:
prtd->sample_rate = 64000;
break;
case SNDRV_PCM_RATE_88200:
prtd->sample_rate = 88200;
break;
case SNDRV_PCM_RATE_96000:
prtd->sample_rate = 96000;
break;
case SNDRV_PCM_RATE_176400:
prtd->sample_rate = 176400;
break;
case SNDRV_PCM_RATE_192000:
prtd->sample_rate = 192000;
break;
#endif
}

pr_debug("%s: sample_rate %d\n", __func__, prtd->sample_rate);
num_rates = sizeof(supported_sample_rates)/sizeof(unsigned int);
for (i = 0; i < num_rates; i++)
if (params->codec.sample_rate == supported_sample_rates[i])
break;
if (i == num_rates)
return -EINVAL;

switch (params->codec.id) {
case SND_AUDIOCODEC_PCM: {
Expand Down Expand Up @@ -1192,6 +1160,12 @@ static int msm_compr_set_params(struct snd_compr_stream *cstream,
}
prtd->partial_drain_delay = delay_time_ms;

memcpy(&prtd->codec_param, params, sizeof(struct snd_compr_params));

/* ToDo: remove duplicates */
prtd->num_channels = prtd->codec_param.codec.ch_in;
prtd->sample_rate = prtd->codec_param.codec.sample_rate;
pr_debug("%s: sample_rate %d\n", __func__, prtd->sample_rate);
ret = msm_compr_configure_dsp(cstream);

return ret;
Expand Down Expand Up @@ -1892,6 +1866,7 @@ static int msm_compr_get_codec_caps(struct snd_compr_stream *cstream,
codec->num_descriptors = 2;
#endif
codec->descriptor[0].max_ch = 2;
/* FIXME sample_rates in Hz */
codec->descriptor[0].sample_rates = SNDRV_PCM_RATE_8000_48000;
codec->descriptor[0].bit_rate[0] = 320; /* 320kbps */
codec->descriptor[0].bit_rate[1] = 128;
Expand All @@ -1907,6 +1882,7 @@ static int msm_compr_get_codec_caps(struct snd_compr_stream *cstream,
codec->num_descriptors = 2;
#endif
codec->descriptor[1].max_ch = 2;
/* FIXME sample_rates in Hz */
codec->descriptor[1].sample_rates = SNDRV_PCM_RATE_8000_48000;
codec->descriptor[1].bit_rate[0] = 320; /* 320kbps */
codec->descriptor[1].bit_rate[1] = 128;
Expand Down

0 comments on commit 2745769

Please sign in to comment.