Click here to Skip to main content
Click here to Skip to main content

CWaveForm

, 24 Feb 2006
Rate this:
Please Sign up or sign in to vote.
A simple wave form API wrapper class

Introduction

This wrapper class implements standard waveform APIs in object oriented way. It supports following features :

  • Supports both wave_in and wave_out object in one class. You can indicate which type of stream to use by setting Direction.
  • Use my own private stream device interface to abstract the real world stream behavior. This  interface is still under development.
  • All memory allocation and deallocation is managed by theobject itself. That is, the caller never worries about memory. This is achieved by using IIDataSource & IIDataSink interface defined by myself.
  • The use of callback functions instead of callback windows. This is especially suitable for drawing intensive programs.
  • The use of the private IIAdvise interface, through which you can notify the client by window, thread ID, event and callback function. Very flexible. In my own project I use a separate thread to process the wave data.
  • Support volume control on wave_in and wave_out stream.
  • The use of AddRef()/Release() to manage the object life cycle. (Similar to COM)

The package includes three files. 

  • CWaveForm.cpp
  • CWaveForm.h
  • Interface.h

How to use my classes:

  1. Create a wave object 
    new CWaveForm(...)

    This contractor has couples parameters. Stream direction (in or out), wave in device id, wave out device id, wave in format, wave out format, wave in volume, wave out volume. Remember to call AddRef()

  2. Wave device operation sequence : open()->start()->stop()->close().
  3. Whenever wave in data is incoming, the object itself will invoke, that is, callback to the client. Then client calls the Read(ppData) function to get data buffer. After processing, client calls ReadDone(pData) to return data buffer.
  4. Whenever the client wants to send data to the wave out device, it can call Write() twice. The first call should provides an empty pointer, which will be filled with a valid buffer address. Then the client can write any data to this buffer, then call Write() again to queue this buffer back to wave out object.
  5. Please call Release() to free wave object.

Example

  1. Create new wave object:
    WaveForm = new CWaveForm
    (
    	WAVE_FORM_FLOW_BOTH, // Support both WAVE_IN and WAVE_OUT
    	m_waveInDeviceID,
    	m_waveOutDeviceID,
    	&m_waveInFormatEx,
    	&m_waveOutFormatEx,
    	m_waveInVolume,
    	m_waveOutVolume
    );
    
    WaveForm->AddRef(); // For wave_in.
    WaveForm->AddRef(); // For wave_out.
  2. Client advises call back interface:
    WaveForm->Advise
    (
    (DWORD)m_hThread, // I use seperate THREAD to processing wave data.
    0, // dwInstance is 0
    WM_STREAM_NOTIFY, // My private window message mask
    CALLBACK_THREAD // Callback type.
    );
    
  3. Whenever wave in data is coming:
    // Notify client.
    Invoke(WM_STREAM_NOTIFY, SUB_EVENT_WAVE_IN, 0);
  4. Client reading data:
    PWAVEFRAME pWaveFrame;
    WaveForm->Read(&pWaveFrame); // Get wave in data.
    .
    .
    // Client processing wave in data.
    .
    .
    WaveForm->ReadDone(pWaveFrame); // Return wave in data.
  5. Client write data to wave out device:
    PWAVEFRAME pWaveFrame = NULL;
    WaveForm->Write(&pWaveFrame); // Ask wave out object to allocate memory.
    .
    .
    // Client fill up this buffer with any data.
    .
    .
    WaveForm->Write(pWaveFrame); // Write data to wave out device.
  6. After using wave object:
    WaveForm->Release(); // For wave_in.
    WaveForm->Release(); // For wave_out.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Skeeter
Program Manager Microsoft
China China
Graduated from Shanghai Tongji university in 1997 with bachelor degree in computer science, Wenbin got his first job as a system engineer at Bell Alcatel Mobile Shanghai office responsible for telcom-class mobile system development and deployment. Since then, Wenbin has in turn worked for Intel and Microsoft both inside and outside China, first as senior engineer, later project manager and then senior product manager.
 
With 15-year experience working with the world top IT companies, Wenbin has developed solid skill in C/C++, C#, Java, software engineering, agile development, etc, and multiple talents in product management, public presentation and speech, etc. He has always been an active member at PMI (Project Management Institution) and a regular lecture at Intel Developer Forum, Microsoft TechED conference as well as many other world-class industrial conferences. His wide-ranged industrial practice and high-level personal maturity have made him one of the best in public speech and professional training.
 
Over the years, Wenbin has cultivated his very own style in public speech, which is considered informative, engaging and refined. Since last year, Wenbin has also taken new adventure in project and product management consulting business and has proven high capacity through his work with many local emergent IT firms. Wenbin’s specialty in management consulting is on project management methodologies and processes, project management tools (e.g. MS Project), and team recruitment, build, and motivation.
 
In addition, Wenbin has received many professional qualifications including MCSE (Microsoft Certified System Engineer), MCSD (Microsoft Certified System Developer), MCDBA (Microsoft Certified Database Administrator), SCJP 2 (Sun Certified Java Programmer 2), and PMP (PMI Certified Project Management Professional). On top of that, Wenbin has got several on-duty inventions and one of them was successfully patented by United States Patent and Trademark Office.

Comments and Discussions

 
GeneralMajor bug Pinmembermikeham8-Dec-06 6:19 
GeneralRe: Major bug Pinmembermikeham8-Dec-06 6:32 
GeneralError 1 error C2143: syntax error : missing ';' before '< Interface.h 272 Pinmemberersany12-Jul-06 1:43 
GeneralNew version is uploaded! PinmemberSkeeter24-Feb-06 8:14 
GeneralRe: New version is uploaded! Pinmemberaks-746-Mar-06 0:28 
GeneralI am back! PinmemberSkeeter21-Feb-06 21:19 
GeneralBug with wave recording Pinmemberaks-7420-Oct-05 18:28 
GeneralRe: Bug with wave recording PinmemberSkeeter24-Feb-06 2:20 
Generalissues Pinmemberstar fish8-May-05 11:36 
just to warn you there are many issues with this application:
1) callback proc
- you cannot call a wave*** function from within a callback proc
- doing so may - and does - result in deadlock
- this application makes many calls to such functions
- the callback must signal an event - or a new notification method should be devised
 

2) unprepare header
- this application does not properly-and timely unprepare the headers of the waiting and free lists
- the poor timing in calling waveinreset followed by waveinstop may - and often does - result in a hang.
- one must wait for all the buffers to be returned from the wave device before calling close.
 
3) the error noted below "A minor bug" must also be applied to the wavein counter part
 
4) simply do not call ::waveinclose as there are hang issues
suffice to call ::waveinreset
 
i will try and post a reworked version which appears to function smoothly (or at least smoother).
 

52,115

GeneralRe: issues Pinmemberstar fish9-May-05 2:08 
GeneralWave Format Transforming Question PinmemberDick.leeSolucky19-Jan-05 19:02 
Questionwhat thread.h file?? Pinmemberpsyco26-Jul-04 1:23 
AnswerRe: what thread.h file?? Pinmemberstar fish19-Apr-05 10:35 
AnswerRe: what thread.h file?? PinmemberSkeeter24-Feb-06 2:21 
Generalduration of the wav file Pinmemberelxharoon13-Jul-04 22:43 
Generalthread.h Pinmemberstar fish3-May-04 5:10 
GeneralRe: thread.h Pinmemberstar fish3-May-04 8:55 
Generalconverting WAV to EBU WAV format Pinmembernmanes26-Nov-02 2:30 
GeneralBorland C++ Builder Pinsussrodrigue7-Nov-02 6:22 
GeneralA minor bug PinsussMike Hamilton5-Aug-02 4:27 
QuestionHow to Store 16 Bit PCM Wave PinmemberMaria Jothi5-May-02 19:22 
AnswerHelp please PinsussLucian M31-Oct-03 2:54 
Questionany example projects? PinmemberSteve Guerreri23-Jan-02 10:15 
QuestionExample code? Pinmemberchen8-Nov-01 22:15 
QuestionAny examples of usage? PinmemberJ.G. Hattingh5-Nov-01 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 24 Feb 2006
Article Copyright 2001 by Skeeter
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid