Ejemplo n.º 1
0
int RtInOut( void* outputBuffer, void* inputBuffer, unsigned int framesPerBuffer, 
			double streamTime, RtAudioStreamStatus status, void *userdata )
{
	if(!UNTZ::System::get()->getData()->isActive())
	{
		memset(outputBuffer, 0, sizeof(float) * framesPerBuffer * UNTZ::System::get()->getData()->getNumOutputChannels());
		return 0;
	}

	if(status)
		std::cout << "Stream underflow detected!" << std::endl;	
	AudioMixer *mixer = (AudioMixer*)userdata;
	mixer->process(0, NULL, UNTZ::System::get()->getData()->getNumOutputChannels(), (float*)outputBuffer, framesPerBuffer);
	
    // volume & clipping
    // HBS
    UInt32 samples = UNTZ::System::get()->getData()->getNumOutputChannels() * framesPerBuffer;
	float volume = mixer->getVolume();
    // TODO: doing an extra read/write here is painful...
    float *outB = (float*)outputBuffer;
	for (UInt32 k = 0; k < samples; ++k)
    {
        float val = *outB * volume;
        val = val > 1.0 ? 1.0 : val;
        val = val < -1.0 ? -1.0 : val;
        *(outB)++ = val;
    }

	return 0;
}
Ejemplo n.º 2
0
int RtInOut( void* outputBuffer, void* inputBuffer, unsigned int framesPerBuffer, 
			double streamTime, RtAudioStreamStatus status, void *userdata )
{
    LinuxSystemData *sysData = (LinuxSystemData *)userdata;
    UInt32 numOutputChannels = UNTZ::System::get()->getData()->getNumOutputChannels();
    UInt32 samples = numOutputChannels * framesPerBuffer;

	if(!UNTZ::System::get()->getData()->isActive())
	{
		memset(outputBuffer, 0, sizeof(float) * samples);
		return 0;
	}

    if(sysData->mOutputBuffer.size() < samples)
    {
        sysData->mOutputBuffer.resize(samples);
    }
    float *mixerOutputBuffer = (float*)&sysData->mOutputBuffer[0];
    
	if(status)
		std::cout << "Stream underflow detected!" << std::endl;	
	AudioMixer *mixer = &sysData->mMixer;
	mixer->process(0, NULL, numOutputChannels, mixerOutputBuffer, framesPerBuffer);
	
    // volume & clipping & interleaving
	float volume = mixer->getVolume();
    float *outB = (float*)outputBuffer;
    for(UInt32 i=0; i<framesPerBuffer; i++)
    {
        for(UInt32 j=0; j<numOutputChannels; j++)
        {
			float val = volume * mixerOutputBuffer[j*framesPerBuffer+i];
            val = val > 1.0 ? 1.0 : val;
            val = val < -1.0 ? -1.0 : val;
            *(outB)++ = val;
        }
    }    

	return 0;
}
void CSgSelectionPreparationBar::OnUpdateAudioSlider(CCmdUI *pCmdUI)
{
    if (m_pAvGrabber && 
        m_pAvGrabber->getAudioMixer() && 
        m_pAvGrabber->getAudioMixer()->getSourceCount() > 0)
        pCmdUI->Enable(true);
    else
        pCmdUI->Enable(false);

    if (m_pAvGrabber && GetKeyState(VK_LBUTTON) >= 0) // left mouse not key pressed)
    {
        AudioMixer *pAudioMixer = m_pAvGrabber->getAudioMixer();
        if (pAudioMixer) {
            UINT nMixerVolume = pAudioMixer->getVolume();
            if (nMixerVolume < 0)
                nMixerVolume = 0;

            if (nMixerVolume > 100)
                nMixerVolume = 100;

            m_sldAudioInputLevel.SetPos(100 - nMixerVolume);
        }
    }
}