April 16, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

MFC Multithreaded Recording and Playback of Sound

  • January 21, 2000
  • 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();
m_pRecordSound->CreateThread();
CPlaySound can be invoked by the following code:

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

m_RecordThread->PostThreadMessage(WM_RECORDSOUND_STARTRECORDING,
 0, 0L);
To stop recording sound:

m_RecordThread->PostThreadMessage(WM_RECORDSOUND_STOPRECORDING,
 0,0);
Similar calls begin playing and stopping of sound:

m_PlayThread->PostThreadMessage(WM_PLAYSOUND_STARTPLAYING,0,0);
m_PlayThread->PostThreadMessage(WM_PLAYSOUND_STOPPLAYING,0,0);
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:

m_RecordSound->PostThreadMessage(WM_RECORDSOUND_SOUNDPLAYER, 
 0,(LPARAM)m_PlaySound);
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.

Downloads

Download demo project - 17 Kb

History

Date Posted: January 21, 2000






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel