sn986系列音频编解码器编程指南_第1页
sn986系列音频编解码器编程指南_第2页
sn986系列音频编解码器编程指南_第3页
sn986系列音频编解码器编程指南_第4页
sn986系列音频编解码器编程指南_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Overview

SDKArchitecture

Features:

Audiocodecformats:

Hardwareaudiocodec

MS-ADPCM

A-LAW

Softwareaudiocodec

A-LAW

Mu-LAW

G.722

G.726

AudioCodecsamplerate

8/16/24/32/44.1/48Kbps

SN986SeriesSDK ludesaudiocodecdriverandudiomiddleware.

Interface

ALSA-Lib

Plug-in

ALSA-CORE

ALSADeviceDriver(AudioContro Drier)

SIGDriver

R2RDriver

I2S viceDriver

Figure01.AudioCodecSoftwarStack

AudioCodecDriver

AudioCodecDiverarebasedonAdvancedLinuxSoundArchitecture(ALSA).AudioCodecdriver luesaudiocontrollerdriver,Sigma-DeltaADCdriver,R2RDACdriver,AIC23driverandtw286 driver.

1. AdioMiddleware

AudioMiddleware ludesALSAlibrary,softwareaudiocodec(A-LAW,Mu-LAW,G.722,G.726)plugin,sonixaudiolibraryandaudiotesttools。

AudioCodecDriver

AudioCodecDriver

AudioCodecDriverludesaudiocontrollerdriverandAD/DAcodecsub-moduledivers.Inaddition,therearetwokindsofAD/DAcodecsub-moduledriver,whichisintnalcodecdriverandexternalcodecdriver.

Theaudiocontrollerdriverisma odecdriver,controlsI2S,digitaladustfunction,DDRbufferandallhardwarefunctioninaudiocontrollerhardware.

TheinternalAD/DAcodecsub-moduledrivercontrolsinternalcoec,whichisinsideSN986seriesIC.ThereareSigma-DeltaADCdriverandR2RDACdrivrforinternalcodec.

Additionally,theyareaplug-in,hooktoaudiocontrollerdiverandco-workwithit.

TheexternalAD/DAcodecsub-moduledrivercontrol ternalcodec,whichi ternalAD/DAICconnecttoSN986seriesICbyI2Sforaudodatatransfer,andothercontrolsignal(ex:I2CorSPI)forcontrolsettings.Currently,wesuportTITLV320AIC23codecdriverandTECHWELLTW2866codecdriver,andtheyaebothADCandDACdriver.

AudioCodecDriverUsageDescriptions

AudioCodecDriverludesaudiocontrolerdriverandAD/DAcodecsub-moduledrivers.Audiocontrollerdriverismaodedriver,andthismodulemustbeinsertedfirstlybeforeothercodecsub-modules.

TheAD/DAcodecsub-mod drivers ludeADorDAcodecsub-moduledriver,orbothinonemodule.SN986seriessupportonechannelandmonomodeaudioonbothADandDApath.Astheresult,onlyonADcodecsub-moduledriverandoneDAcodecsub-moduledrivercanbehookedorplug-in.

Thefollowing reusages:

Audioontrollerdriver:

ins odsnx_aud_core.ko[audio_cap=capability]

caabilitybit0standsforyornot,bit1standsforrecordornot,anddefaultis3bit0|bit1)

InternalSIGADCcodecsub-moduledriver:

insmodsnx_aud_sigma.ko[mic_in=enable]

enable1standsforenablemicrophone(differential)insignal,0standsforsinglendsignal

InternalR2RDACcodecsub-moduledriver:insmodsnx_aud_r2r.ko

ExternalTITLV320AIC23codecsub-moduledriver:snx_aud_aic23.ko[audio_cap=capability]

capabilitybit0standsforyornot,bit1standsforrecordrot,anddefaultis3(bit0|bit1)

ExternalTechwellTW2866codecsub-moduledriver:snx_aud_aic23.ko[audio_cap=capability]

capabilitybit0standsforyornot,bit1standsf recordornot,anddefaultis3(bit0|bit1)

AudioMiddleware

ALSALibrary

ALSALibraryIntroduction

TheALSALibrarycontainstheuserspacelibrarythatdeveloperscompileASAapplications

.

ApplicationprogrammersshouldusethelibraryAPIratherthanthekernelAI.ThelibraryoffersthefullfunctionalityofthekernelAPIandaddsmajorimprovem sinusabilitymakingtheapplicationcodesimplerandbetterlooking.Inaddition,futurefix orcompatibilitycodemaybecedinthelibrarycodeinsteadofthekerneldriver.

ALSALibraryCommonAPI

ThedetaileddescriptionofALSALibraryAPIs,pleaserefero“ALSAproject-theClibraryreference”.

ThedescriptionofALSAlibrarycommonAPIs:

FunctionName Descriptions

int snd_pcm_open(snd_pcm_t**pcm,constchar

*name,snd_pcm_stream_tstream,intmode)

OpensaPCM

int snd_pcm_close(snd_pcm_t*pcm) ClosePCMhandle

snd_pcm_hw_params_alloca Allocateaninvalidsnd_pcm_hw_params_tusingstandardalloca.

int snd_pcm_hw_params_any(snd_pm_t*pcm,snd_pcm_hw_params_t*params)

int snd_pcm_hw_params_setaccess(snd_pcm_t

*pcm,snd_pcm_hw_param_*params,snd_pcm_access_t_acess)

int snd_pcm_formawidh(snd_pcm_format_tformat)

int snd_pcmh rams_set_format(snd_pcm_t

*pcm,snd cm_w_params_t*params,snd_pcmformt_tval)

int s pcm_hw_params_set_channels

(snd_cm_t*pcm,snd_pcm_hw_params_t*params,u ignedintval)

FillparamswithafullconfigurationspaceforaPCM.

Restrictaconfigurationspacetocontainonlyoneaccesstype.

ReturnnominalbitsperaPCMsample.

Restrictaconfigurationspacetocontainonlyoneformat.

Restrictaconfigurationspacetocontainonlyonechannelscount.

int snd_pcm_hw_params_set_rate(snd_pcm_t

*pcm,snd_pcm_hw_params_t*params,unsignedintval,intdir)

int snd_pcm_hw_params_set_period_size(snd_pcm_t*pcm,snd_pcm_hw_params_t*params,snd_pcm_uframes_tval,intdir)

int snd_pcm_hw_params(snd_pcm_t*pcm,snd_pcm_hw_params_t*params)

snd_pcm_sframes_tsnd_pcm_readi(snd_pcm_t

*pcm,void*buffer,snd_pcm_uframes_tsize)

Restrictaconfigurationspacetocontainonlyonerate.

Restrictaconfigurationspacetocontainolyoneperiodsize.

InstallonePCMhardwareconfiguratnchosenfromaconfigurationspaceandsd_pcm_prepareit.

Readinterleavedfram omaPCM.

int snd_pcm_prepare(snd_pcm_t*pcm) PreparePCMforus

int snd_pcm_wait(snd_pcm_t*pcm,inttimeout) WaitforaPCMobcomeready.

int snd_pcm_drain(snd_pcm_t*pcm) StopaPCMpeservingpendingframes.int snd_pcm_start(snd_pcm_t*pcm) StartaPCM.

int snd_pcm_drop(snd_pcm_t*pcm)

StopaPCMdrop

pendingframes.

int snd_pcm_pause(snd_pcm_t*pcm,intenable) PauseesumePCM.

snd_pcm_sframes_tsnd_pcm_writei(snd_pcm_t

*pcm,constvoid*buffer,snd_pcm_uframes_tsize)snd_pcm_sframes_tsnd_pcm_readi(snd_pcm_t

*pcm,void*buffer,snd_pcm_uframes_tsize)

constchar*snd_pcm_stream_name(constsnd_pcm_stream_tstream)

constchar*snd_pcm_access_namecontsnd_pcm_access_t_access)

constchar*snd_pcm_format_nam(constsnd_pcm_format_tformat)

constchar*snd_pcm_fomadescription(constsnd_pcm_format_tfo at)

constchar*snd_pmsbformat_description(constsnd_pcm_subformat_tsubformat)

WrteinterleavedframestoaPCM.

ReadinterleavedframesfromaPCM.

GetnameofPCMstreamtype

GetnameofPCMaccesstype

GetnameofPCMsampleformat

GetdescriptionofPCMsampleformat

GetdescriptionofPCMsamplesubformat

constchar* error(interrnum) Returnsthemessageforanerrorcode.

Table01.ALALibaryCommonAPIDescriptions

ALSALibraryUsageDescriptions

3.31 Generaloverview

ALSAusestheringbuffertostoreoutgoing(yback)and oming(capture,record)samples.Therearetwopointersbeingmaintainedtoallowaprecisecommunicationbetweenapplicationanddevicepointingtocurrentprocessedsamplebyhardwareandlastprocesedsamplebyapplication.Themodernaudiochipsareallowedtobeprogrammedthetransfertimeperiods.Itmeansthatthestreamofsamplesisdividedtosmallchunks.Devieacknowledgestoapplicationwhenthetransferofachunkiscomplete.

PCMnamingconventions

TheALSAlibraryusesagenericstringrepresentationfornamesofdevices.Thedevicesmightbevirtual,physicaloramixofboth.Thegenericstringispassedtosnd_pcm_open().Itcontainstwoparts:devicenameandarguments.Devicesandarumentsaredescribedinconfigurationfiles.Theusualcefordefauefinitionsisatur/share/alsa/alsa.conf.

About/usr/share/alsa/alsa.conffilesyntax,seeConfiguraionfes

Blockedandnon-blockedopen

TheALSAPCMAPIusesadifferentbehaviourwhenthedeviceisopenedwithblockedornon-blockedmode.Themodecanbespecifiedwihmodeargumentinsnd_pcm_open()function.Theblockedmodeisthedefault(wihoutSND_PCM_NONBLOCKmode).Inthismode,thebehaviouristhatiftheresourcehavealreadyusedwithanotherapplication,thenitblocksthecaller,untilresourcesareThenon-blockedbehaviour(withSND_PCM_NONBLOCK)doesn'tblokthecallerinanywayandreturns-EBUSYerrorwhentheresourcesarenotavailable.No thatthemodealsodeterminesthebehaviourofstandardI/Ocalls,returning-EAGAINwhennon-blockedmodeisusedandtheringbufferisfull(yback)orempty(capt e).

Example:

intrc;

snd_pcm_t*hanle

rc=snd_pm_open(&handle,"hw:0,0",SND_PCM_STREAM_CAPTURE,SND_PCM_NONBLOCK);if(rc<0)

{

fintf(stderr,"unabletoope mdevice:%s\n",snd_strerror(rc));exit(1);

}

Setuptheparamsofdevice

TheALSAPCMdeviceusestwogroupsofPCMrelatedparameters.Thehardwareparameterscontainsthestreamdescriptionlikeformat,rate,countofchannels,ringbffersizeetc.Thesoftwareparameterscontainsthesoftware(driver)relatedparametes. hecommunicationbehaviourcanbecontrolledviatheseparameters,likeautomaticstart,automaticstop,interrupting(chunkacknowledge)etc.Thesoftwareparamerscanbemodifiedatanytime(whenvalidhardwareparametersareset).It ludestherunningstateaswell.

Hardwarerelatedparameters

TheALSAPCMdevicesusetheparameterrefiningsystemforhardwareparameters-snd_pcm_hw_params_t.Itmeans,thatapplicationchoosetheful-rangeofconfigurationsatfirstandthenapplicationsetssingleparametersuntilallaametersareelementary(definite).

Accessmodes

ALSAknowsaboutfiveaccessmodes.Thefirstthreeanbeusedfordirectcommunication.

SND_PCM_ACCESS_MMAP_INTERLEAVEDdeterminesthedirectmemoryareaandinterleavedsampleorganization.Interleavedrganizationmeans,thatsamplesfromchannelsaremixedtogether.

SND_PCM_ACCESS_MMAP_NONINERLEAVEDdeterminesthedirectmemoryareaandnon-interleavedsampleorganizatin.Eachchannelhasaseparatebufferinthecase.

SND_PCM_ACCESS_MMAP_OMPLEXrepresentsthecomplexdirectmemoryorganization.Thesampleoganizationdoesnotfittheinterleavedornon-interleavedaccessmodesinthecase.

Thelasttwoaccesmodesdescribetheread/writeaccessmethods.TheSND_PCM_ACCESS_RW_INTERLEAVEDrepresentstheread/writeinterleavedaccess,andtheSND CM_ACCESS_RW_NONINTERLEAVEDrepresentsthenon-interleavedaccess.

Form s

Thfulllistofformatsisavailableinsnd_pcm_format_tenumeration.

Example:

snd_pcm_hw_params_t*params

/*Allocateahardwareparametersobject.*/snd_pcm_hw_params_alloca(¶ms);

/*Fillitinwithdefaultvalues.*/snd_pcm_hw_params_any(handle,params);

/*Setthedesiredhardwareparameters.*/

/*Interleavedmode*/

snd_pcm_hw_params_set_access(handle,params,SND_PCM_ACCESS_RW_INTERLEAVED);

/*SND_PCM_FORMAT_S16Format*/snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORAT_S16);

/*onechannel(mono)*/snd_pcm_hw_params_set_channels(handle,params,1);

/*8KHzsamplingrate*/snd_pcm_hw_params_set_rate(handle,params,8000,0);

/*Writetheparameterstothedriver*/

rc=snd_pcm_hw_params(handle,params)if(rc<0)

{

fprintf(stderr,"unabletoset parameters:%s\n",snd_strerror(rc));exit(1);

}

Softwarerelatedparameters

Theseparmeters-snd_pcm_sw_params_tcanbemodifiedatanytime ludingtherunningstte.

Mnimmavailablecountofsamples

Thiparametercontrolsthewakeuppoint.Ifthecountofavailablesamplesisequalorgreater

thanthisvalue,theapplicationwillbeactivated.

Timestampmode

Thetimestampmodespecifies,iftimestampsareactivated.Currently,onlySND_PCM_TSTAMP_NONEandSND_PCM_TSTAMP_MMAPmodesareknownThemmapmodemeansthattimestampistakenoneveryperiodtimeboundary.Correspondingpositionintheringbufferassignedtotimestampcanbeobtainedusingsnd_pcm_htimestamp()function.

Transferalign

Theread/writetransferscanbealignedtothissamplecount.Themoduloisignoredbydevice.Usually,thisvalueissettoone(noalign).

Startthreshold

Thestartthresholdparameterisusedtodeterm hest tpointinstream.Foryback,ifsamplesinringbufferisequalorgreaterthanthestartthresholdparametersandthestreamisnotrunning,thestreamwillbestartedautomaticllyfromthedevice.Forcapture,iftheapplicationwantstoreadcountofsamplesequalogreaterthenthestreamwillbestarted.Ifyouwanttouseexplicitstart(snd_pcm_start),youcansetthisvaluegreaterthanringbuffersize(insamples),butusetheconstantMAXINTisnotabadidea.

Stopthreshold

Similarly,thestopthresholdparameteisusedtoautomaticallystoptherunningstream,whentheavailablesamplescrossesthis undary.Itmeans,foryback,theemptysamplesinringbufferandforcapture,thefille(used)samplesinringbuffer.

Silencethreshold

Thesilencethresholdspecifescountofsamplesfilledwithsilenceaheadofthecurrentapplicationpointerforpayack.Itisusableforapplicationswhenanoverrunispossible(liketasksdependingo workI/Oetc.).Ifapplicationwantstomanagetheaheadsamplesitself,thesnd_pcm_rewind()functionallowstoforgetthelastsamplesinthestream.

Example:

interr;

/*getthecu nts rams*/

err=snd_cm_sw_params_current(handle,s rams);iferr<)

{

printf("Unabletodeterminecurrentsramsforyback:%s\n",snd_strerror(err));returnerr;

}

/*startthetransferwhenthebufferisalmostfull:*/

/*(buffer_size/avail_min)*avail_min*/

err=snd_pcm_sw_params_set_start_threshold(handle,srams,(buffer_size/period_size)period_size);if(err<0)

{

printf("Unabletosetstartthresholdmodeforyback:%s\n",snd_strerro r);returnerr;

}

/*allowthetransferwhenatleastperiod_sizesamplescanbeprocesed

/*ordisablethismechanismwhenperiodeventisenabled(akainterptlikestyleprocessing)*/ err=snd_pcm_sw_params_set_avail_min(handle,srams,period_event?buffer_size:period_size);

if(err<0)

{

printf("Unabletosetavailminforyback:%s\n,snd_trerror(err));returnerr;

}

/*enableperiodeventswhenrequested*/if(period_event)

{

err=snd_pcm_sw_params_s period_event(handle,s rams,1);if(err<0)

{

printf("Unabletoetperiodevent:%s\n",snd_strerror(err));returnerr;

}

}

/*writetheparamerstotheybackdevice*/err=snd_pcsw_params(handle,srams);if(err<0)

{

prtf("Unabletosets ramsforyback:%s\n",snd_strerror(err));turnerr;

}

Handshak weenapplicationandlibrary

TheALSAPCMAPIdesignusesthestatestodeterm hecommunicationphasbtweenapplicationandlibrary.Theactualstatecanbedeterminedusingsnd_pcm_sate()call.Therearethesestates:

SND_PCM_STATE_OPEN

ThePCMdeviceisintheopenstate.Afterthesnd_pcm_open()opnall,thedeviceisinthisstate.Also,whensnd_pcm_hw_params()callfails,thenthisstateisenteredtoapplicationcallingsnd_pcm_hw_params()functiontosetrightcmmunicationparameters.

SND_PCM_STATE_SETUP

ThePCMdevicehasacceptedcommunicationparamete anditiswaitingforsnd_pcm_prepare()calltopreparethehardwareforselectedoperation(ybackorcapture).

SND_PCM_STATE_PREPARED

ThePCMdeviceispreparedforoperation.Applicationcanusesnd_pcm_start()call,writeorreaddatatostarttheoperation.

SND_PCM_STATE_RUNNING

ThePCMdevicehasbeenstartedandisunning.Itprocessesthesamples.Thestreamcanbestoppedusingthesnd_pcm_dro()orsnd_pcm_drain()calls.

SND_PCM_STATE_XRUN

ThePCMdevicereachedovrrun(capture)orunderrun(yback).Youcanusethe-EPIPEreturncodefromI/Ofunctios(snd_pcm_writei(),snd_pcm_writen(),snd_pcm_readi(),snd_pcm_readn())todterm hisstatewithoutcheckingtheactualstateviasnd_pcm_state()call.Itisrecommendedtousethehelperfunctionsnd_pcm_recover()torecoverfromthisstte,butyouc sousesnd_pcm_prepare(),snd_pcm_drop()orsnd_pcm_dran()calls.

SND_PCMSTATE_DRAINING

Thedevic isinthisstatewhenapplicationusingthecapturemodecalledsnd_pcm_drain()functionUntilalldataarereadfromtheinternalringbufferusingI/Oroutines

(snd_pm_readi(),snd_pcm_readn()),thenthedevicestaysinthisstate.

Managingthestreamstate

Thefollowingfunctionsdirectlyandindirectlyaffectthestreamstate:

snd_pcm_hw_params

Thesnd_pcm_hw_params()functionbringsthestreamstatetoSND_PCM_STATE_SETUPifsuccessfullyfinishes,otherwisethestateSND_PCM_STATE_OPENisenteed.WhenitisbroughttoSETUPstate,thisfunctionautomaticallycallssnd_pcm_prepare()functiontobringtothePREPAREDstateasbelow.

snd_pcm_prepare

Thesnd_pcm_prepare()functionentersfromSND_PCM_STATE_SETUPtotheSND_PCM_STATE_PREPAREDafsuccessfulfinish.

snd_pcm_start

Thesnd_pcm_start()functionenterstheSND_PCM_STATE_RUNNINGaf successfulfinish.

snd_pcm_drop

Thesnd_pcm_drop()functionenterstheSND_PCM_STATE_SETUPstate.

snd_pcm_drain

Thesnd_pcm_drain()functionentersthSND_PCM_STATE_DRAINING,ifthecapturedevicehassomesamplesintheringbfferotherwiseSND_PCM_STATE_SETUPstateisentered.

snd_pcm_pause

Thesnd_pcm_pause()funcionenterstheSND_PCM_STATE_PAUSEDorSND_PCM_STATE_RUNNING.

snd_pcm_writei,ndpcm_writen

Thesnd_pcm_writei()andsnd_pcm_writen()functionscanconditionallystartthestream-SND_PCM_SATE_RUNNING.Theydependonthestartthresholdsoftwareparameter.

snd_pcmredi,snd_pcm_readn

Thes _pcm_readi()andsnd_pcm_readn()functionscanconditionallystartthestream-SNDPCM_STATE_RUNNING.Theydependonthestartthresholdsoftwareparameter.

Forthedetailusage,pleaserefertoapp/example/src/audio/ac/snx_audio_codec.c

SoftwareAudioCodecPlugin

WecurrentlysupportA-LAW,Mu-LAW,G.722andG.726softwareaudiocodec.

Themaindifferencweenhardwareaudiocodecandsoftwareaudiocodecisdevicename.Callsnd_pcm_open()functionwithdifferentdevicenameparametecnusethecorrespondingsoftwareaudiocodec.

DeviceName Descriptions

hw:0 Hardwareaudiocodec(PCM,MS-ADPCM,A-LAW)

snx_audio_alaw SoftwareA-LAWcodec

snx_audio_mulaw SoftwareMu-LAWcodec

snx_audio_g722 SoftwareG.722codec

snx_audio_g726 SoftwareG.726codec

Table02.DeviceNameDescriptions

SonixAudioLibrary

SonixAudioLibrarycurrentlyonlyprovidescontrlthevolumeofmicrophonesandspeaker.It’sbasedontheALSALibrary.

FunctionName Descriptions

HerearethedescriptionoixAudioLibraryAPI.

intsnx_audio_mic_vol_get_items(intcadnum,int*items)Gettheitemsofmicrophonevolume

adjustment.

intsnx_audio_mic_vol_set(intcadnum,intvol) Setthevolumeofmicrophone.intsnx_audio_mic_vol_get(intcd_num,int*vol) Getthevolumeofmicrophone.intsnx_audio_mic_vol_setmue(intcard_num,intmute) Setthemicrophonemute.

intsnx_audio_mic_v_getmute(intcard_num,int*mute)Determinewhetherthemicrophone

ismute.

intsnx_audio_sk_vol_get_items(intcard_num,int*items)Gettheitemsofspeakervolume

adjustment.

intsnx_audispk_vol_set(intcard_num,intvol) Setthevolumeofspeaker.intsnxau_spk_vol_get(intcard_num,int*vol) Getthevolumeofspeaker.intsnx_dio_spk_vol_set_mute(intcard_num,intmute) Setthespeakermute.

itsnxaudio_spk_vol_get_mute(intcard_num,int*mute)Determinewhetherthespeakerismute.

Table03.SonixAudiolibraryAPIDescri

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论