Detect if the host is exporting audio?


#1

Hi,

I like to add noise to the audio output of my plugin demos if the host is recording or is exporting audio, but the CurrentPositionInfo::isRecording flag is not set if the host exports audio (tested in BitWig).

The idea for a workaround: if the host exports audio we calculate more than one block in the time of one block, because exporting is usually faster. But I'm not sure if this is a good solution or does anybody know a better one?

    bool seems_to_record = false;
    const int64 current_time = Time::currentTimeMillis();
    const int64 block_difference = current_time - last_block_time;
    last_block_time = current_time;
    const int64 expected_time_per_block = samplesToMsFast(block_size,sample_rate);
    
    if( block_difference*2.5 < expected_time_per_block ) // 2 double + safety 0.5
    {
        if( ++safety_counter == 10 )
        {
            seems_to_record = true;
        }
    }
    else
    {
        // RESET
        safety_counter = 0;
        seems_to_record = false;
    }

    // ADD JUNK TO THE OUTPUT
    if( is_demo && seems_to_record )
    {
        // add noise to the buffer
    }

#2

Did you see isNonRealTime() in AudioProcessor? Seems like it does what you are looking for. http://www.juce.com/doc/classAudioProcessor#aed44cae950cdcf0d2283d875e036ff87

But I am not sure if it solves the initial question, if the audio stream is recorded, because nobody can stop you from exporting in realtime / recording in realtime. And second it depends if you trust the host, to set this flag always correctly.

EDIT: isRecording shows, if there are live inputs which implies that it can't be non realtime. But it does not say anything about if the output is being recorded to another memory... now I'm no longer sure, if I understood the problem correctly... ;-)


#3

Damn :D

Perfect, thanks!


#4

This was to fast. isNonRealtime() is always false for BitWig.


#5

EDIT: isRecording shows, if there are live inputs which implies that it can't be non realtime. But it does not say anything about if the output is being recorded to another memory... now I'm no longer sure, if I understood the problem correctly... ;-)

Hm, right. Damn again. BitWig was confusing me, there is just one way to record the audio in realtime and for that you have to enable the record button and BitWig sets the isRecording flag...

But then only the workaround from my first post left and a noise after time x for time y.

 

EDIT: "noise for time y after time x" will be added to the output in realtime mode.

EDIT: better will be: "for x samples after x samples"