1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Sample accurate song position

Discussion in 'REAKTOR' started by howesc, Apr 23, 2015.

  1. howesc

    howesc New Member

    Messages:
    23
    Hi all

    I'm writing my first audio table instrument in which I control the read and write positions at the sample level by using a Unit Delay and plus 1 - as each sample plays the output increments by 1.

    I reset the counter by multiplying its output by 0 whenever the counter reaches a specified number of samples.

    I also wish to reset the counter whenever the song position is reset to zero. I've spent a few days trying various methods but haven't been able to find a satisfactory solution. Essentially I need a macro which outputs a zero on the first sample, and a 1 on all other samples. (a side question: do I need to output a 0 at the beginning of the first sample or the end? - I can't get my head around that at all!)

    I can't make head nor tail of the Start/Stop module. I'd presumed that clicking the "Reset play position to zero" button in Reaktor's transport would cause the Start/Stop's Rst to output a 1 when clicked, and revert to 0 thereafter, but that doesn't seem to be the case.

    The event output of the Song Position module cannot be used because this outputs a 0 during the entire first 96th bar of the song.

    The audio output of the Song Position module seems to behave quite strangely - it even outputs negative values, and rarely (but sometimes) outputs a 0. The best I've managed to come up with is to use a Compare/Equal module to assess whether the 96a output is less than 10^-6. This "appears" to work, but I cannot prove to myself that this is sample accurate.

    Any help, much appreciated.

    Kind regards
     
  2. James Nicholl

    James Nicholl Forum Member

    Messages:
    354
    I thought I'd give this one a shot...

    The behavior of 96a is really funky.

    The only solution I could come up with is to use an Audio Core Cell with an event input to process the 96 output of Song Position: SampleIsZero.png
     
  3. herw

    herw NI Product Owner

    Messages:
    6,421
  4. colB

    colB NI Product Owner

    Messages:
    3,969
    The problem here is that after a stop and rewind, pressing play ignores the first note.
    The problem is due to the fact that you need a dup filter when moving between Audio and event streams, but the rewind outputs a 0, so the 0 that should be processed when play is pressed is treated as a duplicate and filtered out.
     
  5. herw

    herw NI Product Owner

    Messages:
    6,421
    cannot confirm for the audio snc&pos (there is no dup filter). It works correct and that was the sense of my upload.
     
  6. colB

    colB NI Product Owner

    Messages:
    3,969
    My bad - it is a StpFlt (same function as dup filter). In your example ensemble in the 'Major Scale' module.
    This is needed because otherwise you get an audio rate stream of duplicate events. However, the StpFlt causes the problem when you hit play after stopping and rewinding - the first note is ignored due to the StpFlt.
    The problem happens with the audio and event versions and for the same reason.

    To hear the problem, switch the patterns to a slow rate - 1/4 and 1/6 are good. Then hit play. After a few notes have sounded, hit stop. Now hit rewind. You should hear the first notes in the pattern sounding. Now wait a second and hit play. IMO this should start both patterns with their first notes. But the first notes are ignored as I've explained.

    It occurs because rewinding after stopping sends a position value of zero, then pressing play sends a position value of zero - oops, that one gets treated as a duplicate and is filtered out!
    One way to work around this is to create a version that sends a unique value for the rewind (or for the initial zero position) I use -1 for this. Then create custom dup filters that turn this into a zero after filtering duplicates.

    An alternative would be to treat the rewind/reset when stopped as a special case where instead of sending a position value of zero, it sends no position value, but instead sends a reset command of some sort - then the ensemble it is driving can do other stuff that might be good on reset, like silencing all notes... it would also mean that you wouldn't hear the first note(s) of a pattern ring out when you press rewind.
     
  7. herw

    herw NI Product Owner

    Messages:
    6,421
    yes you are - when i wrote last post it was correct. I have something changed but i don't remember what. :(
     
  8. howesc

    howesc New Member

    Messages:
    23
    Hi all - many thanks for your help.

    I think I've managed to crack this problem - see attached screenshot. The idea is to output a zero on the first sample after the song has been reset and then a 1 immediately thereafter.

    It appears to working correctly but would be great if you could have a look and confirm - its entirely possible that this isn't working like I think it is (as with most things in Reaktor!)

    I will also test James Nicholl's approach - I've not touched core yet so this will be a good exercise to get my feet wet.

    Thanks again

    Screen Shot 2015-04-24 at 7.40.48 pm.png
     
  9. howesc

    howesc New Member

    Messages:
    23
    I should mention that that is daniel battaglia's Song Position macro from the user library
     
  10. James Nicholl

    James Nicholl Forum Member

    Messages:
    354
    That might work for your instrument, but it's not what you described.

    The black ports on modules are clocked to audio rate. The red ports are clocked to control rate.

    So, it is immediately apparent that your solution won't have audio rate accuracy, only control rate accuracy.

    Here's a solution using non core modules.

    ZeroSampleOnReset.png

    I think it works...
     
    Last edited: Apr 24, 2015
  11. howesc

    howesc New Member

    Messages:
    23
    Hi James - I actually meant to put an A/E Perm with sampling frequency = 44100 instead of the A/E. Out of interest do you think that would fix it?

    Your approach is much more appealing/simpler though so I'm going to switch to yours anyway. It took me about 5 minutes of staring at it to work out what its doing, but when I worked it out I all made perfect sense.

    Thanks so much for your help
     
  12. James Nicholl

    James Nicholl Forum Member

    Messages:
    354
    I just edited it because the addition module was unnecessary.

    Also, there's a weird bug where if you run zero through a unit delay it produces a small non zero number. The quantize modules takes care of that.
     
  13. James Nicholl

    James Nicholl Forum Member

    Messages:
    354
    I don't believe it will.

    Control rate is set in Reaktor's preferences, and as far as I know you can't exceed that value.
     
  14. salamanderanagram

    salamanderanagram NI Product Owner

    Messages:
    3,454
    you can absolutely use an A to E with a freq ranging all the way up to the sample rate. in fact, only a few event modules actually function at control rate (for example, the LFO, the CR output of the system module, and some others with continuous streams of events).

    this is probably a denormal function?
     
  15. James Nicholl

    James Nicholl Forum Member

    Messages:
    354
    Yeah, the comparison with zero fails every time.

    So, whatever magic the devs put in that seemingly simple module made it unusable for this application.
     
  16. James Nicholl

    James Nicholl Forum Member

    Messages:
    354
    Amazingly, I've never wanted to do that.
     
  17. howesc

    howesc New Member

    Messages:
    23
    Hi Salamader - i'm actually building this instrument having watched a couple of your tutorials on YouTube - about audio tables and phrase loopers. Thanks very much for those. So if I use an A/E Perm do you reckon that would be a working solution? Just out of interest. Thanks!
     
  18. salamanderanagram

    salamanderanagram NI Product Owner

    Messages:
    3,454
    probably for use in iir filters, which was probably helpful before core.

    ha, well it does have some uses, but it's generally quite inefficient.

    @howesc, i actually haven't been following along that closely, so i'm not sure. in fact your last picture is kinda confusing. you create an audio signal and then translate back to events , and now you want to translate back to audio? seems like those last two translations are pointless.
     
  19. howesc

    howesc New Member

    Messages:
    23
    Yeah I see your point actually, James' approach is way cleaner so I've adopted it!

    Many thanks for all your help
     
  20. colB

    colB NI Product Owner

    Messages:
    3,969
    Had a bash at an audio rate position with divisions. It's completely from scratch, but I used Herw's test ensemble with the 'Major Scale' macro and lights just for simplicity. Not been exhaustively tested, so watch out. My main goals were rewind when stopped not causing note triggers, and init not causing note triggers. Also, obviously the first note should sound where appropriate :).
    Seems complicated for what it does, but maybe that is required.
    There are macros in the Major Scale module 'clip&wrap' and 'filter&wrap' that either ignore the negative values, or convert them to zeros, so don't forget them if you want to try and use this! There's also one in the lights module...

    Seems like all this crap shouldn't be necessary in Reaktor. It's supposed to make the basics of audio device design easier, and you don't get much more fundamental than a song postion clock... :(
     

    Attached Files: