C++ to PB

Just starting out? Need help? Post your questions and find answers here.
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

C++ to PB

Post 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
macOS Catalina 10.15.7
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: C++ to PB

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: C++ to PB

Post 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
macOS Catalina 10.15.7
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: C++ to PB

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: C++ to PB

Post 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
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: C++ to PB

Post 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?
macOS Catalina 10.15.7
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: C++ to PB

Post 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.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: C++ to PB

Post 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?
macOS Catalina 10.15.7
ToniPB
User
User
Posts: 13
Joined: Tue Dec 16, 2014 3:44 am

Re: C++ to PB

Post 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++
Post Reply