Github上有个简单的Alsa DSD测试程序,可以播放DSD,地址位于:https://github.com/zonque/alsa-dsd-player 细看其代码,发现有ALSA_FORMAT_SND_PCM_FORMAT_DSD_U8的定义,详情如下:
#if 1
/* 8-bit DSD */
#define ALSA_FORMAT SND_PCM_FORMAT_DSD_U8
#define SAMPLE_SIZE (sizeof(uint8_t) * 2)
#define SAMPLE_RATE_DIV 1
#else
/* 16-bit DSD */
#define ALSA_FORMAT SND_PCM_FORMAT_DSD_U16
#define SAMPLE_SIZE (sizeof(uint16_t) * 2)
#define SAMPLE_RATE_DIV 2
#endif
那么在Android中能运行这个测试程序吗?ALSA_FORMAT_SND_PCM_FORMAT_DSD_U8似乎是亮点,之前没有看到过。尝试在Android的源码中寻找它的定义,没找到。但是在标准的alsa-lib中找到了:
typedef enum _snd_pcm_format {
SND_PCM_FORMAT_UNKNOWN = -,
SND_PCM_FORMAT_S8 = ,
SND_PCM_FORMAT_U8,
SND_PCM_FORMAT_S16_LE,
SND_PCM_FORMAT_S16_BE,
SND_PCM_FORMAT_U16_LE,
SND_PCM_FORMAT_U16_BE,
SND_PCM_FORMAT_S24_LE,
SND_PCM_FORMAT_S24_BE,
SND_PCM_FORMAT_U24_LE,
SND_PCM_FORMAT_U24_BE,
SND_PCM_FORMAT_S32_LE,
SND_PCM_FORMAT_S32_BE,
SND_PCM_FORMAT_U32_LE,
SND_PCM_FORMAT_U32_BE,
SND_PCM_FORMAT_FLOAT_LE,
SND_PCM_FORMAT_FLOAT_BE,
SND_PCM_FORMAT_FLOAT64_LE,
SND_PCM_FORMAT_FLOAT64_BE,
SND_PCM_FORMAT_IEC958_SUBFRAME_LE,
SND_PCM_FORMAT_IEC958_SUBFRAME_BE,
SND_PCM_FORMAT_MU_LAW,
SND_PCM_FORMAT_A_LAW,
SND_PCM_FORMAT_IMA_ADPCM,
SND_PCM_FORMAT_MPEG,
SND_PCM_FORMAT_GSM,
SND_PCM_FORMAT_SPECIAL = ,
SND_PCM_FORMAT_S24_3LE = ,
SND_PCM_FORMAT_S24_3BE,
SND_PCM_FORMAT_U24_3LE,
SND_PCM_FORMAT_U24_3BE,
SND_PCM_FORMAT_S20_3LE,
SND_PCM_FORMAT_S20_3BE,
SND_PCM_FORMAT_U20_3LE,
SND_PCM_FORMAT_U20_3BE,
SND_PCM_FORMAT_S18_3LE,
SND_PCM_FORMAT_S18_3BE,
SND_PCM_FORMAT_U18_3LE,
SND_PCM_FORMAT_U18_3BE,
/* G.723 (ADPCM) 24 kbit/s, 8 samples in 3 bytes */
SND_PCM_FORMAT_G723_24,
/* G.723 (ADPCM) 24 kbit/s, 1 sample in 1 byte */
SND_PCM_FORMAT_G723_24_1B,
/* G.723 (ADPCM) 40 kbit/s, 8 samples in 3 bytes */
SND_PCM_FORMAT_G723_40,
/* G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte */
SND_PCM_FORMAT_G723_40_1B,
/* Direct Stream Digital (DSD) in 1-byte samples (x8) */
SND_PCM_FORMAT_DSD_U8,
/* Direct Stream Digital (DSD) in 2-byte samples (x16) */
SND_PCM_FORMAT_DSD_U16_LE,
SND_PCM_FORMAT_LAST = SND_PCM_FORMAT_DSD_U16_LE, #if __BYTE_ORDER == __LITTLE_ENDIAN SND_PCM_FORMAT_S16 = SND_PCM_FORMAT_S16_LE,
SND_PCM_FORMAT_U16 = SND_PCM_FORMAT_U16_LE,
SND_PCM_FORMAT_S24 = SND_PCM_FORMAT_S24_LE,
SND_PCM_FORMAT_U24 = SND_PCM_FORMAT_U24_LE,
SND_PCM_FORMAT_S32 = SND_PCM_FORMAT_S32_LE,
SND_PCM_FORMAT_U32 = SND_PCM_FORMAT_U32_LE,
SND_PCM_FORMAT_FLOAT = SND_PCM_FORMAT_FLOAT_LE,
SND_PCM_FORMAT_FLOAT64 = SND_PCM_FORMAT_FLOAT64_LE,
SND_PCM_FORMAT_IEC958_SUBFRAME = SND_PCM_FORMAT_IEC958_SUBFRAME_LE
#elif __BYTE_ORDER == __BIG_ENDIAN SND_PCM_FORMAT_S16 = SND_PCM_FORMAT_S16_BE,
SND_PCM_FORMAT_U16 = SND_PCM_FORMAT_U16_BE,
SND_PCM_FORMAT_S24 = SND_PCM_FORMAT_S24_BE,
SND_PCM_FORMAT_U24 = SND_PCM_FORMAT_U24_BE,
SND_PCM_FORMAT_S32 = SND_PCM_FORMAT_S32_BE,
SND_PCM_FORMAT_U32 = SND_PCM_FORMAT_U32_BE,
SND_PCM_FORMAT_FLOAT = SND_PCM_FORMAT_FLOAT_BE,
SND_PCM_FORMAT_FLOAT64 = SND_PCM_FORMAT_FLOAT64_BE,
SND_PCM_FORMAT_IEC958_SUBFRAME = SND_PCM_FORMAT_IEC958_SUBFRAME_BE
#else
#error "Unknown endian"
#endif
} snd_pcm_format_t;
暂时还不知具体是怎么工作的,是透传DSD数据到硬件?还是alsa-lib中先转换为标准的PCM? 但在Android的alsa-lib中,确实是没有SND_PCM_FORMAT_DSD的定义,应该是被精简掉了。因此只能考虑采用DSD->PCM转换成24bit 176K后,再按照标准的PCM方式来播放。