Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > irrKlang
record what's being played through ISound*

petesound
Registered User
Quote
2016-01-30 17:54:36

Is it possible to record what is being played through ISound* as a final mixdown instead of input through mic?

myMusic = engine->play2D("song", true, false, true, ESM_AUTO_DETECT, true);

recorder->startRecordingBufferedAudio(22000, ESF_S16, 1);

Thanks for feedback!

Cheers,
Pete


petesound
Guest
Quote
2016-01-31 13:36:31

Hello,
After doing some research I implemented a class which derives from ISoundMixedOutputReceiver and ICapturedAudioDataReceiver to record a final mixdown of a song currently playing. If i print printf("Audio data size %d\n", data) from OnAudioDataReady( i actually receive data packages, but the recorded memory is always null.
What am I doing wrong?
Any help would be kindly appreciated!

Pete

Here is the cpp:

// IrrKl.cpp : Defines the entry point for the console application.

include "stdafx.h"
include <iostream>
include <string>
include "include/irrKlang.h"
include "include/ik_ISoundMixedOutputReceiver.h"
include "include/ik_IAudioRecorder.h"

using namespace irrklang;

pragma comment(lib, "irrKlang.lib")

class MySoundMixedOutputReceiver : public ISoundMixedOutputReceiver, public ICapturedAudioDataReceiver
{
public:
virtual void OnAudioDataReady(const void* data, int byteCount, int playbackrate)
{
//printf("Audio data size %d\n", data);
}

virtual void OnReceiveAudioDataStreamChunk(unsigned char *audioData, unsigned long lengthInBytes)
{
int total = 0;
for (unsigned long i = 0; i<lengthInBytes; i++)
if (total != 0) total += audioData[i];

printf("%.3f\n", ((float)total / lengthInBytes));
}
};


int main(int argc, const char** argv)
{

ISoundEngine* engine = createIrrKlangDevice(ESOD_WIN_MM);
if (!engine) return 0; // error starting up the engine

ISound* myMusic = engine->play2D("song.mp3", true, false, true, ESM_AUTO_DETECT, true);
IAudioRecorder* recorder = irrklang::createIrrKlangAudioRecorder(engine);

if (!engine) return 0;

if (myMusic) {

MySoundMixedOutputReceiver* receiver = new MySoundMixedOutputReceiver();
//record
recorder->startRecordingCustomHandledAudio(receiver, 22000, ESF_U8, 1);
engine->setMixedDataOutputReceiver(receiver);
std::cout << "recording started \n";
std::getchar();
//stop record
recorder->stopRecordingAudio();
std::cout << "recording stopped \n";
printf("\nRecording done, recorded %dms of audio.\n",
recorder->getAudioFormat().FrameCount * 1000 / recorder->getAudioFormat().SampleRate);
printf("Press any key to play back recorded audio...\n");
engine->stopAllSounds();
std::getchar();
// play the recorded audio
recorder->addSoundSourceFromRecordedAudio("myRecordedSong");
engine->play2D("myRecordedSong", true);
printf("\nPress any key to quit...");
std::getchar();
}

engine->drop();

return 0;
}


niko
Moderator
Quote
2016-01-31 14:47:17

Hm, are you hearing any sound while playing?


petesound
Guest
Quote
2016-01-31 16:56:53

Yes, sound playing works.


niko
Moderator
Quote
2016-02-01 03:12:16

Strange. You say
but the recorded memory is always null

Is the data pointer null? Or the content of the bytes?


petesound
Guest
Quote
2016-02-01 18:28:11

To answer your question OnAudioDataReady always receives data, but 0ms of audio are recorded and audio data is 0.

After some tinkering I found out that recording is only working if a microphone is plugged in (Then of course it gets the audio data). This may sound naive, but is it also possible to record what I am listening through play2D, without a microphone plugged in? The strange thing is, when a microphone is plugged in, it records the microphone with the correct level, but it also records the sound which is played through play2D with just 1/10 of the level. This is also true when I deactivate the power switch of the microphone-> It records 1/10 of the level of the input level. But as soon as I unplug the microphone I am not able to record what's played through play2D.
This is also true when MySoundMixedOutputReceiver is completely removed. (Class not instantiated and used) So this is more of a case of an interference.
So my question is, can I use MySoundMixedOutputReceiver to record what's playing through play2D and if yes, how would I connect it to the recorder?
MySoundMixedOutputReceiver* receiver = new MySoundMixedOutputReceiver();
engine->setMixedDataOutputReceiver(receiver);
recorder->startRecordingCustomHandledAudio(receiver, 22000, ESF_U8, 1);
(this would not work as I derive MySoundMixedOutputReceiver from ISoundMixedOutputReceiver, which is the wrong type for the first parameter of startRecordingCustomHandledAudio as it asks for ICapturedAudioDataReceiver)
So my second question is, if it is possible to convert my receiver to this type?

Finally, let me say your audio library is amazing and it would be great if you could help me out one more time!

Cheers, petesound


petesound
Guest
Quote
2016-02-02 09:55:26

i forgot to mention that i want to record play2d with some fx applied and get the final mixdown of it.


niko
Moderator
Quote
2016-02-03 03:50:41

About the level problem: This is likely a problem with your audio hardware/driver, there is nothing you can do about it. And I know no way to connect MySoundMixedOutputReceiver to the recorder.

You can only get the mixed audio data from a software device, and those don't support FX, so this likely won't work.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "?nternational" (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