Sign in to follow this  
The C modest god

Design question

Recommended Posts

I am making a sound synthesizer, so I want to create different types of waves for notes. Such as: sin wave, trianhle waves, etc. In short, I did the following:
class SynthesizerTypeCreator: public BaseClass {
	public:
		virtual Real SynthSample (Real _Amplitude, Real _Position)=0;
};

class SquareSynthesizer: public SynthesizerTypeCreator {
	public:
		Real SynthSample (Real _Amplitude, Real _Position);
};

class SinSynthesizer: public SynthesizerTypeCreator {
	public:
		Real SynthSample (Real _Amplitude, Real _Position);
};

class SoundSynthesizer: public BaseClass {
	public:
		void CreateWave (MusicalNote & _MNote, Real _StartTime, SoundContainer & _SContainer, SynthesizerTypeCreator * _pTypeCreator);
	private:
};

Is this a good way to solve this problem? or can the pointer cause some bugs? Thanks in advance.

Share this post


Link to post
Share on other sites
It's not a very good idea to have a BaseClass.

The name SynthesizerTypeCreator doesn't describe very well what it does. I would rather call it Synthesizer.

Your derived classes (SquareSynthesizer and SinSynthesizer) should have constructors that take whatever parameters they need (in those two cases, a frequency will do) and data members to store them.

I would also write a factory that would be able to construct any type of Synthesizer from a description (probably a text string). That way the rest of the code will not see the derived classes and you can add new Synthesizers without even recompiling the rest of the program.

Why is your rating 0? What did you do?

Share this post


Link to post
Share on other sites
Quote:
Original post by alvaro
It's not a very good idea to have a BaseClass.

The name SynthesizerTypeCreator doesn't describe very well what it does. I would rather call it Synthesizer.

Your derived classes (SquareSynthesizer and SinSynthesizer) should have constructors that take whatever parameters they need (in those two cases, a frequency will do) and data members to store them.

I would also write a factory that would be able to construct any type of Synthesizer from a description (probably a text string). That way the rest of the code will not see the derived classes and you can add new Synthesizers without even recompiling the rest of the program.

Why is your rating 0? What did you do?

These are good ideas, but I think it is a bit overkill.
I just feared there might be a bug for using a pointer instead of a reference, but I dont think I can replace the pointer with a reference in this case.
Why I have a zero rating? perhaps an art statement?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this