February 26, 2021
Hot Topics:

MFC Multithreaded Recording and Playback of Sound

  • By Paul Cheffers
  • Send Email »
  • More Articles »

This article was contributed by Paul Cheffers.

The following classes, CRecordSound and CPlaySound, record sound and play PCM sound simultaneously. An example dialog-based program is provided that records and echos sound. With these two classes, sound can be both recorded and played at the same time. Continuous sound can be monitored and upon appropriate queues, sound can be played back. Simple sound recognition could also, for instance, be put into CRecordSound. The multithreading allows other actions to take place while sound recording and playback go on.

CRecordSound can be invoked by the following code:

m_pRecordSound = new CRecordSound();
CPlaySound can be invoked by the following code:

m_pPlaySound = new CPlaySound();
To initiate sound recording from CRecordSound do the following:

 0, 0L);
To stop recording sound:

Similar calls begin playing and stopping of sound:

The CRecordSound class ferries sound blocks that have been recorded over to the CPlaySound class. The CRecordSound class is notified of the CPlaySound thread via:

For both CRecordSound and CPlaySound, the virtual member,

ProcessSoundData(short int* sound, DWORD dwSamples);
can be overridden to get access to the actual sound data.


Download demo project - 17 Kb


Date Posted: January 21, 2000

This article was originally published on January 21, 2000

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date