Kyma Forum
  Tips & Techniques
  Sample rate counter

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Sample rate counter
tuscland
Member
posted 12 April 2006 03:17         Edit/Delete Message   Reply w/Quote
Hi,

I would like to be able to use a counter at sample rate, like countTriggers, but not control rate.

Do you think of an idea of how to implement this?
I was thinking of makeing a simple counter with latches and gates, but I fear it is a big solution for a small problem ... is that?


Cheers,
Camille

IP: Logged

SSC
Administrator
posted 12 April 2006 08:28         Edit/Delete Message   Reply w/Quote
One alternative you could try: Take a PulseTrain, attenuate its amplitude to 1/maxCount (using the inputScale on the DelayWithFeedback), feed into DelayWithFeedback (with delay of 1 sample and feedback of 1).

The DelayWithFeedback will accumulate the sum of pulses seen so far.

IP: Logged

tuscland
Member
posted 12 April 2006 09:17         Edit/Delete Message   Reply w/Quote
Great!
I kind of thought about this, but not with this simplicity.
I would like to know how I can reset the DelayWithFeedBack in order to count back from 0?

IP: Logged

pete
Member
posted 12 April 2006 09:27         Edit/Delete Message   Reply w/Quote
Hi Camille

I assume you want to be able to reset it at sample rate as well. You can use an Up/Down counter module again, but the output starts at a minus number for indexing. So what you can do is put 2 times the MaxNumber of counts that you want in the NoOfSamps field and put 0-(2*MaxNumber) in the OffSetHalfStep field. This way the output starts at zero and will move up by 1/MaxNumber every time the CountUp is triggered. When you reach the max number it will wrap around to minus one and start moving up with the same step size (for every CountUp trigger and will stop at 0-(1/MaxNumber) if the WrapAround is zero. If WrapAround is one then it will carry on forever.

Is this what you want ?

Pete

IP: Logged

tuscland
Member
posted 12 April 2006 17:49         Edit/Delete Message   Reply w/Quote
Yes, the use of CountUp with a trigger is a great idea, thanks !
One exception, though, the counter wraps at minus 1 and it is not zero base, but I think I can get over it by changing the OffsetHalfStep value.

I will try with a triggered table read, although it is a bit strong just for a counter.

[This message has been edited by tuscland (edited 12 April 2006).]

IP: Logged

pete
Member
posted 13 April 2006 01:57         Edit/Delete Message   Reply w/Quote
It wraps to minus one only if there are more triggers than your selected max. Reset still resets to zero. If you make your max much bigger than you need, the minus one will never happen. I was only explaining a fault condition, which you can make use of i.e. if the output is a minus then an overrun has happened.

If you really do want it to wrap around to zero then you can use the counter without the doubling up of the max values and with zero in the OffSetHalfStep field and then add a scale and offset module to it's output.

[This message has been edited by pete (edited 13 April 2006).]

IP: Logged

pete
Member
posted 13 April 2006 05:45         Edit/Delete Message   Reply w/Quote

SRTriggerCount.kym

 
As a picture paints a thousand words I've added an example.
I've realized that the max has to be one more than the required Max as True Value One doesn't exists in twos compliment numbers with a range of +/- 1. Also the OffSetHalfStep formula need to be one minus the max number of steps plus one times two. You may notice that in the number to index module I have subtracted 0.5 . This is because we comparing values that are supposed to be identical, but an error of just 0.000000001 (which is quite possible with 24 bit numbers) can give entirely the wrong result. Most of the time this would not be a problem but if you had a max value of number of say 125767, then occasional errors will appear and they would be virtually impossible to track down.

IP: Logged

tuscland
Member
posted 13 April 2006 18:41         Edit/Delete Message   Reply w/Quote

SRTriggerCount2.kym

 
Hi Pete,

I think this is a good solution, as I enables me to count triggers and divide them with the ratio I want. I modified a bit your example to introduce a feedback loop that allows for an automatic reset.
I have still 2 small problems that I need to fix before I can make a class out of this example (which I'll later publish to Tweaky of course!) :
- The feedback loop I implemented is not very efficient, is there a way to make more cpu-wise? I tried to use a FeedbackInput/Output instead of a MemoryWriter/Sample feedback loop, but the 12 sample delay of FeedbackInput scares me.
- The counter won't work until a initial Reset is made, could you explain why? I can't figure out ...

Cheers,
Camille

IP: Logged

pete
Member
posted 14 April 2006 07:33         Edit/Delete Message   Reply w/Quote

SRTriggerCount234.kym

 
Hi Camille

Feedback is always a problem in multi DSP systems, as you've found it either has to be on one chip for a one sample delay only or many samples if the feed back spreads over more chips. This is unavoidable even if we soldered extra links between the chips we still couldn't avoid the delay. Also you are right about the reset error. The plan was that if the user feed the same pulse into the count up and the write of a step writer the first memory cell would be written to. This meant that it had to start one before the first step which was fine when Wrap was on but not when it was off. I'll have to look at this again sometime and put in an exception in the DSP with inputs module. Any way as you don't need protection against overrun then you can switch wrap on. I've done this in version 3 and cleared out some other unnecessary modules.

If you don't need to change the count number at sample rate then you can get away with out using feed back as in version 4. This does have a problem that during the change from more to less steps an extra click can be introduced. I don't know how disastrous this would be to the overall thing.

Hope it helps

Pete


BTW you can open up the class of SetableRamp. This one has no DSP module of it's own , it is made up of other DSP modules. In fact the reason it's not working is because the Negate module inside is faulty . But I think you found a cure for that. This may give clues as to other methods of achieving the same thing.

[This message has been edited by pete (edited 14 April 2006).]

IP: Logged

pete
Member
posted 14 April 2006 08:40         Edit/Delete Message   Reply w/Quote
Just thought

With ver 4 you can just AND the output pulses with the input pulses to mask the extras.

IP: Logged

tuscland
Member
posted 14 April 2006 13:36         Edit/Delete Message   Reply w/Quote
Thanks Pete,
This does the trick very well.
I don't know yet if the spurious clicks will be problem, I don't think so.

By the way the SetableRamp class is not openable, it seems to be protected. Actually, the "Retrive example from Class" doesn't work for any Class, even those I create. Did I missed something ?

I am going to do a class of this patch and publish it to the tweaky very soon, thanks to your help!

[This message has been edited by tuscland (edited 14 April 2006).]

IP: Logged

pete
Member
posted 14 April 2006 20:44         Edit/Delete Message   Reply w/Quote
You know you have to be editing the class before you try to retrieve it. And you must edit it from the sound file window not the sound editor ?

IP: Logged

tuscland
Member
posted 15 April 2006 04:41         Edit/Delete Message   Reply w/Quote
OK, sorry I just forgot how to retrieve the example ...
As you said, fhe problem lies in the Negate class. It seems to have been corrupted, there is a typo a message with a selector like 0yPut: is sent.

Would you accept I correct the errors and update the microsounds on the tweaky? I have also organized the sounds so that it integrate nicely in the prototypes window. Last thing, there is a class Half Wave Rectifier, why isn't it used? I has good results and could be useful!

Have a good weekend!
Cam

IP: Logged

pete
Member
posted 15 April 2006 08:23         Edit/Delete Message   Reply w/Quote
Hi Cam

It would be great if you could put the corrections on the tweeky.

Also somewhere on the forum kurt made some amendments to some of the DSP assy code for a job that Mathis was doing and this version make the scheduler allocate less DSP where it should for two of the modules. It would be great if this version could be found.

BTW I think Half Wave does the same job as the Absolute module which Kyma already has.

Thanks

Pete

IP: Logged

tuscland
Member
posted 19 April 2006 09:36         Edit/Delete Message   Reply w/Quote
Hi Pete,

I'm on my way, now it is time for debugging.
I now have two questions for you :

1. In Up/Down Counter. It seems like I have more precise results if I use an odd count in the NumberOfSamples field. Can you confirm that?

2. The Set/Reset Flip Flop shows its limitations when the Set and the Reset keys are on at the same time. I get inconsistent results just because of this. In the file I have put on the tweaky where there are some of my new classes, one of them is called SyncTrigger, and is very handy because it output only one trigger sync'ed to master rising edge triggers, on response to a triggering trigger (!). If both the triggering trigger and the master trigger are down to up at the same time, I get inconsistent results. I would like to accomplish the same function but without the SR flip flop. The solution would be perhaps to implement a JK Flip Flop, but my skills are not yet enough to write the microcode for that.

[Update: I actually found solutions with the SR flip flop gate]

Cheers!
Camille

[This message has been edited by tuscland (edited 19 April 2006).]

IP: Logged

pete
Member
posted 20 April 2006 04:39         Edit/Delete Message   Reply w/Quote
Hi Cam

The up/down counter is optimized to work 100% as an index for a wave shaper. The reality of a wave shapers index is that for even numbers the values are spread evenly across the +/- 1 range but for odd numbers the spread is the same as the next highest even number but with the top value missing. So Odd numbers don't work correctly in wrap maths, but I had to match the wave shaper. Strange you say it's even numbers that have the problem and as we multiply the max by 2 it should always be even. Can you post the modules as they are and with the thing that's telling you that the evens are wrong and I'll have a look.

BTW with the SR flip flop it works as a hardware flip flop would work i.e. when both inputs are high it give's priority to one of them (in this case the reset). In a lot of cases you want to use it as a way of knowing which input was the last to go hi rather than as a true hardware FlipFlop . This can be achieved by putting a gate to trigger on the reset input (as mentioned in the help text). I wonder if this is what you ended up doing ?

Pete

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c