libcm is a C development framework with an emphasis on audio signal processing applications.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cmProc5.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef cmProc5_h
  2. #define cmProc5_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //=======================================================================================================================
  7. // Goertzel Filter
  8. //
  9. typedef struct
  10. {
  11. double s0;
  12. double s1;
  13. double s2;
  14. double coeff;
  15. double hz;
  16. } cmGoertzelCh;
  17. struct cmShiftBuf_str;
  18. typedef struct cmGoertzel_str
  19. {
  20. cmObj obj;
  21. cmGoertzelCh* ch;
  22. unsigned chCnt;
  23. double srate;
  24. struct cmShiftBuf_str* shb;
  25. cmSample_t* wnd;
  26. } cmGoertzel;
  27. cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt );
  28. cmRC_t cmGoertzelFree( cmGoertzel** pp );
  29. cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt );
  30. cmRC_t cmGoertzelFinal( cmGoertzel* p );
  31. cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz );
  32. cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* in, unsigned procSmpCnt, double* outV, unsigned chCnt );
  33. //=======================================================================================================================
  34. // Gold Code Signal Generator
  35. //
  36. typedef struct
  37. {
  38. unsigned chN; // count of channels (each channel has a unique id)
  39. double srate; // system sample rate (samples/second)
  40. unsigned lfsrN; // linear feedback shift register (LFSR) length used to form Gold codes
  41. unsigned mlsCoeff0; // LFSR coeff. 0
  42. unsigned mlsCoeff1; // LFSR coeff. 1
  43. unsigned samplesPerChip; // samples per spreading code bit
  44. double rcosBeta; // raised cosine impulse response beta coeff.
  45. unsigned rcosOSFact; // raised cosine impulse response oversample factor
  46. double carrierHz; // carrier frequency
  47. double envMs; // attack/decay envelope duration
  48. } cmGoldSigArg_t;
  49. typedef struct
  50. {
  51. int* pnV; // pnV[ mlsN ] spread code (aliased from pnM[:,i])
  52. cmSample_t* bbV; // bbV[ sigN ] baseband signal at audio rate
  53. cmSample_t* mdV; // mdV[ sigN ] modulated signal at audio rate
  54. } cmGoldSigCh_t;
  55. typedef struct
  56. {
  57. cmObj obj; //
  58. cmGoldSigArg_t a; // argument record
  59. cmGoldSigCh_t* ch; // ch[ chN ] channel array
  60. int* pnM; // pnM[mlsN,chN] (aliased to ch[].pnV)
  61. cmSample_t* rcosV; // rcosV[rcosN] raised cosine impulse response
  62. unsigned rcosN; // length of raised cosine impulse response
  63. unsigned mlsN; // length of Gold codes (Maximum length sequence length)
  64. unsigned sigN; // length of channel signals bbV[] and mdV[]
  65. } cmGoldSig_t;
  66. cmGoldSig_t* cmGoldSigAlloc( cmCtx* ctx, cmGoldSig_t* p, const cmGoldSigArg_t* a );
  67. cmRC_t cmGoldSigFree( cmGoldSig_t** pp );
  68. cmRC_t cmGoldSigInit( cmGoldSig_t* p, const cmGoldSigArg_t* a );
  69. cmRC_t cmGoldSigFinal( cmGoldSig_t* p );
  70. cmRC_t cmGoldSigWrite( cmCtx* ctx, cmGoldSig_t* p, const char* fn );
  71. // Generate a signal consisting of underlying white noise with
  72. // bsiN repeated copies of the id signal associated with
  73. // channel 'chIdx'. Each discrete id signal copy is separated by 'dsN' samples.
  74. // The signal will be prefixed with 'prefixN' samples of silence (noise).
  75. // On return sets 'yVRef' to point to the generated signal and 'yNRef'
  76. // to the count of samples in 'yVRef'.
  77. // On error sets yVRef to NULL and yNRef to zero.
  78. // The vector returned in 'yVRef' should be freed via atMemFree().
  79. // On return sets bsiV[bsiN] to the onset sample index of each id signal copy.
  80. // The background noise signal is limited to the range -noiseGain to noiseGain.
  81. cmRC_t cmGoldSigGen(
  82. cmGoldSig_t* p,
  83. unsigned chIdx,
  84. unsigned prefixN,
  85. unsigned dsN,
  86. unsigned *bsiV,
  87. unsigned bsiN,
  88. double noiseGain,
  89. cmSample_t** yVRef,
  90. unsigned* yNRef );
  91. cmRC_t cmGoldSigTest( cmCtx* ctx );
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif