一.概述
QNX音频类似于linux,采用节点的方式,open,read,write
二.查看节点类型
ls -l /dev/snd/
-rw-rw-rw- 1 root nto 0 Jan 01 00:07 controlC0 -rw-rw-rw- 1 root nto 0 Jan 01 00:55 controlC1 -rw-rw-rw- 1 root nto 0 Jan 01 00:55 controlC2 lrw-rw-rw- 1 root nto 0 Jan 01 00:55 defaultc -> pcmC0D0c lrw-rw-rw- 1 root nto 0 Jan 01 1970 defaultp -> pcmC0D1p -rw-rw-rw- 1 root nto 0 Jan 01 00:07 mixerC0D0 -rw-rw-rw- 1 root nto 0 Jan 01 00:55 mixerC1D0 -rw-rw-rw- 1 root nto 0 Jan 01 00:55 mixerC2D0 -rw-rw-rw- 1 root nto 0 Jan 01 00:07 pcmC0D0c -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC0D0p -rw-rw-rw- 1 root nto 0 Jan 01 00:07 pcmC0D1p -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC1D0c -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC1D0p -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC1D1p -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC2D0c -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC2D0p -rw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmC2D1p lrw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmNavigation -> pcmC2D1p lrw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmPreferredc -> pcmC0D0c lrw-rw-rw- 1 root nto 0 Jan 01 00:55 pcmPreferredp -> pcmC0D1p
三.sample code
<span style="white-space:pre"> </span>snd_pcm_channel_info_t info; snd_pcm_channel_params_t params; snd_pcm_channel_setup_t setup; snd_pcm_t *pcmHandle; ret = snd_pcm_open(&pcmHandle, card,device, input ? SND_PCM_OPEN_CAPTURE : SND_PCM_OPEN_PLAYBACK); if(ret == EOK) { printf("open success\n"); } else { printf("open fault\n"); } snd_pcm_plugin_set_disable( pcmHandle, PLUGIN_DISABLE_MMAP ); memset( &info, 0, sizeof( info ) ); info.channel = input ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK; snd_pcm_plugin_info( pcmHandle, &info ); memset( ¶ms, 0, sizeof( params ) ); params.channel = info.channel; params.mode = SND_PCM_MODE_BLOCK; if( bits == 8 ) { if( sign ) params.format.format = SND_PCM_SFMT_S8; else params.format.format = SND_PCM_SFMT_U8; } else if( bits == 16 ) { if( be && sign ) params.format.format = SND_PCM_SFMT_S16_BE; else if( be ) params.format.format = SND_PCM_SFMT_U16_BE; else if( sign ) params.format.format = SND_PCM_SFMT_S16_LE; else params.format.format = SND_PCM_SFMT_U16_LE; } else if( bits == 24 ) { if( be && sign ) params.format.format = SND_PCM_SFMT_S24_BE; else if( be ) params.format.format = SND_PCM_SFMT_U24_BE; else if( sign ) params.format.format = SND_PCM_SFMT_S24_LE; else params.format.format = SND_PCM_SFMT_U24_LE; } params.format.interleave = 1; params.format.rate = rate; params.format.voices = 1; params.start_mode = SND_PCM_START_FULL; params.stop_mode = SND_PCM_STOP_ROLLOVER; if (input) { params.buf.block.frag_size = params.format.rate * params.format.voices * sizeof(short) * 2 / 125; // Enforce 16ms frag size } else { params.buf.block.frag_size = info.max_fragment_size; } params.buf.block.frags_max = 2; params.buf.block.frags_min = 1; snd_pcm_plugin_params( pcmHandle, ¶ms ); snd_pcm_plugin_prepare( pcmHandle, info.channel ); memset( &setup, 0, sizeof( setup ) ); setup.channel = info.channel; snd_pcm_plugin_setup( pcmHandle, &setup );
snd_pcm_plugin_read( arg->pcmHandleIn1, arg->audioBufferOut, arg->audioMaxLenOut ); snd_pcm_plugin_write( arg->pcmHandleOut1, arg->audioBufferOut, arg->audioMaxLenOut);