Page 1 of 1

C++ to PB

Posted: Tue Dec 22, 2015 12:01 pm
by Wolfram
Hello,

can anybody translate me these C++ code to PB?

Code: Select all

Convs[ i ] = new CDSPBlockConvolver(
						CDSPFIRFilterCache :: getLPFilter( 0.5, tb, ReqAtten,
						ReqPhase, 2.0 ), 2, 1, PrevLatencyFrac );
Thanks

Re: C++ to PB

Posted: Tue Dec 22, 2015 1:36 pm
by TI-994A
Wolfram wrote:...can anybody translate me these C++ code to PB?

Code: Select all

Convs[ i ] = new CDSPBlockConvolver(
						CDSPFIRFilterCache :: getLPFilter( 0.5, tb, ReqAtten,
						ReqPhase, 2.0 ), 2, 1, PrevLatencyFrac );
From that single line, not a chance. :lol:

For one thing, we have no access to the CDSPBlockConvolver() and CDSPFIRFilterCache() object class codes.

Re: C++ to PB

Posted: Tue Dec 22, 2015 1:45 pm
by Wolfram
TI-994A wrote:
Wolfram wrote:...can anybody translate me these C++ code to PB?

Code: Select all

Convs[ i ] = new CDSPBlockConvolver(
						CDSPFIRFilterCache :: getLPFilter( 0.5, tb, ReqAtten,
						ReqPhase, 2.0 ), 2, 1, PrevLatencyFrac );
From that single line, not a chance. :lol:

For one thing, we have no access to the CDSPBlockConvolver() and CDSPFIRFilterCache() object class codes.
If you need the rest you can get it here
https://github.com/avaneev/r8brain-free-src

Thanks for help

Re: C++ to PB

Posted: Tue Dec 22, 2015 2:32 pm
by TI-994A
Wolfram wrote:If you need the rest you can get it here
https://github.com/avaneev/r8brain-free-src
It seems to be mainly data-manipulation, which should be quite doable in PureBasic. However, just between those two objects, you're conservatively looking at nearly a thousand lines of code.

I can't be sure, but it seems that it might be possible to wrap them up in C functions.

But that's beyond me. Sorry.

Re: C++ to PB

Posted: Tue Dec 22, 2015 5:05 pm
by Lunasole
You can take a look here about import C++ classes to PB
http://www.purebasic.fr/english/viewtop ... 12&t=53808

But if translate... well that's even more complicated, you have to rewrite original code to be used without classes. Or use some custom OOP extension to Purebasic, there are several on forum

Re: C++ to PB

Posted: Tue Dec 22, 2015 8:34 pm
by Wolfram
My Problem is, I don't understand what Convs[ i ] = new CDSPBlockConvolver() means
What ist Convs[ i ] in this case?
Is it possible to translate this to PB?

Re: C++ to PB

Posted: Tue Dec 22, 2015 8:49 pm
by Lunasole
Wolfram wrote:My Problem is, I don't understand what Convs[ i ] = new CDSPBlockConvolver() means
What ist Convs[ i ] in this case?
Is it possible to translate this to PB?

Convs itself is just an array containing CDSPBlockConvolver classes.
That code just adds new element using i as array index.

There are no problems with array, the problem of translation is that Purebasic doesn't support classes. You need to rewrite CDSPBlockConvolver class in procedural way or use another solution like custom OOP implementation.
So generally yes, it is possible to translate, but much more complicated than just rewriting code as is.

Re: C++ to PB

Posted: Tue Dec 22, 2015 9:25 pm
by Wolfram
Lunasole wrote:
Wolfram wrote:My Problem is, I don't understand what Convs[ i ] = new CDSPBlockConvolver() means
What ist Convs[ i ] in this case?
Is it possible to translate this to PB?

Convs itself is just an array containing CDSPBlockConvolver classes.
That code just adds new element using i as array index.

There are no problems with array, the problem of translation is that Purebasic doesn't support classes. You need to rewrite CDSPBlockConvolver class in procedural way or use another solution like custom OOP implementation.
So generally yes, it is possible to translate, but much more complicated than just rewriting code as is.
Ok that helps!
But I thought that a array, in C++, will be build like this Convs = new int;

And how do I know what kind of array? I can't find any Information about the datatype of the convs array?

Re: C++ to PB

Posted: Sat Dec 26, 2015 6:17 am
by ToniPB
Wolfram wrote:My Problem is, I don't understand what Convs[ i ] = new CDSPBlockConvolver() means
What ist Convs[ i ] in this case?
Is it possible to translate this to PB?
Converting C++ code to PB without understating the C++ code itself, is not gonna work well.

I took a quick look at the library you posted and it doesn't seem like a easy task to convert it.

Here's some tips:

CDSPResampler.h - Line: 203

Code: Select all

					Convs[ i ] = new CDSPBlockConvolver(
						CDSPFIRFilterCache :: getLPFilter( 0.5, tb, ReqAtten,
						ReqPhase, 2.0 ), 2, 1, PrevLatencyFrac );
"Convs" is an array of pointers.

CDSPResampler.h - Line: 462

Code: Select all

CPtrKeeper< CDSPBlockConvolver* > Convs[ ConvCountMax ]; ///< Convolvers.
This is the array implementation:

r8bbase.h - Line: 477

Code: Select all

class CPtrKeeper
{
	R8BNOCTOR( CPtrKeeper );

public:
	CPtrKeeper()
		: Object( NULL )
	{
	}

	/**
	 * Constructor assigns a pointer to object to *this keeper.
	 *
	 * @param aObject Pointer to object to keep, can be NULL.
	 */

	template< class T2 >
	CPtrKeeper( T2 const aObject )
		: Object( aObject )
	{
	}

	~CPtrKeeper()
	{
		delete Object;
	}

	/**
	 * Function assigns a pointer to object to *this keeper. A previously
	 * keeped pointer will be reset and object deleted.
	 *
	 * @param aObject Pointer to object to keep, can be NULL.
	 */

	template< class T2 >
	void operator = ( T2 const aObject )
	{
		reset();
		Object = aObject;
	}

	/**
	 * @return Pointer to keeped object, NULL if no object is being kept.
	 */

	T operator -> () const
	{
		return( Object );
	}

	/**
	 * @return Pointer to keeped object, NULL if no object is being kept.
	 */

	operator T () const
	{
		return( Object );
	}

	/**
	 * Function resets the keeped pointer and deletes the keeped object.
	 */

	void reset()
	{
		T DelObj = Object;
		Object = NULL;
		delete DelObj;
	}

	/**
	 * @return Function returns the keeped pointer and resets it in *this
	 * keeper without object deletion.
	 */

	T unkeep()
	{
		T ResObject = Object;
		Object = NULL;
		return( ResObject );
	}

private:
	T Object; ///< Pointer to keeped object.
		///<
};
In PureBasic:

Code: Select all

Structure CPtrKeeper Align #PB_Structure_AlignC
  *Object.Integer ; Pointer to keeped object.
EndStructure
Here's a couple steps on where to start.

1. Convert "R8B_BASECLASSÂȘ if defined
2. Convert "CDSPFIRFilterCache"
3. Convert "CDSPProcessor"
4. Convert "CDSPBlockConvolver"
5. etc.........

Bottom line is, it's too much work to it manually, so you either code some sort of Automatic Converter, make a C-Style Wrapper or simply use it in C++