2016/5/11

ALSA driver, add support 24000Hz Sample Rate..

include/uapi/sound/asound.h
#define SNDRV_MASK_MAX  256

struct snd_mask {
        __u32 bits[(SNDRV_MASK_MAX+31)/32];
};


tinypcminfo : 會列出 sound card 的 property (rules), 例如:
root@sabreauto_6q:/ # tinypcminfo -D 0                                         
Info for card 0, device 0:

PCM out:
      Access: 0x000009
   Format[0]: 0x000045
   Format[1]: 00000000
 Format Name: S8, S16_LE, S24_LE
   Subformat: 0x000001
        Rate: min=48000Hz max=192000Hz
    Channels: min=1  max=12
 Sample bits: min=8  max=32
 Period size: min=3  max=65535
Period count: min=2  max=255

PCM in:
      Access: 0x000009
   Format[0]: 0x000045
   Format[1]: 00000000
 Format Name: S8, S16_LE, S24_LE
   Subformat: 0x000001
        Rate: min=48000Hz max=192000Hz
    Channels: min=1  max=8
 Sample bits: min=8  max=32
 Period size: min=4  max=65535
Period count: min=2  max=255


然後看到 fsl_esai.c 李有..
#define FSL_ESAI_RATES          SNDRV_PCM_RATE_8000_192000
...
...
        .probe = fsl_esai_dai_probe,
        .playback = {
                .stream_name = "esai-Playback",
                .channels_min = 1,
                .channels_max = 12,
                .rates = FSL_ESAI_RATES,
                .formats = FSL_ESAI_FORMATS,
        },
        .capture = {
                .stream_name = "esai-Capture",
                .channels_min = 1,
                .channels_max = 8,
                .rates = FSL_ESAI_RATES,
                .formats = FSL_ESAI_FORMATS,
        },
        .ops = &fsl_esai_dai_ops,
};


找一下這個..
include/sound/pcm.h:

/* If you change this don't forget to change rates[] table in pcm_native.c */
#define SNDRV_PCM_RATE_5512             (1<<0)          /* 5512Hz */
#define SNDRV_PCM_RATE_8000             (1<<1)          /* 8000Hz */
#define SNDRV_PCM_RATE_11025            (1<<2)          /* 11025Hz */
#define SNDRV_PCM_RATE_16000            (1<<3)          /* 16000Hz */
#define SNDRV_PCM_RATE_22050            (1<<4)          /* 22050Hz */
#define SNDRV_PCM_RATE_32000            (1<<5)          /* 32000Hz */
#define SNDRV_PCM_RATE_44100            (1<<6)          /* 44100Hz */
#define SNDRV_PCM_RATE_48000            (1<<7)          /* 48000Hz */
#define SNDRV_PCM_RATE_64000            (1<<8)          /* 64000Hz */
#define SNDRV_PCM_RATE_88200            (1<<9)          /* 88200Hz */
#define SNDRV_PCM_RATE_96000            (1<<10)         /* 96000Hz */
#define SNDRV_PCM_RATE_176400           (1<<11)         /* 176400Hz */
#define SNDRV_PCM_RATE_192000           (1<<12)         /* 192000Hz */

#define SNDRV_PCM_RATE_CONTINUOUS       (1<<30)         /* continuous range */
#define SNDRV_PCM_RATE_KNOT             (1<<31)         /* supports more non-continuos rates */

#define SNDRV_PCM_RATE_8000_44100       (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
                                         SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
                                         SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100)
#define SNDRV_PCM_RATE_8000_48000       (SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000)
#define SNDRV_PCM_RATE_8000_96000       (SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\
                                         SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000)
#define SNDRV_PCM_RATE_8000_192000      (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\

裡面沒有 24000....

又,有 comment..." If you change this don't forget to change rates[] table in pcm_native.c "
大概是可以自己修改的意思,所以,...插入一個 24000

然後去看看 pcm_native.c..
也有對應的 code, 和檢查,所以照著修改...
#if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 13
#error "Change this table"
#endif

static unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 24000, 32000, 44100,
                                 48000, 64000, 88200, 96000, 176400, 192000 };
這樣 build 完就可以 support 2400 了...


alsa driver 決定 sound card 的 sample rate range 是由一堆rules 取交集,
這些 rule 可能是 i2s, sound card, hardwae, software driver..
最後 pcm_native.c 會把所有的 rule 做交集取出有效的 range.

沒有留言:

張貼留言