示例#1
0
Simulator::Result
ExampleProducer::DoProduce()
{
    int x = m_counter;

    if (!m_fifo.Push(x))
    {
	std::cout << "cycle " << GetKernel()->GetCycleNo() << ": producer stalls" << std::endl;
	return Simulator::FAILED;
    }
    COMMIT {
	std::cout << "cycle " << GetKernel()->GetCycleNo() << ": producer produces " << x << std::endl;
	++m_counter;
    }
    return Simulator::SUCCESS;
}
RString RageSoundDriver_ALSA9_Software::Init()
{
	RString sError = LoadALSA();
	if( sError != "" )
		return ssprintf( "Driver unusable: %s", sError.c_str() );

	g_iMaxWriteahead = safe_writeahead;
	RString sys;
	int vers;
	GetKernel( sys, vers );
	LOG->Trace( "OS: %s ver %06i", sys.c_str(), vers );
	if( sys == "Linux" && vers >= 20600 )
		g_iMaxWriteahead = g_iMaxWriteahead_linux_26;

	if( PREFSMAN->m_iSoundWriteAhead )
		g_iMaxWriteahead = PREFSMAN->m_iSoundWriteAhead;

	m_pPCM = new Alsa9Buf();
	sError = m_pPCM->Init( channels,
			g_iMaxWriteahead,
			g_iMaxWriteahead / num_chunks,
			PREFSMAN->m_iSoundPreferredSampleRate );
	if( sError != "" )
		return sError;

	m_iSampleRate = m_pPCM->GetSampleRate();
	
	StartDecodeThread();
	
	m_MixingThread.SetName( "RageSoundDriver_ALSA9_Software" );
	m_MixingThread.Create( MixerThread_start, this );

	return "";
}
示例#3
0
bool Menus::MenuCaptureEventHandler(unsigned long event,MenuItem* sender)
{
	UNREFERENCED_PARAMETER(event);

	// Back
	if(sender->GetId() == GetKernel()->GetAudio()->GetSourcesCount()+1)
	{
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(0); // Main menu
		return true;
	}

	// Set the selected vis
	if(sender->GetId())
		return GetKernel()->GetAudio()->SetSource(sender->GetId()-1);

	return false;
}
示例#4
0
bool Menus::MenuVisEventHandler(unsigned long event,MenuItem* sender)
{
	UNREFERENCED_PARAMETER(event);

	// Back
	if(sender->GetId() == GetKernel()->GetGraphics()->GetVisualizationCount()+1)
	{
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(0); // Main menu
		return true;
	}

	// Set the selected vis
	if(sender->GetId())
		return GetKernel()->GetGraphics()->SetVisualization(sender->GetId()-1);

	return false;
}
示例#5
0
const wchar_t* Menus::MenuInfoItemTextHandler(MenuItem* sender)
{
	static String string;

	switch(sender->GetId())
	{
	case 1: // Current vis
		string = GetKernel()->GetGraphics()->GetVisualizationName(GetKernel()->GetGraphics()->GetVisualizationIndex());
		string.ToLower();
		return string;

	case 2: // Curent color preset
		string = GetKernel()->GetGraphics()->GetColorPresetName(GetKernel()->GetGraphics()->GetColorPresetIndex());
		string.ToLower();
		return string;
	}

	return false;
}
示例#6
0
bool TrackBar::OnRender(void)
{
	if(!GetVisible())
		return false;

	Rect box = GetBoundingBox();

	GetKernel()->GetUserInterface()->DrawTrackBar(box,GetTrackBox(),GetTrackRange(),GetTrackValue(),false,GetEnabled(),GetFocused());

	return Control::OnRender();
}
示例#7
0
Simulator::Result
ExampleConsumer::DoConsume()
{
    assert(!m_fifo.Empty());
    const int &x = m_fifo.Front();

    COMMIT {
	std::cout << "cycle " << GetKernel()->GetCycleNo() << ": consumer takes " << x << std::endl;
    }
    m_fifo.Pop();
    return Simulator::SUCCESS;
}
示例#8
0
bool Scope::Render()
{
	// This will contain the line coordinates
	Vector2 lines[ANALYZER_FFTBUFFERSIZE/2];

	// Set the line width
	static const float width = 2.0f;
	static const float radius = 160.0f;

	// Set the coordinates for the shadow
	for(unsigned long x = 0; x < ANALYZER_FFTBUFFERSIZE/2; ++x)
		lines[x] = Vector2(40.0f+2.0f+1.4f*x,250.0f+2.0f+GetKernel()->GetAudio()->GetScope(x)*radius);

	// Create the shadow color
	Color color(GetKernel()->GetGraphics()->GetColorPreset()->foreground);
	color.Shadow();

	// Draw the line shadow
	GetKernel()->GetGraphics()->DrawLines(lines,ANALYZER_FFTBUFFERSIZE/2,color,width);

	// Set the coordinates for the scope line
	for(unsigned long x = 0; x < ANALYZER_FFTBUFFERSIZE/2; ++x)
		lines[x] = Vector2(40.0f+1.4f*x,250.0f+GetKernel()->GetAudio()->GetScope(x)*radius);

	// Draw the scope line
	GetKernel()->GetGraphics()->DrawLines(lines,ANALYZER_FFTBUFFERSIZE/2,GetKernel()->GetGraphics()->GetColorPreset()->foreground,width);

	return true;
}
示例#9
0
bool Menus::MenuEventHandler(unsigned long event,MenuItem* sender)
{
	UNREFERENCED_PARAMETER(event);

	switch(sender->GetId())
	{
	case 1: // Visualizations menu
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(5);	// Vis menu
		break;

	case 2: // Color presets menu
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(6);	// Presets menu
		break;

	case 3: // Options
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(3);	// Options menu
		return true;

	case 4: // Capture Source
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(2);	// Capture Source menu
		return true;

	case 5: // Info
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(4);	// Info menu
		return true;

	case 6: // Close
		//PostQuitMessage(0);
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(1);	// Exit menu
		return true;
	}

	return false;
}
示例#10
0
bool Menus::MenuInfoEventHandler(unsigned long event,MenuItem* sender)
{
	UNREFERENCED_PARAMETER(event);

	switch(sender->GetId())
	{
	case 6: // Back
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(0); // Main menu
		return true;
	}

	return false;
}
示例#11
0
void Interpolator::Update(void)
{
	if(!mStates.GetSize())
		return;

	if(mTime == mStates[mDestination])
		return;

	if(mTime < mStates[mDestination])
	{
		mTime += mSpeed * GetKernel()->GetElapsedTime();

		if(mTime > mStates[mDestination])
			mTime = mStates[mDestination];
	}
	else
	{
		mTime -= mSpeed * GetKernel()->GetElapsedTime();

		if(mTime < mStates[mDestination])
			mTime = mStates[mDestination];
	}
}
示例#12
0
   void GenericModel::plotOn(RooPlot* frame)
   {
      // Add the pseudo-PDF to the RooPlot
      // We plot:
      //    - the fit result with a 1-sigma error band;
      //    - each of the individual kernel PDF's

      //plot fit result with 1-sigma error band
      fModelPseudoPDF->plotOn(frame, VisualizeError(*fLastFit, 1), FillColor(kMagenta));
      fModelPseudoPDF->plotOn(frame);
      //plot individual kernels
      for (int i = 0; i < GetNumberOfDataSets(); i++) {
         fModelPseudoPDF->plotOn(frame, Components(*GetKernel(i)), LineStyle(kDashed), LineColor(kBlue + 4 * i));
      }
   }
示例#13
0
bool Menus::MenuExitEventHandler(unsigned long event,MenuItem* sender)
{
	UNREFERENCED_PARAMETER(event);

	switch(sender->GetId())
	{
	case 1: // Yes
		PostQuitMessage(0);
		return true;
		
	case 2: // No
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(0);	// Main menu
		return true;
	}

	return false;
}
示例#14
0
bool Texture::Create(unsigned long width,unsigned long height,unsigned long levels,Usage usage,Format format,Pool pool)
{
	ASSERT(!mCreated);

	if(usage == UsageNone)
		mUsage = NULL;

	if(usage == UsageDynamic)
		mUsage = D3DUSAGE_DYNAMIC;

	if(usage == UsageRenderTarget)
		mUsage = D3DUSAGE_RENDERTARGET;

	if(format == FormatUnknown)
		mFormat = D3DFMT_UNKNOWN;

	if(format == FormatA8R8G8B8)
		mFormat = D3DFMT_A8R8G8B8;

	if(format == FormatV8U8)
		mFormat = D3DFMT_V8U8;

	if(format == FormatDXT5)
		mFormat = D3DFMT_DXT5;

	if(pool == PoolDefault)
		mPool = D3DPOOL_DEFAULT;

	if(pool == PoolManaged)
		mPool = D3DPOOL_MANAGED;

	mWidth = width;
	mHeight = height;
	mLevels = levels;

	if(FAILED(GetKernel()->GetGraphics()->GetDevice()->CreateTexture(mWidth,mHeight,mLevels,mUsage,mFormat,mPool,&mTexture,NULL)))
	{
		TRACE(L"Failed to create texture.\n");
		return false;
	}

	mCreated = true;

	return true;
}
示例#15
0
void ArchHooks_Unix::DumpDebugInfo()
{
	CString sys;
	int vers;
	GetKernel( sys, vers );
	LOG->Info( "OS: %s ver %06i", sys.c_str(), vers );

#if defined(CRASH_HANDLER)
	LOG->Info( "Crash backtrace component: %s", BACKTRACE_METHOD_TEXT );
	LOG->Info( "Crash lookup component: %s", BACKTRACE_LOOKUP_METHOD_TEXT );
#if defined(BACKTRACE_DEMANGLE_METHOD_TEXT)
	LOG->Info( "Crash demangle component: %s", BACKTRACE_DEMANGLE_METHOD_TEXT );
#endif
#endif

	LOG->Info( "Runtime library: %s", LibcVersion().c_str() );
	LOG->Info( "Threads library: %s", ThreadsVersion().c_str() );
}
示例#16
0
bool Texture::OnResetDevice(void)
{
	if(mPool == D3DPOOL_DEFAULT && mBuffer)
	{
		//if(FAILED(GetDynamicD3DX()->D3DXCreateTextureFromFileInMemoryEx(GetKernel()->GetGraphics()->GetDevice(),mBuffer,mSize,mWidth,mHeight,mMipmaps,mUsage,mFormat,mPool,D3DX_DEFAULT,D3DX_DEFAULT,NULL,NULL,NULL,&mTexture)))
		//{
		//	Trace(L"Failed to recreate texture.\n");
		//	return false;
		//}

		Targa tga;

		if(!tga.LoadFromMemory(mBuffer,mSize))
		{
			TRACE(L"Failed to load texture.\n");
			return false;
		}

		mWidth =  tga.GetWidth();
		mHeight = tga.GetHeight();

		if(FAILED(GetKernel()->GetGraphics()->GetDevice()->CreateTexture(mWidth,mHeight,mLevels,mUsage|D3DUSAGE_DYNAMIC,mFormat,mPool,&mTexture,NULL)))
		{
			TRACE(L"Failed to create texture.\n");
			return false;
		}
		
		D3DLOCKED_RECT rect;

		if(FAILED(mTexture->LockRect(0,&rect,NULL,D3DLOCK_DISCARD)))
		{
			TRACE(L"Failed to lock texture.\n");
			return false;
		}

		CopyMemory(rect.pBits,tga.GetData(),tga.GetBitsPerPixel()*tga.GetWidth()*tga.GetHeight()/8);

		mTexture->UnlockRect(0);
	}

	return true;
}
示例#17
0
    void DeviceClw::Execute(Function const* func, std::uint32_t queue, size_t global_size, size_t local_size, Event** e)
    {
        auto func_clw = static_cast<FunctionClw const*>(func);

        try
        {
            CLWEvent event = m_context.Launch1D(queue, global_size, local_size, func_clw->GetKernel());

            if (e)
            {
                auto event_clw = CreateEventClw();
                event_clw->SetEvent(event);
                *e = event_clw;
            }
        }
        catch (CLWException& e)
        {
            throw ExceptionClw(e.what());
        }
    }
RageSound_ALSA9_Software::RageSound_ALSA9_Software()
{
	CString err = LoadALSA();
	if( err != "" )
		RageException::ThrowNonfatal("Driver unusable: %s", err.c_str());
try {
	shutdown = false;

	max_writeahead = safe_writeahead;
	CString sys;
	int vers;
	GetKernel( sys, vers );
	LOG->Trace( "OS: %s ver %06i", sys.c_str(), vers );
	if( sys == "Linux" && vers >= 20600 )
		max_writeahead = max_writeahead_linux_26;

	if( PREFSMAN->m_iSoundWriteAhead )
		max_writeahead = PREFSMAN->m_iSoundWriteAhead;

	pcm = new Alsa9Buf( Alsa9Buf::HW_DONT_CARE, channels );

	samplerate = pcm->FindSampleRate( samplerate );
	pcm->SetSampleRate( samplerate );
	LOG->Info( "ALSA: Software mixing at %ihz", samplerate );
	
	pcm->SetWriteahead( max_writeahead );
	pcm->SetChunksize( max_writeahead / num_chunks );
	pcm->LogParams();
	
	StartDecodeThread();
	
	MixingThread.SetName( "RageSound_ALSA9_Software" );
	MixingThread.Create( MixerThread_start, this );
} catch(...) {
	UnloadALSA();
	throw;
}

}
CString RageSoundDriver_ALSA9_Software::Init()
{
	CString sError = LoadALSA();
	if( sError != "" )
		return ssprintf( "Driver unusable: %s", sError.c_str() );

	max_writeahead = safe_writeahead;
	CString sys;
	int vers;
	GetKernel( sys, vers );
	LOG->Trace( "OS: %s ver %06i", sys.c_str(), vers );
	if( sys == "Linux" && vers >= 20600 )
		max_writeahead = max_writeahead_linux_26;

	if( PREFSMAN->m_iSoundWriteAhead )
		max_writeahead = PREFSMAN->m_iSoundWriteAhead;

	pcm = new Alsa9Buf();
	sError = pcm->Init( Alsa9Buf::HW_DONT_CARE, channels );
	if( sError != "" )
		return sError;

	samplerate = pcm->FindSampleRate( samplerate );
	pcm->SetSampleRate( samplerate );
	LOG->Info( "ALSA: Software mixing at %ihz", samplerate );
	
	pcm->SetWriteahead( max_writeahead );
	pcm->SetChunksize( max_writeahead / num_chunks );
	pcm->LogParams();
	
	StartDecodeThread();
	
	MixingThread.SetName( "RageSoundDriver_ALSA9_Software" );
	MixingThread.Create( MixerThread_start, this );

	return "";
}
示例#20
0
const wchar_t* Menus::MenuItemTextHandler(MenuItem* sender)
{
	switch(sender->GetId())
	{
	case 1: // Draw Peaks
		if(GetKernel()->GetGraphics()->GetDrawPeaks())
			return L"draw peaks: \002on\001";
		else
			return L"draw peaks: \002off\001";

	case 2: // Draw help text
		if(GetKernel()->GetGraphics()->GetDrawHelp())
			return L"draw help text: \002on\001";
		else
			return L"draw help text: \002off\001";

	case 3: // Draw about text
		if(GetKernel()->GetGraphics()->GetDrawAbout())
			return L"draw about text: \002on\001";
		else
			return L"draw about text: \002off\001";

	case 4: // Draw output strings
		if(GetKernel()->GetGraphics()->GetDrawOutputStrings())
			return L"draw output: \002on\001";
		else
			return L"draw output: \002off\001";

	case 5: // Draw fps
		if(GetKernel()->GetGraphics()->GetDrawFps())
			return L"draw fps: \002on\001";
		else
			return L"draw fps: \002off\001";

	case 6: // Draw visualization name
		if(GetKernel()->GetGraphics()->GetDrawVisualizationName())
			return L"draw visualization name: \002on\001";
		else
			return L"draw visualization name: \002off\001";

	case 7: // Draw timer
		if(GetKernel()->GetGraphics()->GetDrawTimer())
			return L"draw timer: \002on\001";
		else
			return L"draw timer: \002off\001";

	case 8: // Keyboard LED
		if(GetKernel()->GetLed())
			return L"keyboard LED: \002on\001";
		else
			return L"keyboard LED: \002off\001";

	case 9: // Eq Falloff
		if(GetKernel()->GetAudio()->GetEqFalloff() == -1)
			return L"eq falloff: \002slow\001";
		else if(GetKernel()->GetAudio()->GetEqFalloff() == 0)
			return L"eq falloff: \002normal\001";
		else if(GetKernel()->GetAudio()->GetEqFalloff() == 1)
			return L"eq falloff: \002fast\001";
		else
			return L"eq falloff: \002unknown\001";

	case 10: // Peak fallof
		if(GetKernel()->GetAudio()->GetPeakFalloff() == -1)
			return L"peak falloff: \002slow\001";
		else if(GetKernel()->GetAudio()->GetPeakFalloff() == 0)
			return L"peak falloff: \002normal\001";
		else if(GetKernel()->GetAudio()->GetPeakFalloff() == 1)
			return L"peak falloff: \002fast\001";
		else
			return L"peak falloff: \002unknown\001";

	case 11: // Peak delay
		if(GetKernel()->GetAudio()->GetPeakDelay() == -1)
			return L"peak delay: \002low\001";
		else if(GetKernel()->GetAudio()->GetPeakDelay() == 0)
			return L"peak delay: \002normal\001";
		else if(GetKernel()->GetAudio()->GetPeakDelay() == 1)
			return L"peak delay: \002high\001";
		else
			return L"peak delay: \002unknown\001";
	}

	return NULL;
}
示例#21
0
bool TrackBar::OnEventMouse(Event event,WPARAM wparam,LPARAM lparam)
{
	if(!GetVisible() || !GetEnabled())
		return false;

	switch(event)
	{
	case EventLeftButtonDown:
		if(PointInTrack(*(Point*)wparam))
		{
			if(!GetFocused())
				Focus();

			mTracking = true;
			mTrackingValue = mValue;
			mTrackingPosition = ((Point*)wparam)->x - GetTrackBox().GetCenter().x;

			SetCapture(GetKernel()->GetWindowHandle());

			return true;
		}

		if(PointIn(*(Point*)wparam))
		{
			if(!GetFocused())
				Focus();

			if(((Point*)wparam)->x > GetTrackBox().GetCenter().x)
			{
				if(GetTrackValue() < GetTrackRange())
					SetTrackValue(GetTrackValue() + 1);
			}
			else
			{
				if(GetTrackValue())
					SetTrackValue(GetTrackValue() - 1);
			}

			return true;
		}

		break;

	case EventLeftButtonUp:
		if(mTracking)
		{
			mTracking = false;

			ReleaseCapture();

			return true;
		}
		break;

	case EventMouseMove:
		if(mTracking)
		{
			Point delta = *(Point*)wparam;

			delta.x -= GetScreenPosition().x + mTrackingPosition;

			float val = (float)GetBoundingBox().GetWidth() / (float)GetTrackRange();

			if((float)delta.x / val > (float)GetTrackRange())
				SetTrackValue(GetTrackRange());
			else if((float)delta.x / val < 0.0f)
				SetTrackValue(0);
			else
				SetTrackValue((float)delta.x / val);

			if(GetParent())
				GetParent()->OnEvent(EventChildCommand,ControlEventTrackChange,(LPARAM)this);
		}

		break;
	}

	return Control::OnEventMouse(event,wparam,lparam);
}
示例#22
0
bool Texture::Create(const unsigned char* data,unsigned long size,unsigned long width,unsigned long height,unsigned long mipmaps,Usage usage,Format format,Pool pool)
{
	ASSERT(!mCreated);

	if(usage == UsageNone)
		mUsage = NULL;

	if(usage == UsageDynamic)
		mUsage = D3DUSAGE_DYNAMIC;

	if(usage == UsageRenderTarget)
		mUsage = D3DUSAGE_RENDERTARGET;

	if(format == FormatUnknown)
		mFormat = D3DFMT_UNKNOWN;

	if(format == FormatA8R8G8B8)
		mFormat = D3DFMT_A8R8G8B8;

	if(format == FormatV8U8)
		mFormat = D3DFMT_V8U8;

	if(format == FormatDXT5)
		mFormat = D3DFMT_DXT5;

	if(pool == PoolDefault)
		mPool = D3DPOOL_DEFAULT;

	if(pool == PoolManaged)
		mPool = D3DPOOL_MANAGED;

	if(mBuffer)
	{
		delete[] mBuffer;
		mBuffer = NULL;
	}

	mSize = size;
	mBuffer = new unsigned char[mSize];
	if(!mBuffer)
	{
		TRACE(L"Failed to allocate local texture data buffer of %u bytes.\n",mSize);
		return false;
	}

	CopyMemory(mBuffer,data,mSize);

	mWidth = width;
	mHeight = height;
	mMipmaps = mipmaps;

	//if(FAILED(GetDynamicD3DX()->D3DXCreateTextureFromFileInMemoryEx(GetKernel()->GetGraphics()->GetDevice(),mBuffer,mSize,mWidth,mHeight,mMipmaps,mUsage,mFormat,mPool,D3DX_DEFAULT,D3DX_DEFAULT,NULL,NULL,NULL,&mTexture)))
	//{
	//	Trace(L"Failed to load texture data.\n");
	//	return false;
	//}

	Targa tga;

	if(!tga.LoadFromMemory(mBuffer,mSize))
	{
		TRACE(L"Failed to load texture.\n");
		return false;
	}

	mWidth =  tga.GetWidth();
	mHeight = tga.GetHeight();

	if(FAILED(GetKernel()->GetGraphics()->GetDevice()->CreateTexture(mWidth,mHeight,mLevels,mUsage|D3DUSAGE_DYNAMIC,mFormat,mPool,&mTexture,NULL)))
	{
		TRACE(L"Failed to create texture.\n");
		return false;
	}
	
	D3DLOCKED_RECT rect;

	if(FAILED(mTexture->LockRect(0,&rect,NULL,D3DLOCK_DISCARD)))
	{
		TRACE(L"Failed to lock texture.\n");
		return false;
	}

	CopyMemory(rect.pBits,tga.GetData(),tga.GetBitsPerPixel()*tga.GetWidth()*tga.GetHeight()/8);

	mTexture->UnlockRect(0);

	if(mPool != D3DPOOL_DEFAULT)
		SAFEDELETE(mBuffer);

	mCreated = true;

	return true;
}
//////////////////////////////////////////////////////////////////////////
// Partial-Gram-Schmidt
TPartialGS::TPartialGS(PSVMTrainSet BigSet, const int& Dim, const double& Eps) {
    IAssert(Dim <= BigSet->Len() && 0.0 <= Eps && Eps < 1.0);
    int Len = BigSet->Len();

    TVec<TKeyDat<TFlt, TBool> > NiV(Len);
    for (int i = 0; i < Len; i++) {
        //NiV[i].Key = BigSet->DotProduct(i, i);
        NiV[i].Key = BigSet->GetNorm2(i);
        NiV[i].Dat = false;
        IAssertR(NiV[i].Key.Val > 0.0 && _isnan(NiV[i].Key.Val) == 0, 
                 TInt::GetStr(i) + TStr(":") + TFlt::GetStr(NiV[i].Key));
    }
    R.Gen(Dim, 0);
    //for (i = 0; i < Dim; i++) R[i].Gen(Len-i);
    IdV.Gen(Len);
    for (int i = 0; i < Len; i++) IdV[i] = i;

    TFltV BlufV(Dim, 0); int max = -1;
    for (int j = 0; j < Dim; j++) {
        // find element with bigest residual norm
        max = -1;
        for (int t = 0, l = Len; t < l; t++)
            if (!NiV[t].Dat && (max == -1 || NiV[t].Key > NiV[max].Key)) max = t;

        // if max residual norm is reached
        if (NiV[max].Key.Val < Eps) break;
        //printf("(%.2f)", NiV[max].Key.Val);

        // permute j-th and max-th column of R
        NiV[max].Dat = true;
        int mid = IdV.SearchForw(max, j);
        { int tmp = IdV[j]; IdV[j] = max; IdV[mid] = tmp; }
        for (int t = 0; t < j; t++) {
            double tmp = R[t][j-t];
            R[t][j-t] = R[t][mid-t];
            R[t][mid-t] = tmp;
        }

        // calculate j-th row of R and update NiV (residual norms)
        if (-0.001 < NiV[max].Key.Val && NiV[max].Key.Val < 0) NiV[max].Key.Val = 0.0;
        IAssertR(NiV[max].Key.Val >= 0.0, TInt::GetStr(j) + TStr(":") + TFlt::GetStr(NiV[max].Key.Val));
        IAssert(R.Len() == j);
        R.Add(TFltV()); R[j].Gen(Len-j); // NEW
        R[j][0] = sqrt(NiV[max].Key.Val);
        BlufV.Add(NiV[IdV[j]].Key.Val);
        for (int i = j+1; i < Len; i++) {
            double RR = BigSet->DotProduct(IdV[i], IdV[j]);
            for (int t = 0; t < j; t++)
                RR -= R[t][j-t] * R[t][i-t];
            IAssertR(NiV[IdV[j]].Key.Val>0, TInt::GetStr(i));
            RR /= sqrt(NiV[IdV[j]].Key.Val);
            IAssertR(_isnan(RR) == 0, TInt::GetStr(IdV[j]) + TStr(":") + TFlt::GetStr(NiV[IdV[j]].Key.Val));
            R[j][i-j] = RR;
            NiV[IdV[i]].Key -= RR*RR;
        }
    }

    if (max == -1) max = 0;
    printf("stoped at %d/%d with residual norm %.3f\n", R.Len(), BigSet->Len(), NiV[max].Key.Val);

    NormV.Gen(Len);
    VecNormV.Gen(Len);
    for (int i = 0; i < Len; i++) {
        NormV[i] = NiV[IdV[i]].Key;
        VecNormV[i] = GetKernel(i,i);
    }
}
示例#24
0
// the process code  that the host sees
static OfxStatus render( OfxImageEffectHandle  instance,
                         OfxPropertySetHandle inArgs,
                         OfxPropertySetHandle outArgs)
{
  // get the render window and the time from the inArgs
  OfxTime time;
  OfxRectI renderWindow;
  OfxStatus status = kOfxStatOK;

  gPropHost->propGetDouble(inArgs, kOfxPropTime, 0, &time);
  gPropHost->propGetIntN(inArgs, kOfxImageEffectPropRenderWindow, 4, &renderWindow.x1);

  // Retrieve instance data associated with this effect
  MyInstanceData *myData = getMyInstanceData(instance);

  // property handles and members of each image
  OfxPropertySetHandle sourceImg = NULL, outputImg = NULL;
  int srcRowBytes, srcBitDepth, dstRowBytes, dstBitDepth;
  bool srcIsAlpha, dstIsAlpha;
  OfxRectI dstRect, srcRect;
  void *src, *dst;

  DPRINT(("Render: window = [%d, %d - %d, %d]\n",
	  renderWindow.x1, renderWindow.y1,
	  renderWindow.x2, renderWindow.y2));

  int isOpenCLEnabled = 0;
  if (gHostSupportsOpenCL)
  {
      gPropHost->propGetInt(inArgs, kOfxImageEffectPropOpenCLEnabled, 0, &isOpenCLEnabled);
      DPRINT(("render: OpenCL rendering %s\n", isOpenCLEnabled ? "enabled" : "DISABLED"));
  }

  cl_context clContext = NULL;
  cl_command_queue cmdQ = NULL;
  cl_device_id deviceId = NULL;
  if (isOpenCLEnabled)
  {
      void* voidPtrCmdQ;
      gPropHost->propGetPointer(inArgs, kOfxImageEffectPropOpenCLCommandQueue, 0, &voidPtrCmdQ);
      cmdQ = reinterpret_cast<cl_command_queue>(voidPtrCmdQ);

      clGetCommandQueueInfo(cmdQ, CL_QUEUE_CONTEXT, sizeof(cl_context), &clContext, NULL);
      clGetCommandQueueInfo(cmdQ, CL_QUEUE_DEVICE, sizeof(cl_device_id), &deviceId, NULL);
  }
  else
  {
      clContext = GetContext(deviceId);
      cmdQ = clCreateCommandQueue(clContext, deviceId, 0, NULL);
  }

  char deviceName[128];
  clGetDeviceInfo(deviceId, CL_DEVICE_NAME, 128, deviceName, NULL);
  DPRINT(("Using %s for plugin\n", deviceName));

  cl_kernel kernel = GetKernel(clContext);

  // get the source image
  sourceImg = ofxuGetImage(myData->sourceClip, time, srcRowBytes, srcBitDepth, srcIsAlpha, srcRect, src);

  // get the output image
  outputImg = ofxuGetImage(myData->outputClip, time, dstRowBytes, dstBitDepth, dstIsAlpha, dstRect, dst);

  // get the scale parameter
  double rGain = 1, gGain = 1, bGain = 1;
  gParamHost->paramGetValueAtTime(myData->rGainParam, time, &rGain);
  gParamHost->paramGetValueAtTime(myData->gGainParam, time, &gGain);
  gParamHost->paramGetValueAtTime(myData->bGainParam, time, &bGain);
  DPRINT(("Gain(%f %f %f)\n", rGain, gGain, bGain));

  float w = (renderWindow.x2 - renderWindow.x1);
  float h = (renderWindow.y2 - renderWindow.y1);

  const size_t rowSize = w * 4 * sizeof(float);

  if (isOpenCLEnabled)
  {
      DPRINT(("Using OpenCL transfers (same device)\n"));

      RunKernel(cmdQ, deviceId, kernel, w, h, rGain, gGain, bGain, (cl_mem)src, (cl_mem)dst);
  }
  else
  {
      DPRINT(("Using CPU transfers\n"));

      const size_t bufferSize = w * h * 4 * sizeof(float);

      // Allocate the temporary buffers on the plugin device
      cl_mem inBuffer = clCreateBuffer(clContext, CL_MEM_READ_ONLY, bufferSize, NULL, NULL);
      cl_mem outBuffer = clCreateBuffer(clContext, CL_MEM_WRITE_ONLY, bufferSize, NULL, NULL);

      // Copy the buffer from the CPU to the plugin device
      clEnqueueWriteBuffer(cmdQ, inBuffer, CL_TRUE, 0, bufferSize, src, 0, NULL, NULL);

      RunKernel(cmdQ, deviceId, kernel, w, h, rGain, gGain, bGain, inBuffer, outBuffer);

      // Copy the buffer from the plugin device to the CPU
      clEnqueueReadBuffer(cmdQ, outBuffer, CL_TRUE, 0, bufferSize, dst, 0, NULL, NULL);

      clFinish(cmdQ);

      // Free the temporary buffers on the plugin device
      clReleaseMemObject(inBuffer);
      clReleaseMemObject(outBuffer);
  }

  if (sourceImg)
  {
      gEffectHost->clipReleaseImage(sourceImg);
  }

  if (outputImg)
  {
      gEffectHost->clipReleaseImage(outputImg);
  }

  return status;
}
示例#25
0
bool Menus::CreateMenus()
{
	// Build the menus
	Menu* menuMain = new Menu;
	ASSERT(menuMain);

	menuMain->AddItem(new MenuLabel(MenuItem::Title,L"main menu",0,true,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Label,L"visualizations",1,false,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Label,L"color presets",2,false,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Label,L"options",3,false,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Label,L"capture source",4,false,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Label,L"info",5,false,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuMain->AddItem(new MenuLabel(MenuItem::Label,L"close",6,false,NULL));

	menuMain->SetSelectedFirstValid();
	menuMain->SetEventHandler(MenuEventHandler);

	mMenuRoot.AddMenu(menuMain);

	Menu* menuExit = new Menu;
	ASSERT(menuExit);

	menuExit->AddItem(new MenuLabel(MenuItem::Title,L"close",0,true,NULL));
	menuExit->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));
	menuExit->AddItem(new MenuLabel(MenuItem::Label,L"yes",1,false,NULL));
	menuExit->AddItem(new MenuLabel(MenuItem::Label,L"no",2,false,NULL));

	menuExit->SetSelected(3);	// No
	menuExit->SetEventHandler(MenuExitEventHandler);

	mMenuRoot.AddMenu(menuExit);

	Menu* menuCapture = new Menu;
	ASSERT(menuCapture);

	menuCapture->AddItem(new MenuLabel(MenuItem::Title,L"capture source menu",0,true,NULL));
	menuCapture->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));

	// Add the capture sources
	for(unsigned long i = 0; i < GetKernel()->GetAudio()->GetSourcesCount(); ++i)
		menuCapture->AddItem(new MenuLabel(MenuItem::Label,GetKernel()->GetAudio()->GetSource(i),i+1,false,NULL));

	if(!GetKernel()->GetAudio()->GetSourcesCount())
		menuCapture->AddItem(new MenuLabel(MenuItem::Label,L"no capture sources",1,true,NULL));

	menuCapture->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuCapture->AddItem(new MenuLabel(MenuItem::Label,L"back",GetKernel()->GetAudio()->GetSourcesCount()+1,false,NULL));

	menuCapture->SetSelectedFirstValid();
	menuCapture->SetEventHandler(MenuCaptureEventHandler);

	mMenuRoot.AddMenu(menuCapture);

	Menu* menuOptions = new Menu;
	ASSERT(menuOptions);

	menuOptions->AddItem(new MenuLabel(MenuItem::Title,L"options menu",0,true,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,1,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,2,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,3,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,4,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,5,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,6,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,7,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,8,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,9,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,10,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,NULL,11,false,MenuItemTextHandler));
	menuOptions->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,L"write config",12,false,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,L"read config",13,false,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuOptions->AddItem(new MenuLabel(MenuItem::Label,L"back",14,false,NULL));

	menuOptions->SetSelectedFirstValid();
	menuOptions->SetEventHandler(MenuOptionsEventHandler);

	mMenuRoot.AddMenu(menuOptions);

	Menu* menuInfo = new Menu;
	ASSERT(menuInfo);

	menuInfo->AddItem(new MenuLabel(MenuItem::Title,L"info menu",0,true,NULL));
	menuInfo->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));
	menuInfo->AddItem(new MenuLabel(MenuItem::Label,NULL,1,true,MenuInfoItemTextHandler));
	menuInfo->AddItem(new MenuLabel(MenuItem::Label,NULL,2,true,MenuInfoItemTextHandler));
	menuInfo->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));
	menuInfo->AddItem(new MenuLabel(MenuItem::Label,L"audio analyzer v\002" TOSTRINGW(ANALYZER_VERSION_MAJOR) L"." TOSTRINGW(ANALYZER_VERSION_MINOR) L"\001",0,true,NULL));
	menuInfo->AddItem(new MenuLabel(MenuItem::Label,L"marko mihovilic",0,true,NULL));
	menuInfo->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));
	menuInfo->AddItem(new MenuLabel(MenuItem::Label,L"back",6,false,NULL));

	menuInfo->SetSelectedFirstValid();
	menuInfo->SetEventHandler(MenuInfoEventHandler);

	mMenuRoot.AddMenu(menuInfo);

	Menu* menuVis = new Menu;
	ASSERT(menuVis);

	menuVis->AddItem(new MenuLabel(MenuItem::Title,L"visualizations menu",0,true,NULL));
	menuVis->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));

	// Add the visualizations
	for(unsigned long i = 0; i < GetKernel()->GetGraphics()->GetVisualizationCount(); ++i)
		menuVis->AddItem(new MenuLabel(MenuItem::Label,GetKernel()->GetGraphics()->GetVisualizationName(i),i+1,false,NULL));

	menuVis->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuVis->AddItem(new MenuLabel(MenuItem::Label,L"back",GetKernel()->GetGraphics()->GetVisualizationCount()+1,false,NULL));

	menuVis->SetSelectedFirstValid();
	menuVis->SetEventHandler(MenuVisEventHandler);

	mMenuRoot.AddMenu(menuVis);

	Menu* menuPreset = new Menu;
	ASSERT(menuPreset);

	menuPreset->AddItem(new MenuLabel(MenuItem::Title,L"color presets menu",0,true,NULL));
	menuPreset->AddItem(new MenuLabel(MenuItem::Margin,NULL,0,true,NULL));

	// Add the color presets
	for(unsigned long i = 0; i < GetKernel()->GetGraphics()->GetColorPresetCount(); ++i)
		menuPreset->AddItem(new MenuLabel(MenuItem::Label,GetKernel()->GetGraphics()->GetColorPresetName(i),i+1,false,NULL));

	menuPreset->AddItem(new MenuLabel(MenuItem::Seperator,NULL,0,true,NULL));
	menuPreset->AddItem(new MenuLabel(MenuItem::Label,L"back",GetKernel()->GetGraphics()->GetColorPresetCount()+1,false,NULL));

	menuPreset->SetSelectedFirstValid();
	menuPreset->SetEventHandler(MenuPresetEventHandler);

	mMenuRoot.AddMenu(menuPreset);

	return true;
}
示例#26
0
bool Menus::MenuOptionsEventHandler(unsigned long event,MenuItem* sender)
{
	UNREFERENCED_PARAMETER(event);

	switch(sender->GetId())
	{
	case 1:	// Draw peaks
		GetKernel()->GetGraphics()->SetDrawPeaks(!GetKernel()->GetGraphics()->GetDrawPeaks());
		return true;

	case 2:	// Draw help text
		GetKernel()->GetGraphics()->SetDrawHelp(!GetKernel()->GetGraphics()->GetDrawHelp());
		return true;

	case 3:	// Draw about text
		GetKernel()->GetGraphics()->SetDrawAbout(!GetKernel()->GetGraphics()->GetDrawAbout());
		return true;

	case 4: // Draw output strings
		GetKernel()->GetGraphics()->SetDrawOutputStrings(!GetKernel()->GetGraphics()->GetDrawOutputStrings());
		return true;

	case 5:	// Draw fps
		GetKernel()->GetGraphics()->SetDrawFps(!GetKernel()->GetGraphics()->GetDrawFps());
		return true;

	case 6:	// Draw visualization name
		GetKernel()->GetGraphics()->SetDrawVisualizationName(!GetKernel()->GetGraphics()->GetDrawVisualizationName());
		return true;

	case 7: // Draw timer
		GetKernel()->GetGraphics()->SetDrawTimer(!GetKernel()->GetGraphics()->GetDrawTimer());
		return true;

	case 8:	// Keyboard LED
		GetKernel()->SetLed(!GetKernel()->GetLed());
		return true;

	case 9: // Eq Falloff
		if(GetKernel()->GetAudio()->GetEqFalloff() == 0)
			GetKernel()->GetAudio()->SetEqFalloff(1);
		else if(GetKernel()->GetAudio()->GetEqFalloff() == 1)
			GetKernel()->GetAudio()->SetEqFalloff(-1);
		else if(GetKernel()->GetAudio()->GetEqFalloff() == -1)
			GetKernel()->GetAudio()->SetEqFalloff(0);
		return true;

	case 10: // Peak Falloff
		if(GetKernel()->GetAudio()->GetPeakFalloff() == 0)
			GetKernel()->GetAudio()->SetPeakFalloff(1);
		else if(GetKernel()->GetAudio()->GetPeakFalloff() == 1)
			GetKernel()->GetAudio()->SetPeakFalloff(-1);
		else if(GetKernel()->GetAudio()->GetPeakFalloff() == -1)
			GetKernel()->GetAudio()->SetPeakFalloff(0);
		return true;

	case 11: // Peak Delay
		if(GetKernel()->GetAudio()->GetPeakDelay() == 0)
			GetKernel()->GetAudio()->SetPeakDelay(1);
		else if(GetKernel()->GetAudio()->GetPeakDelay() == 1)
			GetKernel()->GetAudio()->SetPeakDelay(-1);
		else if(GetKernel()->GetAudio()->GetPeakDelay() == -1)
			GetKernel()->GetAudio()->SetPeakDelay(0);
		return true;

	case 12: // Write config
		GetKernel()->WriteConfig(NULL);
		return true;

	case 13: // Read config
		GetKernel()->ReadConfig(NULL);
		return true;

	case 14: // Back
		GetKernel()->GetMenus()->GetMenuRoot()->SetCurrentMenu(0);
		return true;
	}

	return false;
}
示例#27
0
bool Scope::RenderOverlay()
{
	// Draw the borders of the scope line
	GetKernel()->GetGraphics()->DrawShadowText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35,242),L"|",GetKernel()->GetGraphics()->GetColorPreset()->peak);
	GetKernel()->GetGraphics()->DrawShadowText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35+720-1,242),L"|",GetKernel()->GetGraphics()->GetColorPreset()->peak);

	// Draw the first label
	GetKernel()->GetGraphics()->DrawShadowColorText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35,456),L"|-\00224.00\001 ms",GetKernel()->GetGraphics()->GetColorPreset()->text);

	// Draw the middle label
	Size size;
	GetKernel()->GetGraphics()->GetTextSize(GetKernel()->GetGraphics()->GetBoldFont(),L"-12.00 ms",&size);
	Rect rect(35,456,35+720,456);
	GetKernel()->GetGraphics()->DrawShadowColorText(GetKernel()->GetGraphics()->GetBoldFont(),Point(rect.left + rect.GetWidth() / 2 - size.cx / 2,rect.top),L"-\00212.00\001 ms",GetKernel()->GetGraphics()->GetColorPreset()->text);

	// Draw the end label
	GetKernel()->GetGraphics()->GetTextSize(GetKernel()->GetGraphics()->GetBoldFont(),L"00.00 ms",&size);
	GetKernel()->GetGraphics()->DrawShadowColorText(GetKernel()->GetGraphics()->GetBoldFont(),Point(rect.right - size.cx,rect.top),L"\00200.00\001 ms|",GetKernel()->GetGraphics()->GetColorPreset()->text);

	// Draw the meter vertical lines
	for(unsigned long x = 0; x < 73; ++x)
	{
		if(x == 0)	// First
			GetKernel()->GetGraphics()->DrawShadowText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35+x*10,441),L"|",GetKernel()->GetGraphics()->GetColorPreset()->text[0]);
		else if(x == 72/2)	// Middle
			GetKernel()->GetGraphics()->DrawShadowText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35+x*10,441),L"|",GetKernel()->GetGraphics()->GetColorPreset()->text[0]);
		else if(x == 72)	// Last
			GetKernel()->GetGraphics()->DrawShadowText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35+x*10,441),L"|",GetKernel()->GetGraphics()->GetColorPreset()->text[0]);
		else	// Normal
			GetKernel()->GetGraphics()->DrawShadowText(GetKernel()->GetGraphics()->GetBoldFont(),Point(35+x*10,441),L"|",GetKernel()->GetGraphics()->GetColorPreset()->peak);
	}

	return true;
}
示例#28
0
bool Control::OnRenderEditorMode(void)
{
	GetKernel()->GetUserInterface()->DrawResizeHandles(GetBoundingBox());
	return true;
}