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);
}
......
}
bool Encode(float *input, UINT numInputFrames, DataPacket &packet, QWORD ×tamp)
{
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);