Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Using ISoundMixedOutputReceiver

Annon
Guest
Quote
2016-06-14 17:37:45

I am struggling to use the data collected by an ISoundMixedOutputReceiver derived class. My class is as follows:


class SoundReceiver : public ISoundMixedOutputReceiver
{
public:
void OnAudioDataReady ( const void* Data, int ByteCount, int PlayBackRate) override ;
int mSampleRate ;
vector<char> mData ;
};

void SoundReceiver::OnAudioDataReady(const void* Data, int ByteCount, int PlayBackRate)
{
const char* SoundData = (const char*)Data ;
mData.insert( mData.end(), SoundData, SoundData+ByteCount) ;
mSampleRate = PlayBackRate ;
}


I then use this class as follows:


int main()
{
SoundReceiver MySr ;

ISoundEngine* pSe = createIrrKlangDevice(ESOD_WIN_MM) ;
if ( pSe->setMixedDataOutputReceiver(&MySr)) cout << "Receiver set OK" << endl ;
else cout << "Failed to set receiver" << endl ;

//this_thread::sleep_for(chrono::seconds(2)) ;
pSe->play2D( "A.wav") ; // Any old wav file that plays for a few seconds.
this_thread::sleep_for(chrono::seconds(5)) ;

pSe->setMixedDataOutputReceiver(nullptr) ;
this_thread::sleep_for(chrono::seconds(5)) ;


SAudioStreamFormat Format ;
Format.SampleFormat = ESampleFormat::ESF_S16;
Format.ChannelCount = 2;
Format.SampleRate = MySr.mSampleRate ;
Format.FrameCount = MySr.mData.size() / Format.SampleRate ;

ISoundSource *RecordedSound = pSe->addSoundSourceFromPCMData(MySr.mData.data(), MySr.mData.size(), nullptr, Format, true ) ;
pSe->play2D(RecordedSound ) ;
this_thread::sleep_for(chrono::seconds(10)) ;

return 0;
}



What I was hoping was that my "A.wav" sound would play once and be recorded, then after a short pause it would be replayed via a new sound source generated from the recording. Instead I am hearing the sound just once and am getting silence for the playing of the recorded sound. I suspect that I am not setting up the "Format" object correctly. Can anyone tell me what I am doing wrong please.

On a secondary note -- what I would also like to do is to be able to record any sounds being played on the playback device not just ones played via irrkKlang in the current application. Is this possible?


erik
Registered User
Quote
2016-06-15 08:17:19

Are you sure the sample format and channel count is right?


Annon
Guest
Quote
2016-06-15 09:42:35

I managed to work it out in the end. I need to modify the Format.FrameCount to be set as follows:


Format.FrameCount = MySr.mData.size() / 4 ; // 4 == 2 (channels) * 2 (bytes).



I am still interested in any way to record any sounds being played on the playback device not just ones played via irrkKlang in the current application. So far I have not managed to get that working.

Thanks.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact