|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
On 14 Oct, 19:56, "BobR" <removeBadB...@worldnet.att.net> wrote:
> stephen b wrote in message... > > > I am using arrays instead of vector<double> because I found the > > initialisation of many vector<double>s caused brief CPU spikes each > > time an object is created. > > I'm curious. How did you initialize the vectors? > > > Arrays seemed less troublesome which is > > important for real-time DSP stuff. > > I think it's the opposite. :-} really? right, I think I initialised my vectors like this: vector<double> vec (8192, 0.); so I guess maybe filling the array with zeros was causing some overhead. I also found arrays to be slightly more efficient in use although it's probably negligible even though I'll be using 20 or so per synth. > Could it be because you are dereferenceing un-initialized data (the arrays)? > Let's test something. In your FilterSynth() constructor: > > FilterSynth(){ > for( int i(0); i < 10; ++i ){ > std::cout<< filtIn[ i ] <<'\n'; > } // for(i) > } // Ctor > > What's your output from that? (I got garbage (UB)). well with the filter example I fill the array with zeros first but otherwise just garbage. Stephen. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
stephen b <kernel@audiospillage.com> wrote in message news:1192563109.115307.88440@i38g2000prf.googlegro ups.com... > On 14 Oct, 19:56, "BobR" <removeBadB...@worldnet.att.net> wrote: > > stephen b wrote in message... > > > I am using arrays instead of vector<double> because I found the > > > initialisation of many vector<double>s caused brief CPU spikes each > > > time an object is created. > > > > I'm curious. How did you initialize the vectors? > > > > > Arrays seemed less troublesome which is > > > important for real-time DSP stuff. > > > > I think it's the opposite. :-} > > really? right, I think I initialised my vectors like this: > vector<double> vec (8192, 0.); so I guess maybe filling the array > with zeros was causing some overhead. I also found arrays to be > slightly more efficient in use although it's probably negligible even > though I'll be using 20 or so per synth. > > > Could it be because you are dereferenceing un-initialized data (the arrays)? > > Let's test something. In your FilterSynth() constructor: > > > > FilterSynth(){ > > for( int i(0); i < 10; ++i ){ > > std::cout<< filtIn[ i ] <<'\n'; > > } // for(i) > > } // Ctor > > > > What's your output from that? (I got garbage (UB)). > > well with the filter example I fill the array with zeros first but > otherwise just garbage. > Stephen. > By the time you initialize your raw arrays, there should be very little difference with std::vectors. (you don't need the '0.0' in init, it is the default.) Try your tests with this and see how it goes: This compiles on my system, but of course, you'll need to modify it to use your base classes, etc.. Just for a suggestion. class Filter{ public: // Filter( double *inBlk, double *outBlk ){ // in = inBlk; out = outBlk; } Filter( std::vector<double> const &inBlk, std::vector<double> &outBlk ) : in( inBlk.begin() ), out( outBlk.begin() ){} // void Process(UInt32 inNumFrames) { void Process( int inNumFrames ){ double y0(0); // for test compile for( int i(0); i < inNumFrames; ++i){ y0 = *(in)++; *(out)++ = y0; } // for(i) } // Process(int) private: // double *in, *out; std::vector<double>::const_iterator in; std::vector<double>::iterator out; }; // If 'in' and 'out' are only used in 'Process', you may want // a normal constructor and use the following for 'Process': // void Process( std::vector<double> const &inBlk, // std::vector<double> &outBlk ){ .... } // .... and change the call below. Then you wouldn't need the // iterators in the class (just in the function). class FilterSynth{ public: FilterSynth() : filtIn(8192), filtOut(8192), filt( filtIn, filtOut ){} virtual ~FilterSynth(){} // not needed if base Dtor is virtual. // virtual UInt32 NextBlock( UInt32 inNumFrames ){ virtual int NextBlock( int inNumFrames ){ // this function is called by another class. filt.Process( inNumFrames ); return 0; } private: std::vector<double> filtIn; std::vector<double> filtOut; Filter filt; }; This is a little 'loose', but I don't know exactly the problem you are working. Hope that s some. -- Bob R POVrookie |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"BobR" <removeBadBobR@worldnet.att.net> wrote in
news:BvcRi.226524$ax1.159736@bgtnsc05-news.ops.worldnet.att.net: > > stephen b <kernel@audiospillage.com> wrote in message > news:1192563109.115307.88440@i38g2000prf.googlegro ups.com... >> On 14 Oct, 19:56, "BobR" <removeBadB...@worldnet.att.net> wrote: >> > stephen b wrote in message... >> > > I am using arrays instead of vector<double> because I found the >> > > initialisation of many vector<double>s caused brief CPU spikes >> > > each time an object is created. >> > >> > I'm curious. How did you initialize the vectors? >> > >> > > Arrays seemed less troublesome which is >> > > important for real-time DSP stuff. >> > >> > I think it's the opposite. :-} >> >> really? right, I think I initialised my vectors like this: >> vector<double> vec (8192, 0.); so I guess maybe filling the array >> with zeros was causing some overhead. I also found arrays to be >> slightly more efficient in use although it's probably negligible even >> though I'll be using 20 or so per synth. >> >> > Could it be because you are dereferenceing un-initialized data (the > arrays)? >> > Let's test something. In your FilterSynth() constructor: >> > >> > FilterSynth(){ >> > for( int i(0); i < 10; ++i ){ >> > std::cout<< filtIn[ i ] <<'\n'; >> > } // for(i) >> > } // Ctor >> > >> > What's your output from that? (I got garbage (UB)). >> >> well with the filter example I fill the array with zeros first but >> otherwise just garbage. >> Stephen. >> > > By the time you initialize your raw arrays, there should be very > little difference with std::vectors. (you don't need the '0.0' in > init, it is the default.) Keep in mind that std::vector has to do (Well, is very likely to do) dynamic memory to store its contents. Arrays do not. You might try std::tr1:array instead... |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Andre Kostur wrote in message... > > Keep in mind that std::vector has to do (Well, is very likely to do) > dynamic memory to store its contents. Arrays do not. You might try > std::tr1:array instead... A valid argument. But, sticking 2+ meg in the stack might be a source of his problem (stack overflow/corruption?). And if you 'new' the arrays, well, I think std::vector is a good choice. [ I don't know how C++ sets up the stack, but in assembler, it was precious realestate. My logic is small things on stack, big things in dynamic(heap). Feel free to inform/correct me on this point. :-}] -- Bob R POVrookie |
|
![]() |
| Outils de la discussion | |
|
|