SynthMaker

How to rotate phase of wav sample at 45 degrees

Archive · 2012 28 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

Dimmak0001 ·

Plese help me to find answer. 🙂

Warmonger ·

You know, degrees are related to signal frequency. It can be sampling frequency (which wouldn't make much sense then) or a certain sound in that sample. What do you exactly want to do?

martinvicanek ·

Do you mean something similar to a Hilbert transformer (=a device which generates a 90 degree phase shift over a wide frequency band)? But why 45 degrees?

Dimmak0001 ·

I just want to rotate phase of wav sample around 'circle'( formula with 3.14 ). Not shift, but rotate to any degree from 0 to 180. 😉

Warmonger ·

I ask what you mean by "phase of sample". Samples have no phase parameter as far as I know.

Dimmak0001 ·

Warmonger wrote: I ask what you mean by "phase of sample". Samples have no phase parameter as far as I know.

Sorry... Wav section. Phase of frequency 🙂

Warmonger ·

Phase of which frequency?

Dimmak0001 ·

Warmonger wrote: Phase of which frequency?

phase of wave.

Warmonger ·

If you want just to delay it by 1/8 of period (or wrap around), it shouldn't be hard, assuming you can have buffer long enough.

I don't think this could be of any use, though.

treacherousumbrella ·

The delay time related to a 45 degree shift will be different for each frequency, proportional to the wavelength of that frequency. Shifting a harmonically rich waveform by 45 degrees requires a different delay time for each frequency present. You may want to look into both the Hilbert transform and allpass filter. It's not as simple as you might think unless you are talking about phase shifting a sine wave, in which case the delay time for a 45 degree phase shift can be easily calculated from the wavelength

Warmonger ·

Hilbert transform is quite different, as these are only two SINE waves which are shifted by 90 degrees.

You may try to google for "phase correction", however that's advanced topic and it will be hard to find something free and usable.

Dimmak0001 ·

treacherousumbrella wrote: ...unless you are talking about phase shifting a sine wave, in which case the delay time for a 45 degree phase shift can be easily calculated from the wavelength

Yes, please. How to calculate in that case?

treacherousumbrella ·

Sample rate / frequency(Hz) = Number of samples per cycle 360 degrees / 45 degrees = 8 Number of samples per cycle / 8 = Delay time in samples for a 45 degree shift at the frequency of the input sinusoid

MegaHurtz ·

Dimmak0001 wrote: I just want to rotate phase of wav sample around 'circle'( formula with 3.14 ). Not shift, but rotate to any degree from 0 to 180. 😉

180 degree is easy just invert :P But a typical alpass has the same kind of 180 phase shift. So basically its a paradox :/. But you could go around messing the signal and cpu up using a hilbert transform. Personally i`d just use it for single sideband modulation. I agree for practical applications a delay is a good solution for phase issues. If that was what was said when i was skipping over the text, else ^^. For a practical solution.

Warmonger ·

Compute the offset as sampleSize * (phaseShift / 360), then just copy elementar samples in loop.

or just strat playback at offset and wrap it when it reaches sample's end, if you wnat to create a sampler.

Dimmak0001 ·

treacherousumbrella wrote: Sample rate / frequency(Hz) = Number of samples per cycle 360 degrees / 45 degrees = 8 Number of samples per cycle / 8 = Delay time in samples for a 45 degree shift at the frequency of the input sinusoid

Thanks. 🙂

MegaHurtz wrote: 180 degree is easy just invert :P But a typical alpass has the same kind of 180 phase shift. So basically its a paradox :/.

Ok from 1 to 179. But now I understand how its hard to do.

Dimmak0001 ·

Warmonger wrote: Compute the offset as sampleSize * (phaseShift / 360), then just copy elementar samples in loop.

or just strat playback at offset and wrap it when it reaches sample's end, if you wnat to create a sampler.

No I dont want to create a sampler, but thanx anyway! 🙂

trogluddite ·

MegaHurtz wrote: 180 degree is easy just invert :P

An inversion is not a 180 degree phase shift. By sheer coincidence of the maths, it just happens that you get the same result if, and only if, the waveform is symmetrical about its zero crossings (i.e. pure sine, square, etc. oscillator.) For a complex waveform (i.e. the kind of thing you might want to sample), they are very, very rarely the same thing. This is why flanger/phasing effects often have an invert button - because mixing in the "upside down" version of the waveform results in different cancellations, and so a different sound. Still a useful thing for sure, but not a phase shift.

Moving the samples backward or forward in time is the right idea, and as said it's a case of dividing up the number of samples in each cycle of the waveform. SM's stock oscillators do exactly this when you use their 'phase' inputs (the wavetables that they use are just an advanced form of sample playback). A simple "Interpolated delay" modules is enough for this, so long as you can work out the exact amount of samples for the delay time - so the tricky part of the problem is to know the frequency of the sound. If the frequency is known (e.g. single notes on a instrument) that is easy - otherwise, there are some nice "pitch detection" modules around on the forum that will be worth playing with.

PS) Sorry MHz if I seemed a bit harsh - not meant that way, but the invert/phase-shift thing is my particular DSP pedantry fetish! 😉

Dimmak0001 ·

trogluddite wrote: ...there are some nice "pitch detection" modules around on the forum that will be worth playing with.

Examples, please! 🙂

MegaHurtz ·

Nah man.. Ooh you should see what I do, (but thats so top secret because it changes regular wave theory for a bit) and the delay immabout to release the 25th. But i have some work to do yet this weekend 16 hr days.. http://www.schlukhash.nl is the starting point. Needs some clips and reviews but in time. in time.. hoping because the price isnt that steep people may want to stick with it, for optimisations. But the general thing is ready and sounding smooth as silk. Except for the raw granular sounds it makes 😈

My conception tho.. is that it`s the same harmonics but cancelled out io added 🙂 basically because the sample would disappear when overlapped. But i do mean just delay it so that the phase issue resolves in relation to the music its in. But it all depends on the stuff you are planning to do with it, for an oscillator or wavetable the options are plenty. (a reciprocal for instance). This was just for the mixing scenario.

trogluddite ·

Dimmak0001 wrote: Examples, please!

Pitch Extraction Thread - Martin's method in this thread is the most accurate that I've seen in SM. The theory is complex, but the schematic have easy to use modules that you can cut and paste, so you don't have to understand all the maths. Trogz Toolz - this is a big toolkit of handy SM modules. Inside the "Stream, Code and ASM' section is my own take on getting audio freq etc. - much more crude than Martin's, but very low CPU use.

tester ·

...which reminds me that I have a question here too. What is the relation between delay and circular phase offset for sine waves? Picture to illustrate this - is here: capture state

trogluddite ·

tester wrote: What is the relation between delay and circular phase offset for sine waves?

Wavelength (samples) = Sample Rate / Frequency. (for any wave, not just sines). ...so if phase runs from zero to one (normalised)... Delay = Phase * SR / Freq. ...or phase in radians... Delay = Phase / (2*Pi) * SR / Freq ...or degrees... Delay = (Phase / 360) * SR / Freq

For good accuracy be sure to use an interpolated delay, as the phase offset will be a non-integer number of samples for the vast majority of phase shifts.

In SM we mostly use normalised (zero to one) frequency values, where: Fnorm = 2 * Freq / SR. Or, in reverse: Freq = Fnorm * 0.5 * SR. Substituting gives the equation when using all normalised values...

Delay = Phase * SR / (Fnorm * 0.5 * SR) --> Delay = Phase * 2 / Fnorm.

Dimmak0001 ·

trogluddite thanks!

tester ·

So my point is (because my math is not so much) - on X axis, portions of circular degrees of a sine wave = linearly equal divisions of time?

Warmonger ·

Yes, it is really that simple :P

tester ·

Well - that simplifies a lot, thanks. 😉

trogluddite ·

There's a little animation on the Wikipedia sine wave page that shows this very well.

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.