Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

Design question

This topic is 4446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!