SH-101 pwm
- KVRAF
- 12615 posts since 7 Dec, 2004
started messing with some code and wrote this, the output is perfectly accurate for the average synth psu.
http://xhip.cjb.net/temp/public/psunoise.c
i've used -55db, you might want to use -70db as in the 7815 data-sheet. -55db is closer to the noise level you get out of the average synth after it gets amplified by however many stages. the level of noise on the power rails is probably more around -70db, or 5mvpp maximum.
here is the output, normalized with the dc clunk removed:
http://xhip.cjb.net/temp/public/psu_noise.wav
http://xhip.cjb.net/temp/public/psunoise.c
i've used -55db, you might want to use -70db as in the 7815 data-sheet. -55db is closer to the noise level you get out of the average synth after it gets amplified by however many stages. the level of noise on the power rails is probably more around -70db, or 5mvpp maximum.
here is the output, normalized with the dc clunk removed:
http://xhip.cjb.net/temp/public/psu_noise.wav
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
The pitched noise in the first note suggest that you're BLEP is either slightly mispositioned or inaccurately scaled. At least that's what my code had wrong when I last heard such noise.nollock wrote:The next thing I noticed is that it sounded progressively more dirty the lower you go down in pitch. For example...
www.flak.clara.co.uk/PWM1.wav
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
Now that sounds clean, but you should be able to add some variation without getting the ugly pitched noise in the other two examples, so are you sure you are positioning all bleps correctly?nollock wrote:Here's one with no pulsewwidth variation, for referance.
www.flak.clara.co.uk/PWM3.wav
I had at one point a problem wherein I would calculate BLEP positions wrong, but they happened to end up in the right place anyway (because of another error, really) so a totally stable wave would sound wonderful, but any modulation (even just slow glide) would produce strange glitches (if I remember it right anyway).
- KVRAF
- 12615 posts since 7 Dec, 2004
the main issue we have to remember when emulating these effects though is that the electronics are going to have frequencies up into several mhz on the supply rails.. in fact looking on a scope most of the energy passed through is around 1mhz as the ESR of the capacitors makes them less effective at higher frequencies. the reset point of the oscillators _is_ influenced by this high-frequency noise as non-linear elements rectify and distort the signal bringing it down into the audible range.
despite what i do know about these effects, the main reason i havent yet gone to much effort to duplicate them is that i do not know everything. without creating a fully accurate model which can cover all possible effects i think we'll still be missing out on the timbres we get from analog oscillators, especially the discrete variety.
i wish i could think of how to accurately reproduce the effects this high-frequency noise may have.. i think we're limited to the audible frequency range here..
despite what i do know about these effects, the main reason i havent yet gone to much effort to duplicate them is that i do not know everything. without creating a fully accurate model which can cover all possible effects i think we'll still be missing out on the timbres we get from analog oscillators, especially the discrete variety.
i wish i could think of how to accurately reproduce the effects this high-frequency noise may have.. i think we're limited to the audible frequency range here..
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
Oh and in case it's a "post your square and PWM waves"-competition, here's mine: the square is just that, but the pwm is fake; square synced to another oscillator with LFO tweaking it's frequency below that of the master. That way it does produce more noise than normal PWM would, but I still haven't come around to implementing direct PWM functionality so had no choice.
In any case, both are rather straight-forward BLEPs. They are run through a filter that's fully open, since I could be bothered to bypass it (would have needed a recompile), but since the filter isn't exactly linear that does produce more some distortion. Please ignore any of that.
In any case, both are rather straight-forward BLEPs. They are run through a filter that's fully open, since I could be bothered to bypass it (would have needed a recompile), but since the filter isn't exactly linear that does produce more some distortion. Please ignore any of that.
-
- KVRian
- 1153 posts since 10 Dec, 2003
That's exactly what you're doing when you add noise to the pulsewidth, you're adding random inacuracy to the positioning of the blep.mystran wrote: The pitched noise in the first note suggest that you're BLEP is either slightly mispositioned or inaccurately scaled. At least that's what my code had wrong when I last heard such noise.
I guess you can consider PWM to be rather like frequency / phase Modulation. At least my experiments with audio rate PWM sound very much like that.
This is my blep oscillator self modulating it's own pulsewidth. It is just the output of a single oscillator, self modulating itself, with some LFO applied aswell, and some realtime tweaks to pulsewidth / mod levels.
www.flak.clara.co.uk/PWM6.wav
So imo, modulating the pulsewidth with noise is just like phase modulating a wavetable with noise. You will get some noise in the output.
www.flak.clara.co.uk/PWM4.wavbut you should be able to add some variation without getting the ugly pitched noise in the other two examples, so are you sure you are positioning all bleps correctly?
www.flak.clara.co.uk/PWM5.wav
Actualy you do kindof of hit on a conclusion i came to during my messing around with this. That variation added to the pulsewidth would be better if it was random drift, rather than random noise. So some sort of chaotic but smooth lfo would be preferable imo.
That said i think random noise is probably closer to what an 'analog' oscillator does.
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
But I wasn't objecting to the noise itself. Let's see, I'll look at the sample one in wave editor..nollock wrote: That's exactly what you're doing when you add noise to the pulsewidth, you're adding random inacuracy to the positioning of the blep.
Actually "some sort of chaotic but smooth LFO" sounds a whole lot like low-pass filtered noise to me, and I don't think it's out of question that they could be such effects going on in a given analog oscillator.Actualy you do kindof of hit on a conclusion i came to during my messing around with this. That variation added to the pulsewidth would be better if it was random drift, rather than random noise. So some sort of chaotic but smooth lfo would be preferable imo.
That said i think random noise is probably closer to what an 'analog' oscillator does.
Anyway, this discussion is getting funny again, 'cos there are tons of good and bad and in-between analog designs, not all of them even have a saw-core (say a triangle-core can use comparator to produce pulse waves just like a saw-core, but will get supposed limited-gain effect on both transitions; for such an oscillator the tricky thing is coming up with a good saw).
- KVRAF
- 12615 posts since 7 Dec, 2004
you shouldn't be touching the pulse-width at all.. what i've described already does this effect without needing to meddle with any additional stuff like pulse width.
you should simply run code like i've posted (the psu_noise.c file) and use the output from that like this:
reset_point = some_fraction * dc_blocking_input;
there is an error in my code:
T rectified_mains = fabs(mains - vd);
this should read:
T rectified_mains = fabs(mains) - vd;
if (rectified_mains < 0.0) rectified_mains = 0.0;
could apply a diode voltage-to-voltage approximation here to be absolutely 'correct', but this isnt really going to make a difference in this case.
you should actually difference the signal before this line:
T dc_blocking_input = (psu_caps + pink * thermal_noise_level) * regulator_ripple_rejection;
so that the dc has already been blocked. you can then add the 'ripple' signal to clip(psu_caps + pink * thermal_noise_level). clip() can be a hard clip, a quick approximation or the correct zener function if you're willing to go so far. i would do a simple hardclip with a very simple approximation voltage added on.
you'll then have your accurate 12+ or 15+, or whatever level signal. scale that down to whatever your oscillator is running at, generally 5.0+ in a circuit, probably 1.0+ in your code.
regulator_input = psu_caps + pink * thermal_noise_level;
regulator = clip(regulator_input) + difference(regulator_input) * regulator_ripple_rejection;
reference = regulator * (1.0 / 15.0); //we'll assume clip gives 15+ nominal, your osc runs at 1.0+.
phase_accumulator += delta;
if (phase_accumulator > reference) phase_accumulator -= 1.0;
in most cases the "1.0" value will be constant, even in an analog circuit. it may decrease slightly at higher frequencies. most oscillators have a "linearity" trimmer for this. it causes a flattening of higher frequencies if left untrimmed. we can pretty much ignore this in software with no loss.
the "ripple rejection" factor is actually related to how hard a clip takes place in the clip() function. if you use a perfectly accurate zener function here you dont need to add the differenced ripple signal. if you use a hard-clip, leave it the way i've written it.
btw, for some fun add a on/off button to your gui to shut on or off the ac input and try using this supply voltage in all your "circuits" as a reference. for example, the cutoff control should be scaled between 0.0 and reference so that when you turn off the power all the cv drops off just as it would in the analog version.
you should simply run code like i've posted (the psu_noise.c file) and use the output from that like this:
reset_point = some_fraction * dc_blocking_input;
there is an error in my code:
T rectified_mains = fabs(mains - vd);
this should read:
T rectified_mains = fabs(mains) - vd;
if (rectified_mains < 0.0) rectified_mains = 0.0;
could apply a diode voltage-to-voltage approximation here to be absolutely 'correct', but this isnt really going to make a difference in this case.
you should actually difference the signal before this line:
T dc_blocking_input = (psu_caps + pink * thermal_noise_level) * regulator_ripple_rejection;
so that the dc has already been blocked. you can then add the 'ripple' signal to clip(psu_caps + pink * thermal_noise_level). clip() can be a hard clip, a quick approximation or the correct zener function if you're willing to go so far. i would do a simple hardclip with a very simple approximation voltage added on.
you'll then have your accurate 12+ or 15+, or whatever level signal. scale that down to whatever your oscillator is running at, generally 5.0+ in a circuit, probably 1.0+ in your code.
regulator_input = psu_caps + pink * thermal_noise_level;
regulator = clip(regulator_input) + difference(regulator_input) * regulator_ripple_rejection;
reference = regulator * (1.0 / 15.0); //we'll assume clip gives 15+ nominal, your osc runs at 1.0+.
phase_accumulator += delta;
if (phase_accumulator > reference) phase_accumulator -= 1.0;
in most cases the "1.0" value will be constant, even in an analog circuit. it may decrease slightly at higher frequencies. most oscillators have a "linearity" trimmer for this. it causes a flattening of higher frequencies if left untrimmed. we can pretty much ignore this in software with no loss.
the "ripple rejection" factor is actually related to how hard a clip takes place in the clip() function. if you use a perfectly accurate zener function here you dont need to add the differenced ripple signal. if you use a hard-clip, leave it the way i've written it.
btw, for some fun add a on/off button to your gui to shut on or off the ac input and try using this supply voltage in all your "circuits" as a reference. for example, the cutoff control should be scaled between 0.0 and reference so that when you turn off the power all the cv drops off just as it would in the analog version.
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
Ok, I can't find it from the waveform (PWM1), though it's clearly visible when you look at it in spectrogram view, but it really sounds like a buffer-overflow by one sort of error somewhere. What should happen for some random variation is that you'd get faint traces in the spectrum at the missing harmonics, and then some noise elsewhere, but what I'm seeing (and hearing) is either variation between two sets of harmonics on per cycle basis (32 or so bands FFT view, zoom in a lot into the first note), or interesting triple peaks for all (existing and missing) harmonics. I'll post a picture:mystran wrote:But I wasn't objecting to the noise itself. Let's see, I'll look at the sample one in wave editor..nollock wrote: That's exactly what you're doing when you add noise to the pulsewidth, you're adding random inacuracy to the positioning of the blep.

Those peaks are stable for the duration of the note too.
- KVRAF
- 12615 posts since 7 Dec, 2004
http://xhip.cjb.net/temp/public/on_off.mp3
ok, so you dont get the effect as audible when the output is taken off the vca because the vca cuts off almost immediately when the voltage starts to droop.
http://xhip.cjb.net/temp/public/osc_stuff.mp3
i guess mp3 kind of sucks, so if somebody wanted to look closely at that:
http://xhip.cjb.net/temp/public/osc_stuff.wav <-- dont download this if you only want to listen[/b]
ok, so you dont get the effect as audible when the output is taken off the vca because the vca cuts off almost immediately when the voltage starts to droop.
http://xhip.cjb.net/temp/public/osc_stuff.mp3
i guess mp3 kind of sucks, so if somebody wanted to look closely at that:
http://xhip.cjb.net/temp/public/osc_stuff.wav <-- dont download this if you only want to listen[/b]
- KVRAF
- 8476 posts since 12 Feb, 2006 from Helsinki, Finland
Oh it's an oscillator trick competition. I'm afraid I can't do much on that front, though here's two synced oscillators with filter completely open all the time, no FM (other than the slight vibrato and slave pitch envelope), no ringmod, just straight-forward BLEP. I guess that makes me kinda sad.
-
- KVRian
- 1153 posts since 10 Dec, 2003
Dohhhh!!! Well spotted!!!mystran wrote: Ok, I can't find it from the waveform (PWM1), though it's clearly visible when you look at it in spectrogram view, but it really sounds like a buffer-overflow by one sort of error somewhere. What should happen for some random variation is that you'd get faint traces in the spectrum at the missing harmonics, and then some noise elsewhere, but what I'm seeing (and hearing) is either variation between two sets of harmonics on per cycle basis (32 or so bands FFT view, zoom in a lot into the first note), or interesting triple peaks for all (existing and missing) harmonics. I'll post a picture:
Those peaks are stable for the duration of the note too.
I found it. What i was doing wrong was this..
I was using (phase+offset) for the comapritor.
And using (phase) for the sub sample positioning.
Thats why it didnt show up in the other samples.
Anyway I've go to go out for a few hours now, but when I get back later I'll post some updated samples.
I might try knocking up some with some lowpassed noise aswell.
cheers for the help.
chris
-
- KVRian
- 1153 posts since 10 Dec, 2003
Well tbh i've been working on these the last 2 weeks and was fairly chuffed when I got the audio rate PWM working so well... I do admit I was waiting for an excuse to post some samplesmystran wrote:Oh it's an oscillator trick competition.
So i think that makes me saddest of all! Whoo hoo!
Well actualy, my being a boring computer geek doesnt help either.
-
- KVRist
- Topic Starter
- 120 posts since 10 Aug, 2005
I think it's easier if you use blamps instead of bleps and have each ramp time fixed which is your slew rate limiting. You can have a different slope on the up and down easily this way. So you never jump with a step, you always ramp to the new value at a constant rate.mystran wrote: So what you are trying to say here, is that one should use two different BLEPs (say with slightly different cutoffs...
-
- KVRist
- Topic Starter
- 120 posts since 10 Aug, 2005
I'm loving all the examples, thanks for posting them. The first audio rate pwm I did was emulating the arp 2600 example on the way out ware page, theirs is so bad I couldn't believe they posted it as an example of how good their stuff is:nollock wrote:Well tbh i've been working on these the last 2 weeks and was fairly chuffed when I got the audio rate PWM working so well.mystran wrote:Oh it's an oscillator trick competition.
http://www.wayoutware.com/twarpsamples.html.
Time to refresh my version of this now that I have a little bit of noise on my oscillators.
