⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample.h

📁 C++ , microphone spectrogram viewer, real time
💻 H
字号:
#ifndef SampleH
#define SampleH
#include <mmsystem.h>
#include <math.h>
#include <dsgnintf.hpp>




class TWaveInDeviceID : public TPersistent
{
protected:
  int Fid; void __fastcall SetId(int Value);
  TNotifyEvent FOnChange;
public:
  void __fastcall Assign(TPersistent* Value); void __fastcall Changed();
__published:
  __property int id={read=Fid,write=SetId,default=WAVE_MAPPER};
  __property TNotifyEvent OnChange={read=FOnChange,write=FOnChange};
public:
  __fastcall TWaveInDeviceID();
  __fastcall virtual ~TWaveInDeviceID();
};

class TWaveInDeviceIDProperty : public TOrdinalProperty
{
protected:
  TStringList *deviceList;
  int ndevs;
  virtual void __fastcall GenerateDeviceList();
public:
  virtual AnsiString __fastcall GetValue();
  virtual void __fastcall SetValue(const AnsiString Value);
  virtual TPropertyAttributes __fastcall GetAttributes(); //+paValueList
  virtual void __fastcall GetValues(Classes::TGetStrProc Proc);
  virtual __fastcall TWaveInDeviceIDProperty();
  virtual __fastcall ~TWaveInDeviceIDProperty();
};



class TAudioLineParameters : public TPersistent
{
protected:
  int FChannels; void __fastcall SetChannels(int Value);
  int FFrequency; void __fastcall SetFrequency(int Value);
  int FBitsPerSample; void __fastcall SetBitsPerSample(int Value);
  TNotifyEvent FOnChange;
public:
  void __fastcall Assign(TPersistent* Value); void __fastcall Changed();
__published:
  __property int Channels={read=FChannels,write=SetChannels,default=1};
  __property int Frequency={read=FFrequency,write=SetFrequency,default=11025};
  __property int BitsPerSample={read=FBitsPerSample,write=SetBitsPerSample,default=8};
  __property TNotifyEvent OnChange={read=FOnChange,write=FOnChange};
public:
  _fastcall TAudioLineParameters();
  __fastcall virtual ~TAudioLineParameters();
};

class TAudioLineParametersProperty: public TClassProperty
{
protected:
  TStringList *allowedList;
  int nallowed;
  virtual void __fastcall GenerateAllowedList();
  virtual void __fastcall DestroyAllowedList();
public:
  virtual AnsiString __fastcall GetValue();
  virtual void __fastcall SetValue(AnsiString Value);
  virtual TPropertyAttributes __fastcall GetAttributes(); //+paValueList
  virtual void __fastcall GetValues(Classes::TGetStrProc Proc);
  virtual __fastcall TAudioLineParametersProperty();
  virtual __fastcall ~TAudioLineParametersProperty();
};





#define NUM_BUFS 8
#define MAX_INTERESTS 4

class TRecorder;
enum TRecorderReason {rrData,rrTidy,rrClose,rrOpen};
typedef void __fastcall (__closure *TRecorderNotification)(TObject* Sender,TRecorderReason rr);

class TRecorder: public TComponent
{
protected:
  int sizeSample;             // size of one sample
  int sizeBuf;                // size in bytes of each buffer
  int nextBuf;                // The next buffer that will receive data
  int numBufs;                // number of buffers
  char *pBuf;                 // one flat pool containing all the buffers
  WAVEHDR header[NUM_BUFS];   // pool of headers
  //
  HWND hControlWnd;           // if using VCL-events, then this wnd receives the messages
  void __fastcall ControlWndProc(TMessage &Message);
  TRecorderNotification interest[MAX_INTERESTS];
  //
  TWaveInDeviceID *FWaveInDevice; void __fastcall SetWaveInDevice(TWaveInDeviceID *wid);
  TAudioLineParameters *FQuality; void __fastcall SetQuality(TAudioLineParameters *asp);
  int FSamplesPerBuffer; void __fastcall SetSamplesPerBuffer(int spb);
  unsigned int __fastcall GetSamplePos();
  TNotifyEvent FOnSample;
  HWAVEIN FHandle; HWAVEIN __fastcall GetHandle(); void __fastcall CreateHandle(); void __fastcall DestroyHandle();
  bool FIsStarted;
  HANDLE FHEvent; void __fastcall SetHEvent(HANDLE h);
  bool __fastcall GetIsNextBufferReady();
  int __fastcall GetIData(int i);
  bool FAutoStart;
public:
  __fastcall virtual TRecorder(TComponent *AOwner);
  virtual __fastcall ~TRecorder();
  void __fastcall virtual Start();
  void __fastcall virtual Stop();
  void __fastcall virtual Reset();
  //
  __property HWAVEIN Handle={read=GetHandle};
  __property bool isStarted={read=FIsStarted};
  __property HANDLE hEvent={read=FHEvent,write=SetHEvent};
  //
  __property bool isNextBufferReady={read=GetIsNextBufferReady};
  void __fastcall virtual ReadyForNextBuffer();          // to say that you're done with the previous buffer and are now ready to use this one. Only for threaded model.
  __property int iData[int i]={read=GetIData};
  BYTE *bData;
  WORD *wData;
  int BufNumBytes;
  int BufNumSamples;
  //
  void __fastcall virtual AddInterest(TRecorderNotification ie);
  void __fastcall virtual RemoveInterest(TRecorderNotification ie);
  //
  int __fastcall virtual GetNumDevices();
  bool __fastcall virtual IsThisQualityPossible();
  bool __fastcall virtual IsQualityPossible(int freq,int channels,int bits);

__published:
  __property TWaveInDeviceID *Device={read=FWaveInDevice,write=SetWaveInDevice,nodefault};
  __property TAudioLineParameters *Quality={read=FQuality,write=SetQuality,nodefault};
  __property int BufSize={read=FSamplesPerBuffer,write=SetSamplesPerBuffer,default=256};
  __property TNotifyEvent OnSample={read=FOnSample,write=FOnSample};
  __property unsigned int SamplePos={read=GetSamplePos};
  __property bool AutoStart={read=FAutoStart,write=FAutoStart,default=false};
};






class TComplex;

#define MAX_FFTINTERESTS 4

class TFFT : public TComponent
{
private:
protected:
  TRecorder *FSource; void __fastcall SetSource(TRecorder *s);
  int FnPoints; void __fastcall SetNPoints(int); void __fastcall AdjustNPoints();
  bool isRegistered;
  TRecorderNotification interest[MAX_FFTINTERESTS];
  void __fastcall RegisterInterest();
  void __fastcall UnregisterInterest();
  void __fastcall UpdateSettings();
  void __fastcall CloseSettings();
  int freq;
  double *aTape;         // recording tape
  double sqrtPoints;
  int logPoints;
  int *aBitRev;        // bit reverse vector
  TComplex *X;         // in-place fft array
  TComplex **W;        // exponentials
  void __fastcall CopyIn();
  void __fastcall Transform ();
  int __fastcall GetData(int i);
  //
  virtual void __fastcall Notification(TComponent *AComponent,TOperation op);
public:
  virtual __fastcall TFFT(TComponent* Owner);
  virtual __fastcall ~TFFT();
  virtual void __fastcall Sample(TRecorder *Sender);
  void __fastcall virtual InterestProc(TObject *Sender, TRecorderReason rr);
  //
  void __fastcall virtual AddInterest(TRecorderNotification ie);
  void __fastcall virtual RemoveInterest(TRecorderNotification ie);
  //
  __property int Data[int i]={read=GetData};
    double __fastcall IntensityFromFrequency(int i);
  int __fastcall FrequencyFromPoint(int point);
  int __fastcall PointFromFrequency(int freq);
  int __fastcall MaxFreqency();

__published:
  __property TRecorder *Source={read=FSource,write=SetSource};
  __property int BufSize={read=FnPoints,write=SetNPoints,default=1024};
};
//---------------------------------------------------------------------------

//------------------------------------
//  complex.h
//  Complex number
//  (c) Reliable Software, 1996
//------------------------------------
class TComplex
{
public:
    TComplex () {}
    TComplex (double re): _re(re), _im(0.0) {}
    TComplex (double re, double im): _re(re), _im(im) {}
    double Re () const { return _re; }
    double Im () const { return _im; }
    void operator += (const TComplex& c) {_re += c._re; _im += c._im;}
    void operator -= (const TComplex& c) {_re -= c._re; _im -= c._im;}
    void operator *= (const TComplex& c) { double reT = c._re * _re - c._im * _im;_im = c._re * _im + c._im * _re; _re = reT;}
    TComplex operator- () { return TComplex (- _re, _im);}
    double Mod () const { return sqrt (_re * _re + _im * _im); }
    double _re;
    double _im;
};









class TWaveView : public TGraphicControl
{
private:
protected:
  TRecorder *FSource;
  bool isRegistered;
  void __fastcall SetSource(TRecorder *s);
  void __fastcall RegisterInterest();
  void __fastcall UnregisterInterest();
  POINT *pts;
  int numPoints;
  TColor FLine; virtual void __fastcall SetLine(TColor col);
  int nFrame;
  int FSkip;
public:
  __fastcall virtual TWaveView(TComponent* Owner);
  __fastcall virtual ~TWaveView();
  void __fastcall virtual InterestProc(TObject *Sender, TRecorderReason rr);
  virtual void __fastcall Paint();
  virtual void __fastcall Sample(TRecorder *src);
  virtual void __fastcall Notification(TComponent *AComponent,TOperation op);
__published:
  __property Align;
  __property TRecorder *Source={read=FSource,write=SetSource};
  __property Color={default=clBlack};
  __property TColor Line={read=FLine,write=SetLine,default=clLime};
  __property int SkipFrames={read=FSkip,write=FSkip,default=0};
};

class TFingerprintView : public TGraphicControl
{
private:
protected:
  TFFT *FSource;
  bool isRegistered;
  void __fastcall SetSource(TFFT *s);
  void __fastcall RegisterInterest();
  void __fastcall UnregisterInterest();
  int x;
  TColor FLine; void __fastcall virtual SetLine(TColor col);
  int nFrame,FSkip;
public:
  __fastcall virtual TFingerprintView(TComponent* Owner);
  __fastcall virtual ~TFingerprintView();
  void __fastcall virtual InterestProc(TObject *Sender, TRecorderReason rr);
  virtual void __fastcall Paint();
  virtual void __fastcall Sample(TFFT *src);
  virtual void __fastcall Notification(TComponent *AComponent,TOperation op);
__published:
  __property Align;
  __property TFFT *Source={read=FSource,write=SetSource};
  __property Color={default=clBlack};
  __property TColor Line={read=FLine,write=SetLine,default=clWhite};
  __property int SkipFrames={read=FSkip,write=FSkip,default=0};
};



class TSpectralView : public TGraphicControl
{
private:
protected:
  TFFT *FSource;
  bool isRegistered;
  void __fastcall SetSource(TFFT *s);
  void __fastcall RegisterInterest();
  void __fastcall UnregisterInterest();
  int nFrame;
  int FSkip;
  TColor FLine;
  int FBands;
  virtual void __fastcall Notification(TComponent *AComponent,TOperation op);
  virtual void __fastcall SetLine(TColor col);
  virtual void __fastcall SetBands(int b);
public:
  __fastcall virtual TSpectralView(TComponent* Owner);
  __fastcall virtual ~TSpectralView();
  void __fastcall virtual InterestProc(TObject *Sender, TRecorderReason rr);
  virtual void __fastcall Paint();
  virtual void __fastcall Sample(TFFT *src);
__published:
  __property Align;
  __property TFFT *Source={read=FSource,write=SetSource};
  __property Color={default=clBlack};
  __property TColor Line={read=FLine,write=SetLine,default=clGreen};
  __property int Bands={read=FBands,write=SetBands,default=10};
  __property int SkipFrames={read=FSkip,write=FSkip,default=0};
};



#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -