Sei sulla pagina 1di 26

Voice Impairments Detection Library v.2.1.3.

283

Issues Concurrent Operation alternative 1 alternative 2 List of Functions CSST_SDK_API bool CSST_InitLib(void); CSST_SDK_API void CSST_ReleaseLib(void); CSST_SDK_API const wchar_t* CSST_GetVersion(void); CSST_SDK_API CSContext * CSST_CreateProcessor(ESContextsTypes aCType); CSST_SDK_API void ReleaseProcessor(CSContext * aPProcessor); CSST_SDK_API long CSST_PutSound(CSContext * aPProcessor, short * aPSamples, long aNSamples); CSST_SDK_API int CSST_GetFrameSize(CSContext * aPProcessor); CSST_SDK_API long CSST_GetSampleRate(CSContext * aPProcessor); CSST_SDK_API long CSST_GetNChannels(CSContext * aPProcessor); CSST_SDK_API void CSST_SetSampleRate(CSContext * aPProcessor, long aSmplRate); CSST_SDK_API void CSST_SetNChannels(CSContext * aPProcessor, long aNChannels); CSST_SDK_API TSResult CSST_GetResult(CSContext * aPProcessor, long aChannel); int GetLastErrorCode(void); Usage Examples

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 00530 Helsinki11 Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 kula 76911 Huuru Estonia (Harjumaa) Phone: +372 53485178

Signal Noise Ratio Calculator (SNR) Clipping detection Echo detection Sample code of the library usage Sample source code Delivery: Compilation

Voice Impairments Detection Library passively detects different impairments in speech signal that degrade voice perception quality. The library is based on comprehensive algorithms of digital signal processing represented as separate processors, which user can access as unified virtual classes that have identical interfaces.

Issues

Concurrent Operation alternative1


R e s u l t s P r o c e s s S a m p l e s ( L i s t < s h o r t > s a m p l e s ) { f o r ( i n t n = 0 n < s a m p l e s . s i z e ( ) n + + ) { p r o c e s s S a m p l e ( s a m p l e s . a t ( n ) ) } r e t u r n f i n a l A n a l y s i s R e s u l t ( ) }

alternative2
/ / A d d d e c o d e d a u d i o d a t a o f s i n g l e R T P p a c k e t . . . v o i d A d d S a m p l e s ( L i s t < s h o r t > s a m p l e s {
Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

f o r ( i n t n = 0 n < s a m p l e s . s i z e ( ) n + + ) { p r o c e s s S a m p l e ( s a m p l e s . a t ( n ) ) } }

/ / A d d d e c o d e d a u d i o d a t a o f s i n g l e R T P p a c k e t . . . v o i d A d d S a m p l e s ( L i s t < s h o r t > s a m p l e s { f o r ( i n t n = 0 n < s a m p l e s . s i z e ( ) n + + ) { p r o c e s s S a m p l e ( s a m p l e s . a t ( n ) ) } } . . / / r e p e a t s e v e r a l t i m e s . . / / A d d d e c o d e d a u d i o d a t a o f s i n g l e R T P p a c k e t . . . v o i d A d d S a m p l e s ( L i s t < s h o r t > s a m p l e s { f o r ( i n t n = 0 n < s a m p l e s . s i z e ( ) n + + ) { p r o c e s s S a m p l e ( s a m p l e s . a t ( n ) ) } }

/ / G e t r e s u l t s o f w a v e f o r m a n a l y s i s R e s u l t s G e t A n a l y s i s R e s u l t ( ) { r e t u r n f i n a l A n a l y s i s R e s u l t ( ) }

List of Functions

The following functions are used to initialize and release the library:

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

CSST_SDK_API bool CSST_InitLib(void);


Library initialization/loading. To be called to start working with the library. On successful load of the library the function returns True and False in case of failure.

CSST_SDK_API void CSST_ReleaseLib(void);


Release function is called to finish working with the library.

CSST_SDK_API const wchar_t* CSST_GetVersion(void);


Returns library version string. To work with the library one has the following functions:

CSST_SDK_API CSContext * CSST_CreateProcessor(ESContextsTypes aCType);


- create processor; identifier of the processor is set by aCType parameter. ESContextsTypes contains list of possible processors presented in the table below: Identifies esctSNRCalculator esctClippingDetector esctEchoDetector esctClickDetector esctStuckDetector esctUnknownDetector Description SNR calculation Clipping impairment detection Echo impairment detection Clicking detection Stuck impairment detection Unknown processor

On success function returns pointer to unified processor. On error the function returns NULL. Function GetLastErrorCode returns error code.

CSST_SDK_API void ReleaseProcessor(CSContext * aPProcessor);


- removes processor and all associated data from memory.

CSST_SDK_API long CSST_PutSound(CSContext * aPProcessor, short * aPSamples, long aNSamples);


- add sound date to processor aPProcessor. aPSamples is array of signal samples, aNSamples number of samples. In case of multichannel sound samples are placed into aPSamples in the following order:

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

aPSamples[0] = sample 0 channel 1 aPSamples[1] = sample 0 channel 2 ... aPSamples[N-1] = sample 0 channel N aPSamples[N] = sample 1 channel 1 aPSamples[N+1] = sample 1 channel 2 ... aPSamples[aNSamples-1] = sample M-1 channel N Channel numbering starts with 1.

CSST_SDK_API int CSST_GetFrameSize(CSContext * aPProcessor);


- returns size of working data buffer of aPProcessor in samples. Buffer size defines minimal number of samples required by processor to perform analysis. Function CSST_PutSound has only one requirement: input data must be multiple to the number of channels and may not necessarily correspond to the frame size. Processors automatically split data into buffers, but working with buffers gives users a possibility to receive results within every frame.

CSST_SDK_API long CSST_GetSampleRate(CSContext * aPProcessor);


- returns signal sampling frequency value that aPProcessor is set to work with.

CSST_SDK_API long CSST_GetNChannels(CSContext * aPProcessor);


- returns number of speech channels the aPProcessor is set to work with.

CSST_SDK_API ESCodecsTypes CSST_GetCodecType(CSContext * aPProcessor);


- returns identifier of the initial signal coding algorithm. Setting the initial compression algorithm allows the system to adapt more exactly to the parameters of the signal, to improve the used compression algorithm and to identify more accurately the various types of distortion. Codecs known to the system are listed in ESCodecsTypes. The following values are foreseen/defined: Identifier esctNotCoded Description samples without coding

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

esctG711_ALaw esctG711_ULaw esctUnKnownCodec

G.711 A-Law G.711 U-Law Any other codec

CSST_SDK_API void CSST_SetSampleRate(CSContext * aPProcessor, long aSmplRate);


- Passes aPProcessor sampling frequency value of the signal aSmplRate. By default sampling frequency is set to 8kHz. It's important to set actual sampling frequency because many algorithms depend on that and this results into correctness of processing results.

CSST_SDK_API void CSST_SetNChannels(CSContext * aPProcessor, long aNChannels);


- passes aPProcessor number of channels (aNChannels) in the input signal.

CSST_SDK_API int CSST_SetCodecType(CSContext * aPProcessor, ESCodecsTypes aCType);


- passes identifier of initial coding algorithm to aPProcessor.

CSST_SDK_API TSResult CSST_GetResult(CSContext * aPProcessor, long aChannel);


- Returns results of aPProcessor work for channel aChannel joined in the following structure: struct TSResult { ESContextsTypes dRType; bool long isValid; dChannel; dResult;

USUniResult };

The structure has common fields for all types of processors: SNR, Clipping, Echo. Field dRType contains processor
Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

type, which allows correctly select dResult union depending on processor type:

Field isValid contains flag of processing correctness as there are possible cases that processor will not be able to provide results for certain frame. If result is invalid one can obtain the reason using function GetLastErrorCode()

Field dChannel contains channel number that results are associated with. In case of multichannel sound inquiry to channel 0 returns average result over all channels. Averaging depends on the processor type.

Union of polytipic results is defined as the following structure: union USUniResult { TSSNRResult dSNR; TSClippingResult dClipping; TSEchoResult dEcho; TSClickResult dClicking; TSStuckResult dStuck; }; Each processor type corresponds to a certain result identifier:
dSNR dEcho dClicking result of SNR processor; result of Clipping detection processor; result of Clicking detection processor; result of Echo detection processor;

dClipping

dStuck result of Stuck detection processor.

Channel numbering begins with one, if you ask the result for channel 0, you get the average result for all channels that are processed. In all other cases the return value corresponds to the requested channel.

CSST_SDK_API int CSST_GetLastErrorCode(void);


- returns error code of the last error. After function call current error code is reset, so repeating call will return 0 if
Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

no other error occurs in the meanwhile. Error codes are declared in CSpTErrors.h file and their description can be found in the table below: Code 0 1 2 3 4 5 6 7 8 9 10 errNoErrors errSpeechToolIsNotInitialized errLicensesFileNameMissed errLicensesFileOpeningError errIncompatibleLicensesFile errIncompatibleHost errLibraryInUse errLicensesTimeIsOver errAllChannelsAreOpened errUnKnownProcessorType errNotEqualSamplesNumForChannel s 11 12 errIncorrectSampleRate errCannelNumOutOfRange Identifier No error Library is not initialized License file name is missing Error opening license file Incompatible license file License file was issued for another machine The library has been already loaded and is in use License period has expired All channels are in use Unknown processor type The number of samples is not a multiple of the number of channels Algorithm cannot work with the provided sampling frequency Channel number is not in the range of sound channels of the processor 13 14 15 16 17 18 errTooFewOfData errTooFewOfDataForFlySNR errTooFewOfDataForFlyClipping errSetContextInValideCrashed errInitLibCrashed errGetLastErrorCodeCrashed Processor received too few data Too few data to calculate SNR mean value Too few data to calculate clipping mean value Crash in SetContextInValide Crash in CSST_InitLib Crash in CSST_ReleaseLib Description

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

19 20 21 22 23

errPooreProcessorPointer errInValideProcessor errCreateProcessorCrasched errReleaseProcessorCrashed errPutSoundCrashed

Poor pointer to Processor Processor validity flag is false Crash in CSST_CreateProcessor Crash in CSST_ReleaseProcessor Crash in CSST_PutSound

Usage Examples

Signal Noise Ratio Calculator (SNR)


Signal Noise Ratio calculator (SNR processor) can be created by function CSST_CreateProcessor when using parameter esctSNRCalculator. It performs sound processing by 240 samples and frame size may vary depending on sampling frequency used. When passing data into the calculator one does not need to consider frame size as SNR processor stores data and processes it depending on buffer contents size. Results will be sent to structure TSSNRResult :
struct TSSNRResult { double dSNR; double dEnergy; double dFlySNR; double dFlyEnergy; long dNSamples; double dTime; };

Processor calculates signal energy level for each frame in dB. Last frame energy level is sent to dEnergy field. dSNR field contains signal noise ratio from the beginning of the sound stream and up to current moment, which is calculated as difference between maximal and minimal energy values.

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

dFlySNR and dFlyEnergy fields contain average values of signal noise ratio and energy for last 10 frames of the signal. dNSamples field saves number of processed signal samples and field dTime stores duration of the processed signal in seconds. SNR Calculator returns the first result after receiving two valid frames of audio data.By valid we mean: The energy level on the frame exceeds the threshold value; The difference between the minimum and the maximum value exceeds the threshold; The active signal started (we have found a maximum power value that exceeds the threshold value).

Amplitude Clipping detection


Amplitude Clipping detection processor can be created by function CSST_CreateProcessor using parameter value esctClippingDetector. It performs sound processing by 80 samples and frame size may vary depending on sampling frequency used. When passing data into the processor one does not need to consider frame size as the processor stores data and processes it depending on buffer contents size. Results will be sent to structure TSClippingResult : struct TSClippingResult { double dFrameClpLevel; double dFrameClpLevelWide; double dClpLevel; double dClpLevelWide; double dFlyClpLevel; double dFlyClpLevelWide; long dNSamples; double dTime; }; Field dFrameClpLevel contains signal clipping level which corresponds to the number of clipped samples on current frame to the frame length. Field dFrameClpLevelWide contains clipping level of sequentially clipped samples and is calculated as ratio of clipped sequence length to the frame length. Fields dClpLevel and dClpLevelWide contain clipping level and sequential clipping level from the beginning of audio stream till current moment. Fields dFlyClpLevel and dFlyClpLevelWide store clipping level and sequential clipping level received as result of
Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

averaging of the recent 10 processed frames. Field dNSamples stores number of processed signal samples and field dTime stores duration of processed signal in seconds.

Echo detection
Echo detection processor can be created by function CSST_CreateProcessor using parameter value esctEchoDetector. It performs sound processing by 2000 samples and frame size may vary depending on sampling frequency used. When passing data into the processor one does not need to consider frame size as the processor stores data and processes it depending on buffer contents size. Results will be sent to structure TSEchoResult: struct TSEchoResult { double dEchoPower; double dSpeechPower; double dEchoLevel; long dNSamples; double dTime; }; Fields dEchoPower and dSpeechPower contain minimal and maximal levels of signal autocorrelation and field dEchoLevel contains their difference. The current echo detection algorithm is based on echo compensator and fields dEchoPower and dSpeechPower contain energy values of echo and initial signal. Field dEchoLevel is equal to the ratio of these two fields multiplied by 100 (to return value in percentage). Field dNSamples stores number of processed signal samples and field dTime stores duration of processed signal in seconds.

, . , -. , . , , , , . There are two library variant, which implement different ways of detecting echo. In one case, this is done using
Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

correlation, in the other - an echo canceller. The first option provides greater speed, but less accurate detection. In addition, in the first realization the values returned by the detector are also coefficients of the similarity of signals. In the second case they represent the energy of the signals.

Sample code of the library usage


As an example we provide source code of the main file /Sample/sptLibTest/mains/SPTTest.cpp of packet processor for detecting voice impairments in sound files, which can detect different impairments and print out place of their occurrencies in time domain.
/ / S t a n d a r d h e a d e r f i l e s # i n c l u d e < s t d i o . h > # i n c l u d e < s t d l i b . h > # i n c l u d e < s t r i n g . h > # i n c l u d e < f c n t l . h > # i n c l u d e < s y s / t i m e b . h > # i n c l u d e < t i m e . h > # i f d e f W I N 3 2 # i n c l u d e < i o . h > # e n d i f # i f n d e f W I N 3 2 # i n c l u d e < d i r e n t . h > # e n d i f / / T h r e s h o l d v a l u e s t o o u t p u t i m p a i r m e n t s i n t o a l o g f i l e ( u s e r d e f i n e d ) # d e f i n e c m F l y S N R T h r e s h 1 0 # d e f i n e c m F r a m e C l p T h r e s h 0 # d e f i n e c m W i d e F r a m e C l p T h r e s h 0 # d e f i n e c m E c h o T h r e s h 0 . 2 2 / / H e a d e r f i l e s o f t h e S p e e c h T o o l # i n c l u d e " . . / . . / D L L / i n c l u d e / C S p T E r r o r s . h " # i n c l u d e " . . / . . / D L L / i n c l u d e / C S S p e e c h T o o l . h " / / H e a d e r f i l e s t o w o r k w i t h a u d i o r e c o r d i n g s # i n c l u d e " . . / . . / W a v e / W a v F i l e s . h " # i n c l u d e " . . / . . / W a v e / C S m t S a m p l e s . h "

/ / A r r a y o f p r o c e s s o r s n a m e s c h a r * p C n t N a m e s [ ] = { " S N R C a l c u l a t o r " , / / S N R p r o c e s s o r " C l i p p i n g D e t e c t o r " , / / C l i p p i n g d e t e c t i o n p r o c e s s o r " E c h o D e t e c t o r " , / / E c h o d e t e c t i o n p r o c e s s o r " U n K n o w n " , / / U n k n o w n p r o c e s s o r } / / S t r u c t r u e f o r p r o c e s s o r l i s t e l e m e n t s t r u c t T S C o n t e x t s L i s t I t e m { C S C o n t e x t * p C o n t e x t Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

d o u b l e d D u r a t i o n T S C o n t e x t s L i s t I t e m * p N e x t } / / L i s t o f c o n n e c t e d p r o c e s s o r s T S C o n t e x t s L i s t I t e m * p C o n t e x t s L i s t = N U L L / / L o g f i l e F I L E * i P R e p F i l e / / S t r i n g t r a n s c o d i n g f r o m c h a r i n t o w c h a r _ t s t a t i c w c h a r _ t * c h a r 2 w c h a r ( c o n s t c h a r * a P S t r , w c h a r _ t * a P W S t r , i n t a L e n ) { i n t i , l i f ( ! a P S t r ) r e t u r n ( N U L L ) l = s t r l e n ( a P S t r ) i f ( l > = a L e n ) r e t u r n ( N U L L ) f o r ( i = 0 i < l + 1 i + + ) a P W S t r [ i ] = w c h a r _ t ( a P S t r [ i ] ) r e t u r n ( a P W S t r ) } / / C r e a t i n g p r o c e s s o r w i t h s e t f u n c t i o n a l i d e n t i f i e r s i n t C r e a t e P r o c e s s o r ( c h a r * a P P r o c N a m e ) { T S C o n t e x t s L i s t I t e m * i P N e w L I i P N e w L I = n e w T S C o n t e x t s L i s t I t e m ( ) i P N e w L I > d D u r a t i o n = 0 . 0 i f ( s t r c m p ( a P P r o c N a m e , " s n r " ) = = 0 ) { / / S N R c a l c u l a t o r i P N e w L I > p C o n t e x t = C S S T _ C r e a t e P r o c e s s o r ( e s c t S N R C a l c u l a t o r ) i f ( ! i P N e w L I > p C o n t e x t ) { d e l e t e ( i P N e w L I ) r e t u r n ( 2 ) } C S S T _ S e t S a m p l e R a t e ( i P N e w L I > p C o n t e x t , 8 0 0 0 ) C S S T _ S e t N C h a n n e l s ( i P N e w L I > p C o n t e x t , 1 ) / / i P N e w L I > p N e x t = p C o n t e x t s L i s t p C o n t e x t s L i s t = i P N e w L I r e t u r n ( 0 ) } e l s e i f ( s t r c m p ( a P P r o c N a m e , " c l i p p " ) = = 0 ) { / / C l i p p i n g d e t e c t o r i P N e w L I > p C o n t e x t = C S S T _ C r e a t e P r o c e s s o r ( e s c t C l i p p i n g D e t e c t o r ) i f ( ! i P N e w L I > p C o n t e x t ) { d e l e t e ( i P N e w L I ) r e t u r n ( 3 ) } C S S T _ S e t S a m p l e R a t e ( i P N e w L I > p C o n t e x t , 8 0 0 0 ) C S S T _ S e t N C h a n n e l s ( i P N e w L I > p C o n t e x t , 1 )

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

/ / i P N e w L I > p N e x t = p C o n t e x t s L i s t p C o n t e x t s L i s t = i P N e w L I r e t u r n ( 0 ) } e l s e i f ( s t r c m p ( a P P r o c N a m e , " e c h o " ) = = 0 ) { / / E c h o d e t e c t o r i P N e w L I > p C o n t e x t = C S S T _ C r e a t e P r o c e s s o r ( e s c t E c h o D e t e c t o r ) i f ( ! i P N e w L I > p C o n t e x t ) { d e l e t e ( i P N e w L I ) r e t u r n ( 4 ) } C S S T _ S e t S a m p l e R a t e ( i P N e w L I > p C o n t e x t , 8 0 0 0 ) C S S T _ S e t N C h a n n e l s ( i P N e w L I > p C o n t e x t , 1 ) / / i P N e w L I > p N e x t = p C o n t e x t s L i s t p C o n t e x t s L i s t = i P N e w L I r e t u r n ( 0 ) } d e l e t e ( i P N e w L I ) r e t u r n ( 1 ) } / / D e f i n e s m i n i m a l p r o c e s s i n g s t e p l o n g C a l c u l a t e M i n S t e p ( v o i d ) { T S C o n t e x t s L i s t I t e m * i P N e w L I l o n g i R e t , i T m p i R e t = C S S T _ G e t F r a m e S i z e ( p C o n t e x t s L i s t > p C o n t e x t ) f o r ( i P N e w L I = p C o n t e x t s L i s t > p N e x t i P N e w L I i P N e w L I = i P N e w L I > p N e x t ) { i T m p = C S S T _ G e t F r a m e S i z e ( i P N e w L I > p C o n t e x t ) i f ( i R e t > i T m p ) i R e t = i T m p } r e t u r n ( i R e t ) } / / S o u n d p r o c e s s i n g

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

i n t P r o c e s s W a v e ( F I L E * a P R e p F i l e , s h o r t * a P S a m p l e s , l o n g i S i z e ) { T S C o n t e x t s L i s t I t e m * i P N e w L I c l o c k _ t i S t a r t T i m e c l o c k _ t i F i n i s h T i m e d o u b l e i D u r a t i o n f o r ( i P N e w L I = p C o n t e x t s L i s t i P N e w L I i P N e w L I = i P N e w L I > p N e x t ) { i S t a r t T i m e = c l o c k ( ) i f ( C S S T _ P u t S o u n d ( i P N e w L I > p C o n t e x t , a P S a m p l e s , i S i z e ) ! = i S i z e ) { r e t u r n ( 1 ) } i F i n i s h T i m e = c l o c k ( ) i D u r a t i o n = ( d o u b l e ) ( i F i n i s h T i m e i S t a r t T i m e ) / C L O C K S _ P E R _ S E C i P N e w L I > d D u r a t i o n + = i D u r a t i o n } r e t u r n ( 0 ) } / / P r i n t s i n t o l o g f i l e a t e a c h f r a m e i f i m a i r m e n t w a s d e t e c t e d i n t P r i n t f F l y R e p o r t ( F I L E * a P R e p F i l e , l o n g a P o s , d o u b l e a T i m e ) { T S C o n t e x t s L i s t I t e m * i P W r k L I T S R e s u l t i P r R e s b o o l i s P r i n t e d = f a l s e f o r ( i P W r k L I = p C o n t e x t s L i s t i P W r k L I i P W r k L I = i P W r k L I > p N e x t ) { i P r R e s = C S S T _ G e t R e s u l t ( i P W r k L I > p C o n t e x t , 0 ) / / i f ( i P r R e s . i s V a l i d ) {

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

s w i t c h ( i P r R e s . d R T y p e ) { c a s e e s c t S N R C a l c u l a t o r : / / S N R c a l c u l a t o r i f ( i P r R e s . d R e s u l t . d S N R . d F l y S N R < c m F l y S N R T h r e s h ) { i f ( ! i s P r i n t e d ) f p r i n t f ( i P R e p F i l e , " C u r r e n t F i l e P o s i t i o n i s % l i ( % l f s e c ) \ n " , a P o s , a T i m e ) f p r i n t f ( a P R e p F i l e , " d S N R = % l f \ n " , i P r R e s . d R e s u l t . d S N R . d S N R ) f p r i n t f ( a P R e p F i l e , " d F l y S N R = % l f \ n " , i P r R e s . d R e s u l t . d S N R . d F l y S N R ) i s P r i n t e d = t r u e } b r e a k c a s e e s c t C l i p p i n g D e t e c t o r : / / C l i p p i n g d e t e c t i o n i f ( ( i P r R e s . d R e s u l t . d C l i p p i n g . d F r a m e C l p L e v e l > c m F r a m e C l p T h r e s h ) | | ( i P r R e s . d R e s u l t . d C l i p p i n g . d F r a m e C l p L e v e l W i d e > c m W i d e F r a m e C l p T h r e s h ) ) { i f ( ! i s P r i n t e d ) f p r i n t f ( i P R e p F i l e , " C u r r e n t F i l e P o s i t i o n i s % l i ( % l f s e c ) \ n " , a P o s , a T i m e ) f p r i n t f ( a P R e p F i l e , " d F r a m e C l p L e v e l = % l f \ n " , i P r R e s . d R e s u l t . d C l i p p i n g . d F r a m e C l p L e v e l ) f p r i n t f ( a P R e p F i l e , " d F r a m e C l p L e v e l W i d e = % l f \ n " , i P r R e s . d R e s u l t . d C l i p p i n g . d F r a m e C l p L e v e l W i d e ) i s P r i n t e d = t r u e } b r e a k c a s e e s c t E c h o D e t e c t o r : / / E c h o d e t e c t o r i f ( i P r R e s . d R e s u l t . d E c h o . d E c h o L e v e l > c m E c h o T h r e s h ) { i f ( ! i s P r i n t e d ) f p r i n t f ( i P R e p F i l e , " C u r r e n t F i l e P o s i t i o n i s % l i ( % l f s e c ) \ n " , a P o s , a T i m e ) f p r i n t f ( a P R e p F i l e , " d E c h o P o w e r = % l f \ n " , i P r R e s . d R e s u l t . d E c h o . d E c h o P o w e r ) f p r i n t f ( a P R e p F i l e , " d S p e e c h P o w e r = % l f \ n " , i P r R e s . d R e s u l t . d E c h o . d S p e e c h P o w e r ) f p r i n t f ( a P R e p F i l e , " d E c h o L e v e l = % l f \ n " , i P r R e s . d R e s u l t . d E c h o . d E c h o L e v e l )

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

i s P r i n t e d = t r u e } b r e a k c a s e e s c t U n K n o w n : / / U n k n o w n p r o c e s s o r d e f a u l t : b r e a k } } } r e t u r n ( 0 ) } / / P r i n t s f i n a l r e p o r t i n t o l o g f i l e i n t P r i n t f F i n a l R e p o r t ( F I L E * a P R e p F i l e ) { T S C o n t e x t s L i s t I t e m * i P W r k L I T S R e s u l t i P r R e s f p r i n t f ( a P R e p F i l e , " \ n " ) f o r ( i P W r k L I = p C o n t e x t s L i s t i P W r k L I i P W r k L I = i P W r k L I > p N e x t ) { i P r R e s = C S S T _ G e t R e s u l t ( i P W r k L I > p C o n t e x t , 0 ) f p r i n t f ( a P R e p F i l e , " P r o c e s s o r t y p e : % i ( % s ) \ n " , i P W r k L I > p C o n t e x t > d C T y p e , p C n t N a m e s [ i P W r k L I > p C o n t e x t > d C T y p e ] ) i f ( ! i P r R e s . i s V a l i d ) f p r i n t f ( a P R e p F i l e , " N o t r e s u l t e d ( % i ) \ n " , G e t L a s t E r r o r C o d e ( ) ) e l s e { s w i t c h ( i P r R e s . d R T y p e ) { c a s e e s c t S N R C a l c u l a t o r : / / S N R C a l c u l a t o r f p r i n t f ( a P R e p F i l e , " d S N R = % l f \ n " , i P r R e s . d R e s u l t . d S N R . d S N R ) f p r i n t f ( a P R e p F i l e , " d E n e r g y = % l f \ n " , i P r R e s . d R e s u l t . d S N R . d E n e r g y ) b r e a k Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

c a s e e s c t C l i p p i n g D e t e c t o r : / / C l i p p i n g d e t e c t o r f p r i n t f ( a P R e p F i l e , " d C l p L e v e l = % l f \ n " , i P r R e s . d R e s u l t . d C l i p p i n g . d C l p L e v e l ) f p r i n t f ( a P R e p F i l e , " d C l p L e v e l W i d e = % l f \ n " , i P r R e s . d R e s u l t . d C l i p p i n g . d C l p L e v e l W i d e ) b r e a k c a s e e s c t E c h o D e t e c t o r : / / E c h o d e t e c t o r f p r i n t f ( a P R e p F i l e , " d E c h o P o w e r = % l f \ n " , i P r R e s . d R e s u l t . d E c h o . d E c h o P o w e r ) f p r i n t f ( a P R e p F i l e , " d S p e e c h P o w e r = % l f \ n " , i P r R e s . d R e s u l t . d E c h o . d S p e e c h P o w e r ) f p r i n t f ( a P R e p F i l e , " d E c h o L e v e l = % l f \ n " , i P r R e s . d R e s u l t . d E c h o . d E c h o L e v e l ) b r e a k

c a s e e s c t U n K n o w n : / / U n k n o w n p r o c e s s o r d e f a u l t : b r e a k } } } f p r i n t f ( a P R e p F i l e , " \ n " ) r e t u r n ( 0 ) } / / P r i n t s p r o c e s s o r s p e r f o r m a n c e i n t P r i n t f T i m i n g R e p o r t ( F I L E * a P R e p F i l e , l o n g a D a t a S i z e ) { T S C o n t e x t s L i s t I t e m * i P N e w L I d o u b l e i D a t a L e n s d o u b l e i S p e e d C o e f f f p r i n t f ( a P R e p F i l e , " \ n " ) i D a t a L e n s = d o u b l e ( a D a t a S i z e ) / 8 0 0 0 f o r ( i P N e w L I = p C o n t e x t s L i s t i P N e w L I i P N e w L I = i P N e w L I > p N e x t ) { Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

f p r i n t f ( a P R e p F i l e , " P r o c e s s o r t y p e : % i ( % s ) \ n " , i P N e w L I > p C o n t e x t > d C T y p e , p C n t N a m e s [ i P N e w L I > p C o n t e x t > d C T y p e ] ) i f ( i P N e w L I > d D u r a t i o n > 0 . 0 0 0 0 0 1 ) { i S p e e d C o e f f = i D a t a L e n s / i P N e w L I > d D u r a t i o n f p r i n t f ( a P R e p F i l e , " R e a l T i m e C o e f f i c i e n t = % l f \ n " , i S p e e d C o e f f ) } e l s e { f p r i n t f ( a P R e p F i l e , " T o o f a s t t o c a l c u l a t e ! \ n " ) } } f p r i n t f ( a P R e p F i l e , " \ n \ n \ n " ) r e t u r n ( 0 ) } / / R e l e a s e a l l p r o c e s s o r s i n t R e l e a s e P r o c e s s o r s ( v o i d ) { T S C o n t e x t s L i s t I t e m * i P W r k L I w h i l e ( p C o n t e x t s L i s t ) { i P W r k L I = p C o n t e x t s L i s t p C o n t e x t s L i s t = p C o n t e x t s L i s t > p N e x t R e l e a s e P r o c e s s o r ( i P W r k L I > p C o n t e x t ) d e l e t e ( i P W r k L I ) } r e t u r n ( 0 ) } / / P r o c e s s i n g s i n g l e a u d i o f i l e i n t P r o c e s s O n e F i l e ( c h a r * a W a v e N a m e , i n t a r g c , c h a r * a r g v [ ] ) { Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

C S m a r t S a m p l e s i I n D a t a s h o r t * i P D a t a S h o r t l o n g i , i P o s , i S t e p , i E O F D a t a , i S i z e d o u b l e i T i m e f p r i n t f ( i P R e p F i l e , " F i l e : ' % s ' \ n " , a W a v e N a m e ) / / R e a d i n g a u d i o i f ( i I n D a t a . R e a d F r o m F i l e ( a W a v e N a m e , 0 ) ! = 0 ) { i I n D a t a . R e s e t ( ) p r i n t f ( " C a n n o t o p e n i n p u t f i l e ! \ n " ) f p r i n t f ( i P R e p F i l e , " C a n n o t o p e n i n p u t f i l e ! \ n " ) r e t u r n ( 0 ) } / / C r e a t i n g p r o c e s s o r s f o r ( i = 4 i < a r g c i + + ) i f ( C r e a t e P r o c e s s o r ( a r g v [ i ] ) ! = 0 ) { p r i n t f ( " C a n n o t c r e a t e p r o c e s s o r ' % s ' ! \ n " , a r g v [ i ] ) f p r i n t f ( i P R e p F i l e , " C a n n o t c r e a t e p r o c e s s o r ' % s ' ! \ n " , a r g v [ i ] ) i I n D a t a . R e s e t ( ) f c l o s e ( i P R e p F i l e ) r e t u r n ( 0 ) } / / P r e p a r i n g s o u n d d a t a i E O F D a t a = i I n D a t a . G e t N S a m p l e s ( ) i P D a t a S h o r t = ( s h o r t * ) i I n D a t a . G e t P S a m p l e s A r r a y ( e s s t S h o r t ) / / D e f i n e m a x i m a l p r o c e s s i n g s t e p i S t e p = C a l c u l a t e M i n S t e p ( ) / / P a r s e a u d i o d a t a f o r ( i P o s = 0 i P o s < i E O F D a t a i P o s + = i S t e p ) {

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

/ / D e f i n e s i z e o f p r o c e s s e d b l o c k i f ( ( i P o s + i S t e p ) < = i E O F D a t a ) i S i z e = i S t e p e l s e i S i z e = i E O F D a t a i P o s i T i m e = d o u b l e ( i P o s ) / 8 0 0 0 . 0 / / P r o c e s s s o u n d P r o c e s s W a v e ( i P R e p F i l e , i P D a t a S h o r t + i P o s , i S i z e ) / / O u t p u t o f p e r f r a m e r e p o r t P r i n t f F l y R e p o r t ( i P R e p F i l e , i P o s , i T i m e ) } / / O u t p u t o f f i n a l r e p o r t P r i n t f F i n a l R e p o r t ( i P R e p F i l e ) / / P r i n t p r o c e s s o r s ' p e r f o r m a n c e P r i n t f T i m i n g R e p o r t ( i P R e p F i l e , i E O F D a t a ) / / R e l e a s e e v e r y t h i n g R e l e a s e P r o c e s s o r s ( ) i I n D a t a . R e s e t ( ) r e t u r n ( 0 ) } / / F u n c t i o n m a i n ( ) i n t m a i n ( i n t a r g c , c h a r * a r g v [ ] ) { w c h a r _ t i L i c N a m e [ 2 0 4 8 ] / / C h e c k i n g n u m b e r o f a r g u m e n t s i f ( a r g c < 5 ) { p r i n t f ( " U s a g e : \ n " ) p r i n t f ( " s p t t e s t < l i c f i l e > < p a t h t o w a v s > < r e p f i l e > < p r o c i d 0 0 > [ [ p r o c i d 0 1 ] . . . [ p r o c i d N N ] ] \ n " ) p r i n t f ( " < l i c f i l e > : S e t t h e l i c e n s e s f i l e n a m e \ n " ) p r i n t f ( " < p a t h t o w a v s > : S e t t h e p a t h t o w a v e f i l e s \ n " ) p r i n t f ( " < r e p f i l e > : S e t t h e o u t p u t t e x t f i l e n a m e \ n " )

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

p r i n t f ( " < p r o c i d X X > : S e t t h e s o u n d p r o c e s s o r c . \ n " ) p r i n t f ( " : s n r \ n " ) p r i n t f ( " : c l i p p \ n " ) p r i n t f ( " : e c h o \ n " ) r e t u r n ( 0 ) } / / L i b r a r y i n i t i a l i z a t i o n c h a r 2 w c h a r ( a r g v [ 1 ] , i L i c N a m e , 2 0 4 8 ) i f ( ! C S S T _ I n i t L i b ( i L i c N a m e ) ) { p r i n t f ( " L i c e n s e s d a t a f a i l e d ! \ n " ) r e t u r n ( 0 ) } / / P r e p a r i n g l o g f i l e i P R e p F i l e = f o p e n ( a r g v [ 3 ] , " w + t " ) i f ( ! i P R e p F i l e ) { p r i n t f ( " C a n n o t o p e n o u t p u t f i l e ! \ n " ) r e t u r n ( 0 ) } # i f d e f W I N 3 2 / / / / W i n d o w s r e l a t e d / / s t a t i c c h a r d F u l l P a t h S t r i n g [ 4 0 9 6 ] s t r u c t _ f i n d d a t a _ t f f b l k i n t h a n d l e i n t d N F i l e s , d o n e / / F i l l i n g i n s t r i n g w i t h p a t h s p r i n t f ( d F u l l P a t h S t r i n g , " % s \ \ * . w a v " , a r g v [ 2 ] ) / / T a k e f i r s t . w a v f i l e

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

d N F i l e s = d o n e = 0 h a n d l e = _ f i n d f i r s t ( d F u l l P a t h S t r i n g , & f f b l k ) / / S c a n n i n g f o l d e r c o n t a i n i n g . w a v f i l e s w h i l e ( ( h a n d l e ! = 1 ) & & ( d o n e = = 0 ) ) { i f ( ( f f b l k . a t t r i b & _ A _ S U B D I R ) = = 0 ) { s p r i n t f ( d F u l l P a t h S t r i n g , " % s \ \ % s " , a r g v [ 2 ] , f f b l k . n a m e ) P r o c e s s O n e F i l e ( d F u l l P a t h S t r i n g , a r g c , a r g v ) d N F i l e s + + p r i n t f ( " % i f i l e s a r e p r o c e s s e d ! \ r " , d N F i l e s ) } d o n e = _ f i n d n e x t ( h a n d l e , & f f b l k ) } _ f i n d c l o s e ( h a n d l e ) # e l s e / / / / L i n u x r e l a t e d / / s t r u c t d i r e n t * i D i r E n t P D I R * i D i r P i D i r P = o p e n d i r ( a r g v [ 2 ] ) i f ( i D i r P = = N U L L ) r e t u r n ( f a l s e ) / / S c a n n i n g f o l d e r w i t h . w a v f i l e s f o r ( d N F i l e s = d o n e = 0 d o n e + + ) { i D i r E n t P = r e a d d i r ( i D i r P ) i f ( i D i r E n t P = = N U L L ) b r e a k i f ( s t r s t r ( i D i r E n t P > d _ n a m e , " . w a v " ) ) { s p r i n t f ( d F u l l P a t h S t r i n g , " % s / % s " , a r g v [ 2 ] , i D i r E n t P > d _ n a m e )

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

P r o c e s s O n e F i l e ( d F u l l P a t h S t r i n g , a r g v , a r g c ) } } c l o s e d i r ( i D i r P ) # e n d i f p r i n t f ( " % i f i l e s a r e p r o c e s s e d ! \ n " , d N F i l e s ) f c l o s e ( i P R e p F i l e ) / / R e l e a s i n g t h e l i b r a r y C S S T _ R e l e a s e L i b ( ) r e t u r n ( 0 ) }

Sample source code


Delivery:

Header files to work with audio (/Sample/Wave/). Classes implemented within the sample source code are not allowed for commercial use and do not represent part of the product. Header files of the library (/Sample/DLL/Include/). File CspTErrors.h contains error codes and file CSSpeechTool.h contains headers of all library functions. To ease sample code compilation archive include batch file CompileSptLibTest.bat (/Sample/) Libray binary is libSpeechTool_static.a (/Sample/) Compiled sample application spt-lib-test (/Sample/) Sound file for testing clean.wav (/Sample/) Batch file for a test run 2.bat (/Sample/)

Compilation
One can compile the sample source code by invoking batch file CompileSptLibTest.bat which has the following line: g++ -O2 ./sptLibTest/mains/SPTTest.cpp ./libSpeechTool_static.a -o ./spt-lib-test As result of compilation one receives a program that can find places having impairments that the library can detect in audio files. To run the program use the following command line options: spt-lib-test <lic-file> <path-to-wavs> <rep-file> <proc-id-00> [[proc-id-01] ... [proc-id-NN]]

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

where <lic-file> - license file, which is delivered by the vendor <path-to-wav> - path to folder containg .wav files <rep-file> - log/report file name <proc-id-00> [[proc-id-01] ... [proc-id-NN]] list of processors identifies; currently the library supports the following processors: SNR signal/noise ratio processor clipp clipping level calculating processor echo echo level calculating processor

This is a new document.

For measuring the performance of different detectors a SW called Performance.cpp was developed. The program can be compiled with any version of the library (Performance-test-corr - built with library that uses the algorithm based on correlation, Performance-test-echo - built with library that working with the echo canceller). The command line invocation of the software is: Performance-test-XXXX <proc-id> <ch-1-wave> [ch-2-wave] where: <proc-id> : the ID of the sound processors:); : snr : clipp : echo : click : stuck <ch-1-wave> : path of channel 1 wave file;

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

[ch-2-wave] : path of channel 2 wave file.

The parameters passed to the program are: the ID of the analyzing detector and one or two audio data files. Only the echo detector needs two files of audio data. All other detectors operate with a single file. After starting the program a series of performance measurements are done, the mean and variance are calculated. The resulting value of performance will be defined for a single processor core of the computer that has executed the software.

Copyright Sevana Ltd, 2012 Sevana Oy Agricolankatu 11 00530 Helsinki Finland Phone: +358 9 2316 4165 Sevana O Rohtlaane 12 76911 Huuru kula Estonia (Harjumaa) Phone: +372 53485178

Potrebbero piacerti anche