18.4.3Configuring
SetThreadInvokingtrueifyouwantAudioInputinstancetosynchronizeitseventstothemainUI threadautomaticallybutmakesurethatAudioInputinstancehasavalidparentcontrol.ThreadInvokingis falsebydefaultsodonotforgettocallControl.Invokemethodif youupdateGUI inyourDataGeneratedeventhandler.
If youwantto useotherWindows’recordingdevicethanthedefaultone,setRecordingDeviceproperty.YoucangetallavailablerecordingdevicesbyusingAudioInput’sstaticmethodGetRecordingDevices.
VolumecanbecontrolledthroughVolumeproperty.Validvaluesarefrom0to100where0meansmuteand100maximumvolume.YoucansetvolumealsowhenAudioInputinstanceisenabled(i.e.generatingsamples).
If youwanttousedifferencesamplingratethanthedefault(44100Hz)thensetSamplesPerSecond
property.SettingthispropertywhileAudioInputinstanceisenabledhas noeffect.
Tousemonoaudioinsteadofstereo(default),setIsStereotofalse.Settingthispropertywhile
AudioInputinstanceisenabledhas noeffect.
If youprefer8bitsper sampleratherthan16(default),setBitsPerSampleproperty8.Validvaluesare 8and16(default).ThislimitationcomesfromPCMwaveformat.SettingthispropertywhileAudioInputinstanceisenabledhas noeffect.
18.4.4Starting
TostartAudioInputinstanceyoucaneithersetIsInputEnabledpropertytrueorbycallingStartmethod.WhenDataGeneratedeventprovidesyouwitha newsetofaudiosamplesyoucane.g.renderthemusingLightningChartUltimateinstance.
When youwant tostopAudioInputinstance,setIsInputEnabledfalseorcallRequestStopmethod.RequestStopmethoddoesnotstopinstantly.ItjustsignalsAudioInputinstancetostopassoon asitis possible.Ifyouneedto waituntileverythinghas beenstoppedthen waitforStoppedeventtogettriggered.Youneedtohavesubscribedtoit.
18.5Usage(WPF)
This chapterdescribestheusageofWPFversionofAudioInputclass.WPFversionofAudioInputworksbasicallythesamewayasWinFormsversion.However,therearea coupleofthingsthataWPFuser is goodto knowandthesethingsaredescribedinthischapter.
18.5.1Creation
CreateanewAudioInputinstanceeithermanuallyincode-behindorbydragginganddroppingit
fromVisualStudio’stoolboxonto yourwindow,usercontroletc.
If youdonotneedtoshowGUI (i.e.youuseyourownoryoucontrolAudioInputobjectfromyoursourcecode)thenuse AudioInputfromArction.WPF.SignalToolsnamespace.This particularclassis derivedfromFrameworkElementandall itspropertiesarebindable.Foryourconvenience,after
youhaveinstalledLightningChartUltimateSDK,Arction.WPF.SignalTools.AudioInputcanalsobe foundfromVisualStudio’stoolboxso youcandropitonyourwindows,usercontroletc.andthen movetheelementwhereveryouneeditinyourXAMLcode.NecessaryXMLnamespacewillbeaddedautomaticallythisway.
Thereisalsoaready-madeGUI forAudioInput.ItcanbefoundfromArction.WPF.SignalTools.GUInamespace.YoucanfinditalsofromVisualStudio’stoolboxafteryouhaveinstalledLightningChartUltimateSDK.Notethatthisisjusta GUI forArction.WPF.SignalTools.AudioInputclassbutit containsaninstanceofArction.WPF.SignalTools.AudioInputclassandyoucanaccessitthroughInputproperty.I.e.youdonothaveto createanewseparateArction.WPF.SignalTools.AudioInputinstance.
It isrecommendedto setLicenseKeypropertyso thatyourAudioInputinstanceusesanexplicitlicensekeyinsteadoftryingtofindonefromWindows’registry.Note,ifyouareusingatrial version/licensethenyoucanleaveLicenseKeypropertytoitsdefaultvalue.
19.AudioOutputcomponent
AudioOutputcomponentallowsusertoconvertSystem.Doublesignaldataintoanaudiostreamwhichis then playedbackthroughspeakers,orsenttoLine-outconnectorofsounddevice.
19.1Properties
Balance–Getsorsetsaudioplaybackbalance.Validvaluesare between-100to100.-100means thataudioisplayedonlythroughtheleftspeaker.0meansthatbothspeakersoutputaudio.100means that audioisplayedonlythroughtherightspeaker.
BitsPerSample–Getsorsetshowmanybitsareallocatedper sample.Supportedvaluesare8and16.If othervalueisused,16isusedinstead.IssettablewhenIsOutputEnabledisfalse.
IsOutputEnabled–Getsorsetsthe stateofthisinstance(i.e.startsorstopsit).Settingthispropertytrue isthe sameascallingStartmethodwherefalseisthe sameas callingStopmethod.
IsStereo–Getsorsetswhethertousetwochannels(stereo)orjustone(mono).Issettablewhen
IsOutputEnabledisfalse.
LicenseKey–Getsorsetslicensekeystringin normalorencryptedformat.
PlaybackDevice–Getsorsetsthecurrentplaybackdevice.Issettablewhen IsOutputEnabledisfalse.Bysettingthispropertynull,Windows'defaultplaybackdeviceisused.
SamplesPerSecond–Getsorsetssamplingfrequency.Is settablewhen IsOutputEnabledisfalse.
Volume–Getsorsetsvolume(0-100).IssettablewhenIsOutputEnabledisfalse.
20.SpectrumCalculatorcomponent
SpectrumCalculatorcomponentallowsconversionbetweentimedomainandfrequencydomain.
Figure20-1.Exampleofsourcesignaldata(top)convertedtofrequencydomain(bottom).Signalsamplingfrequency=300
Hz,thusfrequencyscaleis300/2=150Hz.Thestrongsinebaselineis10Hz(10cycles/sec).Smallersignalof100Hzisadded
asnoise.Bothspikesarefoundinthepowerspectrum.
Thefollowingpublicmethodsareavailable:
• CalculateForward(double[]samples,outdouble[]fftData):ConvertstimedomainsignaldatatofrequencydomainbyusingFFT.OutputfftDatacontainsalsonegativevalues.Inputandoutputdata arraysmustbeofequallength.Thelengthistheresolutionofthedata,spreadingfrom0Hzto samplingfrequency/2withequalfrequencyintervalbetweenoutputvalues.
• CalculateForward(float[]samples,outfloat[]fftData):likethepreviousmethod,butforsingleaccuracyfloatingpointvalues.
• CalculateBackward(double[]fftData,outdouble[]samples):Convertsfrequencydomaindatatotimedomain.MakessignalsamplesfromFFTdata,samplecountequalsinputfftDatalength.
• CalculateBackward(float[]fftData,outfloat[]samples:likethepreviousmethod,butforsingleaccuracyfloatingpointvalues.
• PowerSpectrum(double[]samples,outdouble[]fftData):Calculatespowerspectrumofsignaldata.Sameas CalculateForward,butwith absoluteoutputvalues.
• PowerSpectrum(float[]samples,outfloat[]fftData):like thepreviousmethod,butforsingleaccuracyfloatingpointvalues.
• PowerSpectrumOverlapped(double[]samples,intfftWindowLength,doubleoverlapPercent,outdouble[]fftData,outintprocessedSampleCount):calculatespowerspectrumbyshiftingthe calculationwindowsinsidesourcesignalsamplesdata,byoverlappercent.SignaldatamustbelongerthangivenFFTwindowlength.The outputFFTdataislengthoffftWindowLength,sonotnecessarilysamethanthelengthofsourcedata.Theoutputdataisabsolutevalues.
• PowerSpectrumOverlapped(float[]samples,intfftWindowLength,doubleoverlapPercent,outfloat[]fftData,outintprocessedSampleCount)
© Copyright 2000-2022 COGITO SOFTWARE CO.,LTD. All rights reserved. 京ICP备09015132号-52