Class for simple processing of audio input data

Source: Internet
Author: User

Process simple audio input data

Soundin class see my another blog http://blog.csdn.net/zgl7903/article/details/5669770

 

# Pragma once // microphone_measure.h # include "soundin. H" class cmicrophone_measure {public: cmicrophone_measure (); Virtual ~ Cmicrophone_measure (); Public: bool startmeasure (); void stopmeansure (); Public: typedef struct _ Empty {bool bvalid; DWORD dwptsize; // double fwave_frame_avg; // average value double fwave_frame_rms; // valid value double fwave_frame_max; // maximum value double fwave_frame_min; // minimum value double percentile; // absolute maximum value double fwave_frame_absmin; // absolute minimum value} wavemeasumeresult; protected metadata; bool isopened () {return bmicrophone_opened;} protected: bool metadata; csoundin m_soundin; static bool waveinproc (lpvoid puser, short * pdata, DWORD dwsize );};

 

 

# Include "stdafx. H "# include" microphone_measure.h "cmicrophone_measure: cmicrophone_measure () {bmicrophone_opened = false; // set the memset (& disabled, 0, sizeof (disabled) status )); // initialize the struct} cmicrophone_measure ::~ Cmicrophone_measure () {stopmeansure (); // stop measurement} bool cmicrophone_measure: startmeasure () {If (! Enabled) // non-open status {If (enabled (this, waveinproc) = mmsyserr_noerror) bmicrophone_opened = true;} return bmicrophone_opened;} void cmicrophone_measure: stopmeansure () {empty (); empty = false;} bool cmicrophone_measure: waveinproc (lpvoid puser, short * pdata, DWORD dwsize) {cmicrophone_measure * pthis = (cmicrophone_measure *) puser; wavemeasumeresult tmpresult = {0}; double dbval = pdata [0]; // The first vertex tmpresult. dwptsize = dwsize; // point tmpresult. fwave_frame_avg = dbval; // average tmpresult. fwave_frame_rms = POW (dbval, 2); // valid value tmpresult. fwave_frame_max = dbval; // maximum tmpresult. fwave_frame_min = dbval; // minimum tmpresult. fwave_frame_absmax = FABS (dbval); // the absolute maximum tmpresult. fwave_frame_absmin = FABS (dbval); // absolute minimum value for (DWORD I = 1; I <dwsize; I ++) {dbval = pdata [I]; // single-channel tmpresult. fwave_frame_avg + = dbval; // average tmpresult. fwave_frame_rms + = POW (dbval, 2); // valid value tmpresult. fwave_frame_max = max (dbval, tmpresult. fwave_frame_max); // maximum tmpresult. fwave_frame_min = min (dbval, tmpresult. fwave_frame_min); // The minimum tmpresult. fwave_frame_absmax = max (FABS (dbval), tmpresult. fwave_frame_absmax); // the absolute maximum tmpresult. fwave_frame_absmin = min (FABS (dbval), tmpresult. fwave_frame_absmin); // absolute minimum value} tmpresult. fwave_frame_avg/= dwsize; // average tmpresult. fwave_frame_rms = SQRT (tmpresult. fwave_frame_rms/dwsize); // valid value tmpresult. bvalid = true; pthis-> m_wavemeasureresult = tmpresult; return true ;}

 

// Simple application example

 

# Pragma once # include "inline" // ctestdlg dialog box class ctestdlg: Public cdialog {public: cmicrophone_measure m_microphone_measure; afx_msg void ontimer (uint_ptr nidevent); cprogressctrl m_progressctrl;

 

Bool ctestdlg: oninitdialog () {cdialog: oninitdialog (); // set the icon of this dialog box. When the main window of the application is not a dialog box, the framework will automatically // execute this operation seticon (m_hicon, true); // set the big icon seticon (m_hicon, false ); // set the small icon // todo: add the additional initialization code here. If (m_microphone_measure.startmeasure () settimer (1,100, null); Return true; // unless focus is set to the control, otherwise, return true} void ctestdlg: ontimer (uint_ptr nidevent) {// todo: add the message processing program code and/or call the default value if (wait) {cstring itemstr; itemstr. format (_ T ("points % LD \ r \ n") _ T ("average % G \ r \ n ") _ T ("valid value % G \ r \ n") _ T ("Maximum Value % G \ r \ n") _ T ("minimum value % G \ r \ n ") _ T ("absolute maximum value % G \ r \ n") _ T ("absolute minimum value % G \ r \ n"), m_microphone_measure.m_wavemeasureresult.dwptsize, // points must, // average vertex, // valid value vertex, // maximum m_microphone_measure.m_wavemeasureresult.fwave_frame_min, // minimum vertex, // absolute maximum vertex, // absolute minimum value 0); setdlgitemtext (idc_edit1, itemstr);} cdialog: ontimer (nidevent );}

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.