fiduciary

Author Topic: smooth swing interpolation with pitch-shifted hums  (Read 18373 times)

0 Members and 1 Guest are viewing this topic.

Offline Thexter

  • Force User
  • ***
  • Posts: 148
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #15 on: February 27, 2017, 09:00:39 AM »
Quote
Thexter, have you tried this simplified code?
Does it work the same as the fixed-math code?

Yes, I'm using this code in the electronics for my sixth saber and it seems to be working the same.

Quote
This is not actually a rotation. A rotation would be something like:
  rotate_x = x * cos - y * sin
  rotate_y = x * sin + y * cos

Apologies if this is too detailed. I'm fairly certain that you only need two sentences out of this, but for anyone else reading, and just to have it written out somewhere:

Remember, you're not rotating the actual gyro values. You're rotating the axis against which they're compared. Let's take the case of only looking at gz. Let's create an imaginary basis where positive z points in the direction the saber would rotate if gz were increasing, positive y orthogonal to both positive z and the midline of the saber... or we could just say y is up. Therefore increasing gz rotates us towards this point, and decreasing gz rotates us away from this point. Also, this point is unit length away. It should be noted that this basis is local to the saber, and not global. You never actually get nearer to the point, you just see if you're swinging in that direction.

In this case, our imaginary axis is fixed. We have a small value of let's say 0.3 for the gyro-z, and that's what we use for our hum selection. Gyro-y is basically has no influence. Remember our gyro-total still influences the total volume.


In this next example, we have a large negative gyro-z, so we have around -0.8 for the hum selection.


Now let's rotate this imaginary axis around x. You are correct, the new axis is a rotation of the original:
Code: [Select]
axis_new_z = z * cos( t ) - y * sin( t )
axis_new_y = z * sin( t ) + y * cos( t )


But remember, our original z and y coordinates were 1 and 0 respectively. So, plugging these back into the equation yields:
Code: [Select]
axis_new_z = cos( t )
axis_new_y = sin( t )

Quote
I thought two of the hums were supposed to be controlled independently by the rotated x/z axis?

I may have been unclear on this, and it's probably also where the confusion in the rotation comes from. I should really have said that I'm making a single non-normalized vector of the two independent axes and comparing them to the swing basis (the newly rotated axis). Each gyro axis still contributes, and it's not an orthonormal contribution because it's not unit length, but I can't really say they're independent.

So, I create a swing vector for the gyro < gz, gy > and see how this vector projects onto the rotated axis. So:
Code: [Select]
projection = dot( gyrovector, axis_new )
projection = gz * axis_new_z + gy * axis_new_y

In this case, the projection of gyro-total onto the rotated axis is almost the full length of the gyro-total vector.


In this case, the projection of gyro-total is largely onto the negative rotated axis, yielding a large negative value.


In my code, I've actually scaled and clamped the gz and gy, so it's flNormalizedZ and flNormalizedY, but this doesn't mean the vector is normalized, only each individual is within some scaled and clamped range.

Quote
Shouldn't this be / 2.0 ? As is, m_flMultiHumAmount can be greater than 1 or less than -1.

You would think so, but you can't actually get values of 2 with the code as written because flAmountY and flAmountZ are 90 degrees out of phase. Remember that our total gyro vector can be greater than 1 in magnitude? Well, the maximum magnitude it can have is sqrt( 2 ), since each component can be a maximum of 1 and you peak when you're swinging 45 degrees between the two gyro axes. To keep the total influence below 1, I divide by this. Think of it as a clipping protection.


Offline Greebles

  • Formerly known as Codeweasel
  • Master Force User
  • *****
  • Posts: 773
  • “You must unlearn what you have learned.”
Re: smooth swing interpolation with pitch-shifted hums
« Reply #16 on: February 27, 2017, 09:24:42 AM »
Very cool!

Offline Thexter

  • Force User
  • ***
  • Posts: 148
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #17 on: February 27, 2017, 10:35:03 AM »
I should also point out that you can apply this to accelerometer values as well. It's actually easier to think about because you don't have the added headache of thinking of the angular velocities as plots on an fake zy plane. However, the code is identical assuming you have different code to scale and clamp the accel values into the -1..1 range.

I've not actually done this as I like my swings only to work with rotation and leave the accel for clash detection, but that's just me.

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: smooth swing interpolation with pitch-shifted hums
« Reply #18 on: February 27, 2017, 10:48:04 AM »
I think my confusion comes from comments and variable names mostly.
The code does do what you say, and you're right diviging by sqrt(2) is the right thing to do.
I would probably write the code a little differently though. If you rotate the gyro values and
always project to the X axis, the code becomes:


  x = clamp(x * scale, -1, 1);
  y = clamp(y * scale, -1, 1);
  projected_x = (sin(angle) * x + cos(angle) * y) / sqrt(2.0);


This is in fact exactly the same as your code, but shorter, and less confusing. (At least to me.)

Am I right that you then calculate the volumes kind of like this:

   total_volume = 0.5 + clamp(total_swing_speed, 0.0, 1.5);
   hum_balance = 1- abs(projected_x);
   hilo_balance = (1 - projected_x) / 2;
   hum.set_volume(total_volume * hum_balance);
   hi.set_volume(total_volume * (1 - hum_balance) * hilo_balance);
   lo.set_volume(total_volume * (1 - hum_balance) * (1 - hilo_balance));

?
 
 

Offline Thexter

  • Force User
  • ***
  • Posts: 148
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #19 on: February 27, 2017, 11:29:14 AM »
Quote

  x = clamp(x * scale, -1, 1);
  y = clamp(y * scale, -1, 1);
  projected_x = (sin(angle) * x + cos(angle) * y) / sqrt(2.0);
Fair enough.

Quote
   total_volume = 0.5 + clamp(total_swing_speed, 0.0, 1.5);
   hum_balance = 1- abs(projected_x);
   hilo_balance = (1 - projected_x) / 2;
   hum.set_volume(total_volume * hum_balance);
   hi.set_volume(total_volume * (1 - hum_balance) * hilo_balance);
   lo.set_volume(total_volume * (1 - hum_balance) * (1 - hilo_balance));

I feel that this part is very much up to your ear. That's very close to how I do it. In your case, you get 50% contribution from both hi and lo when projected_x is 0, which is fine because (1 - hum_balance) will be 0 as well. However, you'll still get some influence from both hums when projected_x is slightly off of zero, because of the straight lerp between the two.

In mine, I have a different summation, which only adds in any of the hi or lo hum when projected_x moves away from 0.

I believe modifying your last 2 lines to look like this would achieve the same effect as I did. However, see which one sounds better and do that.
Code: [Select]
  hi.set_volume( total_volume * max( 0, projected_x ) );
  lo.set_volume( total_volume * -min( 0, projected_x ) );

My min total volume is 1 instead of 0.5 because I have an additional scalar on the "total_volume" value. I do this in a per-font basis, but I often scale the "total_volume" much greater than 1 (sometimes 2 or 3) to get that aggressive volume change for smaller swings. It's all related to your thresholds and other scale factors.

Offline tomleech

  • Force User
  • ***
  • Posts: 145
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #20 on: February 27, 2017, 07:08:00 PM »
Awesome, I've been hoping someone would try this route. I actually messaged HiltWorks to offer my assistance to try and get the project going again.

Do you have a video of how this handles with small and large slow movements? That's the nuance I think this method really has over traditional swing triggering and the reason I like it :)

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: smooth swing interpolation with pitch-shifted hums
« Reply #21 on: February 27, 2017, 10:24:06 PM »
Got this implemented in TeensySaber now, but testing/tuning will have to wait until tomorrow.
Hopefully I can find some good looped sounds...

Offline Darth Xusia

  • Master Force User
  • *****
  • Posts: 1255
  • "quit cher whinin' and just build some sabers"
Re: smooth swing interpolation with pitch-shifted hums
« Reply #22 on: February 27, 2017, 10:38:02 PM »
What kind of looped sounds?
Does file size matter?
Thank you Photobucket for the best Sig ever!

Offline Thexter

  • Force User
  • ***
  • Posts: 148
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #23 on: February 28, 2017, 09:37:17 AM »
Awesome, I've been hoping someone would try this route. I actually messaged HiltWorks to offer my assistance to try and get the project going again.

Do you have a video of how this handles with small and large slow movements? That's the nuance I think this method really has over traditional swing triggering and the reason I like it :)


Offline tomleech

  • Force User
  • ***
  • Posts: 145
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #24 on: February 28, 2017, 11:31:05 AM »
That's awesome :D Is 3 tracks the limit processing-wise or could you add more with larger pitch variations or more inbetween stages for more dynamic variation? Watching a bit of the ESB duel now there seem to be more 'pitches' in the swings. I know you said dynamic pitch shifting is too much for the microcontroller but increasing the 'resolution' with a larger number of tracks with different thresholds might feel more realistic for harder and softer swings?

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: smooth swing interpolation with pitch-shifted hums
« Reply #25 on: February 28, 2017, 11:43:15 AM »
Changing the pitch on the fly is totally doable, however it might affect sound quality to some degree, because there is not enough time to do a true high-quality conversion.



Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: smooth swing interpolation with pitch-shifted hums
« Reply #26 on: February 28, 2017, 11:45:44 AM »
Changing the pitch on the fly is totally doable, however it might affect sound quality to some degree, because there is not enough time to do a true high-quality conversion.

Actually, I take that back. True high-quality conversion is possible, but harder, because the there isn't enough cpu to do it the *simple* way. :)

The teensy is capable of mp3 playback, which is similar in difficulty to resampling.

Offline tomleech

  • Force User
  • ***
  • Posts: 145
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #27 on: March 01, 2017, 12:10:19 PM »
Actually, I take that back. True high-quality conversion is possible, but harder, because the there isn't enough cpu to do it the *simple* way. :)

The teensy is capable of mp3 playback, which is similar in difficulty to resampling.

Well that's potentially even more exciting :) I'm working on a looping version of the original projector hum and broken mic cathode tube recordings from a video interview with Ben Burtt that might be good for this.

Offline profezzorn

  • Mining Colony Members
  • Master Force User
  • *
  • Posts: 901
  • May the source be with you.
    • Hubbe's Corner
Re: smooth swing interpolation with pitch-shifted hums
« Reply #28 on: March 02, 2017, 01:07:02 AM »
Got this implemented in the teensysaber software now. (version 1.43 available from Teensy Saber OS (beta))
My implementation doesn't sound quite as awesome as Thexters though. Could be I don't have the right sounds, could be I don't have it tweaked right, or maybe my dynamic compressor is taking some of the omph out of it. Not sure.

To activate the looped swing mode, just add "swingl.wav" and "swingh.wav" to any existing font.
I made my swingl.wav and swingh.wav like this:
Code: [Select]
sox hum.wav swingh.wav speed -180c rate -v
sox hum.wav swingl.wav speed 150c rate -v

Offline KanyonKris

  • Padawan Learner
  • **
  • Posts: 72
  • Um...Hello?
Re: smooth swing interpolation with pitch-shifted hums
« Reply #29 on: November 30, 2017, 08:56:47 AM »
To activate the looped swing mode, just add "swingl.wav" and "swingh.wav" to any existing font.
What directroy do the "swingl.wav" and "swingh.wav" go in? /hum or /swng or doesn't matter?

 

retrousse