I. Overview
QNX Audio is similar to Linux, with a node-like approach, open,read,write
Two. View node types
Ls-l/dev/snd/
Results:
-rw-rw-rw-1 root nto 0 Jan 00:07 controlc0-rw-rw-rw-1 root nto 0 Jan 01 00: Controlc1-rw-rw-rw-1 root nto 0 Jan 00:55 controlc2lrw-rw-rw-1 root nto 0 Jan 00:55 DEFAULTC-pcmc0d0clrw-rw-rw-1 root nto 0 Jan 1970 DEFAULTP -rw-rw-1 root nto 0 Jan 00:07 mixerc0d0-rw-rw-rw-1 root nto 0 Jan 01 00:55 Mixerc1d0-rw-rw-rw-1 root nto 0 Jan 00:55 mixerc2d0-rw-rw-rw-1 root nto 0 J An 00:07 pcmc0d0c-rw-rw-rw-1 root nto 0 Jan 00:55 pcmc0d0p-rw-rw-rw-1 root nto 0 Jan 00:07 pcmc0d1p-rw-rw-rw-1 root nto 0 Jan 00:55 pcmc1d0c-rw-rw-rw-1 root n to 0 Jan 00:55 pcmc1d0p-rw-rw-rw-1 root nto 0 Jan 00:55 pcmc1d1p-rw-rw-rw-1 r Oot nto 0 Jan 00:55 pcmc2d0c-rw-rw-rw-1 root nto 0 Jan 00:55 pcmc2d0p-rw-rw-rw-1 root nto 0 Jan 00:55 pcmc2d1plrw-rw-rw-1 root nto 0 Jan 00:55 Pcmnavigation-pcmc2d1p Lrw-rw-rw-1 root nto 0 Jan 00:55 pcmpreferredc pcmc0d0clrw-rw-rw-1 root nto 0 Jan 00:55 PCMPREFERREDP-pcmc0d1p
C End is capture, p end is playback, another c2d1 is card 2, device 1
Three. Sample code
<span style= "White-space:pre" ></span>snd_pcm_channel_info_tinfo;snd_pcm_channel_params_tparams;snd_ pcm_channel_setup_tsetup;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));p arams.channel= info.channel;params.mode= snd_pcm_mode_block;if (bits = = 8) {if (sign) Params.format.format = S Nd_pcm_sfmt_s8;elseparams.format.format = snd_pcm_sfmt_u8;} else if (bits = =) {if (is && sign) Params.format.format = Snd_pcm_sfmt_s16_be;else if (IS) Params.format.format = Snd_pcm_sfmt_u16_be;else if (sign) Params.format.format = Snd_pcm_sfmt_s16_le;elseparams.format.format = Snd_pcm_ sfmt_u16_lC;; else if (bits = =) {if (is && sign) Params.format.format = Snd_pcm_sfmt_s24_be;else if (IS) Params.format.format = Snd_pcm_sfmt_u24_be;else if (sign) Params.format.format = Snd_pcm_sfmt_s24_le;elseparams.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 ;p arams.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_frag Ment_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);
Perform a read or write action at the end
Snd_pcm_plugin_read (Arg->pcmhandlein1, Arg->audiobufferout, arg->audiomaxlenout); Snd_pcm_plugin_write ( ARG->PCMHANDLEOUT1, Arg->audiobufferout, arg->audiomaxlenout);
Examples of QNX audio applications