Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
Capturing data from audio devices

Opifex
Guest
Quote
2014-07-01 11:52:04

I'm wondering if IrrKlang can capture audio streams from audio devices in the computer, and give me access to the captured buffer; anyone know if this is possible?

I'm using VoIP software where I can create virtual audio devices and pass audio streams into it, which then get played to people across the network. The only way I know of doing this is using the Windows API to capture the audio stream, but the Windows API is horrible to use compared to elegant IrrKlang code.

Example scenario:

Using C++, Visual Studio 2013

A person is talking on a mic, and is playing sound files through his speakers (Mic = input device, speakers = output device)

The audio data from both devices need to be captured into buffers and mixed together to a single audio stream.

The audio stream is then passed into the virtual audio device of the VoIP software. The audio stream needs to be passed to the VoIP function as a short* buffer.

Like I said, this can be done in WASAPI but I'm just looking for a nicer C++ solution to use. If IrrKlang can't do this can someone suggest another library?


erik
Registered User
Quote
2014-07-01 18:28:09

irrKlang can record audio, but you can only record, then stop recording, and _then_ access the audio data, and do whatever with that (like remixing). You cannot do this while recording is still active.


Opifex
Guest
Quote
2014-07-02 10:24:52

Thanks for the info.

I did some extra digging and found the code

OnReceiveAudioDataStreamChunk()

Seems like this is more appropriate for VoIP and my situation, can you tell me often this function gets called?

For my VoIP software, the most appropriate way to implement near real-time audio transmission is to pass in AudioData every 20ms.


erik
Registered User
Quote
2014-07-02 11:49:55

You are right, I didn't see that method of recording audio. So I guess what you need is possible with irrKlang. I don't know how fast this is and how often this will be called, best is to try it out. But knowing a bit about irrKlang, I think it will be something around realtime (so you will be ok with 20ms) and I think this probably depends on your audio driver and the recording format you are requesting.


Opifex
Guest
Quote
2014-07-03 10:48:14

Ahh excellent! this library sounds like it would solve all my problems. I don't have time to test it at this time though.. would be great to get confirmation from a Dev, which would mean an instant purchase for my project :)


niko
Moderator
Quote
2014-07-03 13:45:13

Erik is right in what he said. Also, best is to try out the library, also as he said, and see if it actually works for your case. You don't have to buy, it's free to try. Buy only once your product is finished. :)


Opifex
Guest
Quote
2014-07-09 13:18:20

I've started experimenting with the stuff we've discussed, but I need a bit of advice. I'm trying to create Sidetone for a headset (Playback mic recordings to headset).

I've created a class that inherits from "ICapturedAudioDataReceiver" so I could use "OnReceiveAudioDataStreamChunk". This function is now called constantly with audioData and a length which is good.

Now I need to figure out how to actually play that audioData to an output device. The only function I can see which I "think" is correct is to use "addSoundSourceFromPCMData" but my attempts to use it have failed.

Am I on the right track?


// derive a class from ICapturedAudioDataReceiver that receives the captured audio data
class SideToneGen : public ICapturedAudioDataReceiver
{
public:
SideToneGen(void)
{
sidetoneFormat.ChannelCount = 1;
sidetoneFormat.SampleFormat = ESF_U8;
sidetoneFormat.SampleRate = 22000;
sidetoneFormat.FrameCount = sidetoneFormat.ChannelCount * sidetoneFormat.getSampleSize();
};

virtual void OnReceiveAudioDataStreamChunk(unsigned char *audioData, unsigned long lengthInBytes);

ISoundEngine* enginePtr;
SAudioStreamFormat sidetoneFormat;
};

// Called often; Play mic audio straight back to the speakers
void SideToneGen::OnReceiveAudioDataStreamChunk(unsigned char *audioData, unsigned long lengthInBytes)
{
enginePtr->addSoundSourceFromPCMData(audioData, lengthInBytes, "SideToneAudio", sidetoneFormat); //????
enginePtr->play2D("SideToneAudio"); //????
}

int main(int argc, char ** argv)
{
// start sound engine
ISoundEngine* engine = createIrrKlangDevice(ESOD_WIN_MM);

if (!engine)
return 0;

// start listening to the input
IAudioRecorder* listener = createIrrKlangAudioRecorder(engine);
SideToneGen* sidetone = new SideToneGen();

sidetone->enginePtr = engine; //dirty

listener->startRecordingCustomHandledAudio(sidetone, 22000, ESF_U8, 1);


// loop indefinitely
while (true)
this_thread::sleep_for(chrono::milliseconds(100));


listener->drop();
engine->drop();

return 0;
}


Code sample came from another thread.

I figured it would be as simple as directing the audioData from "OnReceiveAudioDataStreamChunk" straight into "addSoundSourceFromPCMData". But when this function is called I get the error:

Cannot add sound source, it exists already: SideToneAudio

I don't actually understand this error because I thought "OnReceiveAudioDataStreamChunk" gives the audio buffer to the user, the data isn't stored internally to IrrKlang anymore.


erik
Registered User
Quote
2014-07-10 07:09:33

Your code is on the right track, I think.

Adding a sound source is a way to say the engine that there is this one chunk of data, and you want to name it like this, and that you want to play it from time to time with this name. So adding it multiple times doesn't make sense.

So what I would change is this: In OnReceiveAudioDataStreamChunk, record the data you get. Maybe in an array, maybe in a file. Once you are happy to play all of it, add it once as sound source, and you can play it then.


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