Hi, I have a C++ audio project that I done last year. Now I would create a new C++ audio…
- User
Hi, I have a C++ audio project that I done last year. Now I would create a new C++ audio project, that at least at its first stage will start as a continuation of the past project. The project is a Score-Based Music System, with offline computation and batch processing. For this reason, I am considering the fact to take out the old project and create a mock-up on it because the old project grew randomly without any clear direction related to best practice of design and coding. My idea is to take a piece of code of the old project, delineate all the vulnerabilities that I saw, evaluate the improvements and try to create a mock-up upon it to perform the same piece of code but well-designed. In the following, I would like to provide you my candidate snippet of code, with some comments, plus the list of relevant issues that I see and a proposal of modification. Then, I will ask a comment on it, in particular if you see any drawback on my proposal or any particular issue or something that I am clearly missing. Lastly, please consider that it is a mock-up, I am a fan of KISS principle, and that once this analysis will be done I will try to apply the proposal to another snippet of code taken from the old project, to see if it works correctly.
durGrain = 20000.; // time to be considered for(auto d=0; d<durGrain; ) { const double tIncr = d / static_cast<double>(durGrain); // internal increment double before_start = 150.; // base value double before_var = -70. * util::halfsine(tIncr); // util is a namespace I use for Utilities and wrapper for mathematical functions double dur_start = 80; double dur_var = 46.66 * util::sine(tIncr); double before = before_start + before_var; // base + variation double dur = dur_start + dur_var; double freq_start = freq_main; // base "reference" value, declared as static const value outside this snippet double freq_var = 0. double freq = freq_start + freq_var; // base + variation double amp_start = amp_2f; // reference value, declared as static const value outside this snippet double amp_var = 0.; double amp = amp_start + amp_var; // base + variation itemsSF = myGrain.Calculate_items(before, dur); // myGrain is my synthesizer, here it calculates the number of samples that will be processed myGrain.Set_same_freq(freq); // same value are set myGrain.Set_same_amp(amp); const double* toBeWritten = myGrain.Compute(); // main Process function, that returns a pointer to double there samples are computed and stored successSF = myWriter.Write(toBeWritten, itemsSF); // myWriter is the class that will take the samples and will write them in an external Wave file d += before + dur; // temporal increment }To make this code flexible and modular, I will introduce:
- A Scorer class, that will read and load parameters from an external score text file, following a syntax like = ;, like amp = 2f;. Inside it, also a Parser and Tokenizer have to be considered.
- A ConfigHandler class, that will be responsible for the mediator pattern.
- Assistant
- User
Two additional comments.
- Error handling, from you Additional Recommendations. What do you mean with "logging"? Can you please provide me a context and a reference?
- I think that the Pipeline should be introduced as the same time of a Chain-of-Responsibility pattern, such that at this stage an abstract class can be introduced, like a Direct Acyclic Graph, such that the chain and the pipelining will be uniquely defined for both topics.
- Assistant
- User
One additional question: consider the following case, in my application I use two distinct scores to be processed such that I have in Main.cpp two distinct call to MainController.runProcessingLoop(). However, in this case I can have just once call to Parameters related to Writer, like the Wave filename. My point is: such call to evaluateParameters can be performed before and outside the first runProcessingLoop. However, does it mean that I have to introduce another Parameters, like OnlyOnceParameter? I do not see any difference in such case in the code and in the behavior between StaticParameter and OnlyOnceParameter but only user usage. For this reason I am asking if it is a best practice to introduce another class to handle this, or just to say to leave the user a defined class for this situation?
- Assistant