Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Pitch Snapping

For general discussion related FlowStone

Pitch Snapping

Postby Perfect Human Interface » Fri Feb 27, 2015 8:04 am

Sometimes I get to checking back here regularly and I get a little bummed that there often aren't many new posts to look at. But thankfully, I can always come up with questions to ask. :D

Current problem to figure out is pitch snapping. This is taking a raw frequency value and adjusting it to the nearest note pitch at sample rate. First thing's first, I need to figure out the nearest note pitch based on the input. Then I can work out any more complex behaviors.

So how do we do that? Just do some maths to convert to a linear, integer-based standard like MIDI note numbers, do a little roundint, then convert back from MIDI to Hz. No problem.

MIDI to Freq.PNG
MIDI to Freq.PNG (3.45 KiB) Viewed 13381 times


...obviously not going to work so hot at sample rate. So how can I do this faster?

I could pile all the standard Hz values of MIDI notes into an array and start doing comparisons/sorts. But with 127 notes that could be a lot of comparisons (and no, I don't remember from high school how to calculate how expensive these operations actually are but I know they're not free), and it also doesn't account for the logarithmic scaling of note frequency values.

I know there are "fast" versions of power and log that do approximations. "Reasonably accurate" should definitely be good enough in this case. But really this efficiency stuff is beyond me. So if anyone has some direction they could lend that would be really appreciated!
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Pitch Snapping

Postby martinvicanek » Fri Feb 27, 2015 7:32 pm

There is a pitch manager post here. The schematic has a pitch quantizer that may give you some inspiration.
Optimized pith/frequency converters can be found in the stream functions pack at flowstone guru. You don't need to update the pitch at sample rate, I have found hop(32) sufficient.
Hope that helps!
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: Pitch Snapping

Postby tulamide » Fri Feb 27, 2015 11:11 pm

martinvicanek wrote:I have found hop(32) sufficient.

If this was pitching audio generated from midi, would it be sufficient to just calculate once per midi note, using that result until next note?
If this was just pitching any audio, would it be sufficient to calculate once? Assume a voice recording and 440 Hz should be pitched to 493.88 Hz (A4 to B4), would it be sufficient to calculate both at the beginning, then never again?
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Pitch Snapping

Postby Perfect Human Interface » Sat Feb 28, 2015 12:22 am

martinvicanek wrote:You don't need to update the pitch at sample rate, I have found hop(32) sufficient.


Actually yeah, I'm not sure why these things don't occur to me. :) These forums and you folks are a godsend. If this place ever properly died I wouldn't be able to use Flowstone at all haha.
I will definitely check out the stream functions stuff, and I'm of course quite familiar with your pitch manager work, although I assumed quantizing to specific notes would be different from finding the nearest notes. Thanks!

tulamide wrote:If this was pitching audio generated from midi, would it be sufficient to just calculate once per midi note, using that result until next note?
If this was just pitching any audio, would it be sufficient to calculate once? Assume a voice recording and 440 Hz should be pitched to 493.88 Hz (A4 to B4), would it be sufficient to calculate both at the beginning, then never again?


If you're using MIDI, you already have your pitch data built in there so I don't see the need to do any detection and analysis.

If you mean audio from another plugin triggered by MIDI, then A) your Flowstone plugin wouldn't know if it were MIDI triggered or not, B) it would entirely depend on the kind of output (the pitch may not be static, MIDI triggered or not), and C) you can't know the actual note on and off points so "beginning" and "end" are abstractions unavailable to you in your design.
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Pitch Snapping

Postby RJHollins » Sat Feb 28, 2015 1:52 am

... and from a previous thread ....

a Shout out to Uncle Martin ! :D
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Pitch Snapping

Postby Perfect Human Interface » Tue Mar 03, 2015 11:22 pm

So Martin's fast stream functions worked easy-peasy as shown here.

Snap.PNG
Snap.PNG (27.18 KiB) Viewed 13295 times


But I also wanted to try a hop as suggested. Unfortunately I don't know a lick of ASM so pic above also shows how far I got with that. :lol:

Is this just a matter of pasting this stuff in the right places or is it more complicated than that? Haha
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: Pitch Snapping

Postby KG_is_back » Sat Mar 07, 2015 12:43 am

Perfect Human Interface wrote:But I also wanted to try a hop as suggested. Unfortunately I don't know a lick of ASM so pic above also shows how far I got with that.

Is this just a matter of pasting this stuff in the right places or is it more complicated than that? Haha


In this particular case it is as simple as that. Copy the code between "jnz end0;" and "end0:"

Also make sure that there is no "end0:" in the original code, or there will be doubled label and code will crash (to prevent it, simply rename it).

To explain how hop works:
Code: Select all
mov eax,ecx; //copy ecx to eax register
// ecx holds the index of the sample (each sample it increases by 1 )
and eax,7; //this is basically eax % 8 (a binary trick for fast modulo of powers of two)
cmp eax,0; //compare with zero
jnz end0; //if the result was not equal, jump to "end0:"

//here should be the code you want to hop

end0: //this label marks the spot, where the (to be) hopped code ends.



Theoretically it should work as expected, except for obvious reasons when using code in hop (for example filters will be messed up if used in hop)
KG_is_back
 
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Pitch Snapping

Postby Perfect Human Interface » Sat Mar 07, 2015 11:41 am

Thanks KG! One more thing for the meager bag o' tricks. ;)
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm


Return to General

Who is online

Users browsing this forum: No registered users and 69 guests