Get PCM Audio data

kayvan

New Member
Now, I want to get the PCM audio data from from void OBS::MainAudioLoop() then write to decklink SDI card.

In void OBS::MainAudioLoop() -->

 

Lain

Forum Admin
Lain
Forum Moderator
Developer
I really wouldn't recommend doing this with OBS1 right now. It's going to cause you much pain and suffering. With obs-studio it is super simple and easy to do, it's much more worth it to wait.
 

kayvan

New Member
Sorry for the incomplete question:
I want get pcm data like this:
Code:
 List<float> mixBuffer, levelsBuffer;
mixBuffer.SetSize(audioSampleSize*2); 
levelsBuffer.SetSize(audioSampleSize*2);
 while (true) {
 OSSleep(5); //screw it, just run it every 5ms

 if (!bRunning)
 break;
.........
 while (QueryNewAudio()) {
 .......
//----------------------------------------------------------------------------
// mix mic and desktop sound
// also, it's perfectly fine to just mix into the returned buffer

if (bMicEnabled && micBuffer)
MixAudio(mixBuffer.Array(), micBuffer, audioSampleSize*2, bForceMicMono);

//----------------------------------------------------------------------------
memset(g_audioBuffer, 0, SDI_AUDIO_BUFFER_LEN);
memcpy(g_audioBuffer, mixBuffer.Array(), mixBuffer.Num());

EncodeAudioSegment(mixBuffer.Array(), audioSampleSize, timestamp);
}
......
}

The audioSampleSize is 480 when sampleRate is 48KHz, but mixBuffer only has 240 values, others are 0, why?

I also try to get PCM data before audio encoding:
AACEncoder:Encode()
Code:
    bool Encode(float *input, UINT numInputFrames, DataPacket &packet, QWORD &timestamp)
    {
        if(bFirstFrame)
        {
            curEncodeTimestamp = timestamp;
            bFirstFrame = false;
        }

        //------------------------------------------------

        QWORD curTimestamp = timestamp;

        UINT lastSampleSize = inputBuffer.Num();
        UINT numInputSamples = numInputFrames*2;
        inputBuffer.AppendArray(input, numInputSamples);

        int ret = 0;

        if(inputBuffer.Num() >= numReadSamples)
        {
            //now we have to upscale the floats.  fortunately we almost always have SSE
            UINT floatsLeft  = numReadSamples;
            float *inputTemp = inputBuffer.Array();
            if((UPARAM(inputTemp) & 0xF) == 0)
            {
                UINT alignedFloats = floatsLeft & 0xFFFFFFFC;

                for(UINT i=0; i<alignedFloats; i += 4)
                {
                    float *pos = inputTemp+i;
                    _mm_store_ps(pos, _mm_mul_ps(_mm_load_ps(pos), _mm_set_ps1(32767.0f)));
                }

                floatsLeft &= 0x3;
                inputTemp  += alignedFloats;
            }

            if(floatsLeft)
            {
                for(UINT i=0; i<floatsLeft; i++)
                    inputTemp[i] *= 32767.0f;
            }

            //----------------------------------------------------------------------------
            memset(g_audioBuffer, 0, SDI_AUDIO_BUFFER_LEN);
            memcpy(g_audioBuffer, (int32_t*)inputBuffer.Array(), inputBuffer.Num());

            ret = faacEncEncode(faac, (int32_t*)inputBuffer.Array(), numReadSamples, aacBuffer.Array()+2, outputSize);

Data in inputBuffer has been converted to type in32_t, but it seems not PCM data I need.
Any suggestions are very helpful !
Thanks,

Kayvan
 
Top