Old 01-21-2018, 03:21 PM   #1
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default Anti-aliased single-sample pulse osc?

I'm trying to work on this wonky idea I had. Basically, instead of using an oscillator, you repeat any sample you want at the given frequency. I can't find anything that does this so I'm trying to do it on my own.

It would take me a long time to program a sampler that could do this probably, so I had another idea to make it easier. Essentially I want to make a synthesizer that outputs single-sample pulses and has all the normal controls you would see on a synth. It sounds like utter garbage by itself, but then you apply a convolution reverb to it with say a kick drum sample. It actually sounds kind of cool from what I've done so far.

The problem I'm having is making this pulse oscillator. I have something so far, but it suffers from terrible aliasing and pitch inaccuracies. What I'm doing so far is just outputting one sample high and the rest low for any given frequency, but as you get higher and higher notes, the problem gets worse. I know why the problem is there, I just don't know a solution.

If anyone can help I would appreciate it.
Alkamist is offline   Reply With Quote
Old 01-21-2018, 03:51 PM   #2
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,643
Default

ReaRack has a module called the Karplus-Strong delay which I think does something like what you are proposing. The Karplus-Strong algorithm is used to physically model stringed instruments and does so by looping an impulse or sample at the desired frequency, then filtering the output to create the decay. Usually white noise is used as the impulse. The ReaRack module does the looping part of the algorithm. Other modules are used to complete the algorithm, e.g. noise generator for the source noise and a filter module together with an envelope generator for the filter decay.

It might be worth researching the Karplus-Strong algorithm. Issues such as pitch stability are discussed. Ref:http://static1.1.sqspcdn.com/static/...Gs7NE%2BOjo%3D
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth

Last edited by Time Waster; 01-21-2018 at 04:02 PM. Reason: Found a reference.
Time Waster is offline   Reply With Quote
Old 01-21-2018, 10:21 PM   #3
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,773
Default

Quote:
Originally Posted by Alkamist View Post
instead of using an oscillator, you repeat any sample you want at the given frequency.
Most Samplers feature a loop mode that does this. Usually you loop only a part of the sample, but you can also loop the from beginning to end. (Looping frequency usually much lower than pitch)

AFAIK, if you think of predefined short sample, this is called a WaveTable synth. Most of them use a sequence of multiple samples. (Looping frequency usually equal pitch.)

-Michael

Last edited by mschnell; 01-22-2018 at 08:08 AM.
mschnell is offline   Reply With Quote
Old 01-21-2018, 11:11 PM   #4
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,643
Default

To be clear, the looping frequency is determined by the required pitch, e.g. to play note A 440, the looping frequency is 440 Hz.
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 01-22-2018, 08:34 AM   #5
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default

I've heard about the Karplus-Strong algorithm. I was thinking it is a little different, but I'll look into your resources to see if I can learn anything.

And unfortunately, sample looping is not what I'm looking for. What I want is for the each play of the sample to be capable of overlapping. They also should not scale with pitch. The only thing that should change with pitch is how fast they are being triggered.
Alkamist is offline   Reply With Quote
Old 01-22-2018, 11:03 AM   #6
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default

I managed to figure something out. I looked at Tale's polyblep oscillator and just screwed around until I could get it working. I very barely understand it, but here is what I did. It needs to be DC filtered though or there are problems.

Code:
@init

function _POsc_setdt(dt)
(
    dt <= 0.2 ? 1 : dt < 0.25 ? 1 - sqr(20 * (dt - 0.2));
    // 0 otherwise
);

function POsc_setdt(time)
(
    this.a = _POsc_setdt(time);
    this.dt = time;
);

function POsc_setFrequency(freq)
(
    this.POsc_setdt(freq / srate);
);

function _POsc_blep(t, dt)
(
    t < dt ?
    (
        // x = t/dt
        // y = -(x^2) + 2*x - 1
        -sqr(1 - t / dt);
    ) :

    t > 1 - dt ?
    (
        // x = (t - 1) / dt
        // y = x^2 + 2*x + 1
        sqr(1 - (1 - t) / dt);
    );

    // 0 otherwise
);

function _POsc_increment()
(
    this.t += this.dt;
    this.t -= this.t | 0;
);

function POsc_process()
  local(t1, t2, y, pw)
(
    pw = 0.999 * this.dt;

    t1 = this.t;

    t2 = this.t + 1 - pw;
    t2 -= t2 | 0;

    this._POsc_increment();

    t1 < pw ? y = 1 : y = 0;

    y += _POsc_blep(t1, this.dt) * 0.5 - _POsc_blep(t2, this.dt) * 0.5;

    this.output = this.a * y;
);

function POsc_getOutput()
(
    this.output;
);
Alkamist is offline   Reply With Quote
Old 01-22-2018, 11:56 AM   #7
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 7,293
Default

That's not actually a whole plugin. When you get it working, will you please post it? I've been looking for something like this for years. The idea of pressing a convolution plugin into service is pretty ingeneous.
ashcat_lt is offline   Reply With Quote
Old 01-22-2018, 12:12 PM   #8
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default

I'll post it if I can get it working. I'm still getting a little aliasing, which is enough to add very loud resonances to higher notes after convolution.

I'll probably have to use a different method than polyblep for the antialiasing. If anyone has any advice I'm down to hear it.
Alkamist is offline   Reply With Quote
Old 01-22-2018, 02:05 PM   #9
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default

I think I'm finding now that my problem actually isn't aliasing. I think that's fine now.

My problem is that there is DC offset, but when you apply a DC offset filter, it takes too long to activate at the beginnings and ends of high notes, which causes very loud low end booms after convolution.

Is there a way to filter out the DC offset from an oscillator quickly?

EDIT: Just found that I can subtract by a frequency dependent function to eliminate the DC offset. This has the result I want for now. Still need more work on synth functions though.

Last edited by Alkamist; 01-22-2018 at 02:20 PM.
Alkamist is offline   Reply With Quote
Old 01-23-2018, 03:00 AM   #10
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by Alkamist View Post
It would take me a long time to program a sampler that could do this probably, so I had another idea to make it easier. Essentially I want to make a synthesizer that outputs single-sample pulses and has all the normal controls you would see on a synth. It sounds like utter garbage by itself, but then you apply a convolution reverb to it with say a kick drum sample. It actually sounds kind of cool from what I've done so far.
That's a neat hack! Instead of taking the input and adding delays to repeat it, you synthesise the impulse response, and then use a convolution plugin to add the "input" sound. What a great way to test a prototype!

Quote:
Originally Posted by Time Waster View Post
ReaRack has a module called the Karplus-Strong delay which I think does something like what you are proposing. [...] The ReaRack module does the looping part of the algorithm. Other modules are used to complete the algorithm, e.g. noise generator for the source noise and a filter module together with an envelope generator for the filter decay.
So, I think part of the Karplus-Strong idea is for there to be filtering inside the delay loop - if you apply a filter-sweep afterwards you can approximate this, but it's not quite the same. I haven't played around with ReaRack though, so I don't know what it does or doesn't have.

Quote:
Originally Posted by Alkamist View Post
I've heard about the Karplus-Strong algorithm. I was thinking it is a little different, but I'll look into your resources to see if I can learn anything.
Yeah, what you've described above is indeed very similar to Karplus-Strong.

K-S is a feedback-delay loop, where the delay time is tuned to the frequency of your "string". So if you play an input sound (e.g. a kick drum) into a K-S resonator, that input sound will repeat every 1/440th of a second (or whatever your note is), which sounds like exactly what you want.

It also puts a filter inside the delay loop, so that (usually) every repetition is slightly more damped in the high-frequencies - this is how it produces the string-like sound, because that's similar to the energy loss as a wave reflects up and down the string.

Last edited by geraintluff; 01-23-2018 at 03:32 AM.
geraintluff is offline   Reply With Quote
Old 01-23-2018, 03:21 AM   #11
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by Alkamist View Post
It sounds like utter garbage by itself, but then you apply a convolution reverb to it with say a kick drum sample. It actually sounds kind of cool from what I've done so far.
Aw yiss - kick drums combined with K-S delays/resonators like that make a great bass synth. I have a Karplus-Strong synth which I use a lot for bass and guitar-ish sounds.

Another thing that's fun is holding a chord open (i.e. a set of independent delays/resonators), and playing a drum loop through it - that's not really possible with the architecture you've described though.

(audio demo and project file)

I've also had a great time beatboxing, or making whooshing/babbling noises, and putting that through the resonator. Suddenly, a whole bunch of sounds from ambient-ish artists I like (e.g. Tripswitch) were possible! (audio demo)

Do share your plugin when it works, I look forward to hearing it! Although the principles are the same, every implementation has its own strengths, and you sound like you've got some cool ideas.

Last edited by geraintluff; 01-23-2018 at 03:41 AM.
geraintluff is offline   Reply With Quote
Old 01-23-2018, 05:48 AM   #12
Time Waster
Human being with feelings
 
Time Waster's Avatar
 
Join Date: Aug 2013
Location: Bowral, Australia
Posts: 1,643
Default

Quote:
Originally Posted by geraintluff View Post
So, I think part of the Karplus-Strong idea is for there to be filtering inside the delay loop - if you apply a filter-sweep afterwards you can approximate this, but it's not quite the same.
Yes, I have adapted the algorithm to suit the modular system. It's actually more complex because you need an envelope to control the filter cutoff frequency, but all the pieces were there, except for the pitch controlled delay, so it made sense to me to use them. The end result is fairly similar, if not identical to the original method. An advantage of doing it this way is that you can use, for instance, a high pass filter instead of low pass, so you can produce cymbal or bell sounds. One interesting aspect of Karplus-Strong is that because it is (typically) seeded with noise, no two notes sound exactly alike, which can sound more natural (assuming you recreate the sample for each new note).
__________________
Mal, aka The Wasters of Time
Mal's JSFX: ReaRack2 Modular Synth
Time Waster is offline   Reply With Quote
Old 01-23-2018, 06:26 AM   #13
geraintluff
Human being with feelings
 
geraintluff's Avatar
 
Join Date: Nov 2009
Location: mostly inside my own head
Posts: 346
Default

Quote:
Originally Posted by Time Waster View Post
An advantage of doing it this way is that you can use, for instance, a high pass filter instead of low pass.
There's nothing to stop you from putting a low-shelf (or a bandpass/peak EQ) in a K-S feedback loop. The main difference is that for an in-loop filter, the decay pattern for every frequency is exponential, just at different rates (defined by the filter). I like that sound, but that might be because almost every other synth I use has a filter-envelope setup, so it sounds different.

I'm curious to hear the results if you have a phase-shifting filter (e.g. allpass) inside that loop. Different frequencies would have different effective delay lengths, so it would generate inharmonicity, which might help your cymbal/bell synths sound more metallic.

(Apologies to Alkamist/Corey for hijacking your thread!)
geraintluff is offline   Reply With Quote
Old 01-23-2018, 08:56 AM   #14
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default

Thanks for the comments and info!

I'm going to work on some improvements today. I'll probably post a thread with the synth when I get it finished at some point. I have quite a few challenges ahead though.
Alkamist is offline   Reply With Quote
Old 02-28-2018, 11:30 PM   #15
ashcat_lt
Human being with feelings
 
Join Date: Dec 2012
Posts: 7,293
Default

Just coming back to say that this basic premise is fucking genius! It's something I've been looking for for decades, and posted about a few times, and the answer was just right there in front of me in ReaVerb. For my purposes, ReaSynth works fine. The niave square wave just retriggers the impulse every time it crosses zero (flips polarity), so the theoretical fundamental is an octave above what the synth is playing, but there's so much harmonic splatter that it's kind of hard to tell depending on the impulse. Messing with pulse Width gives all kinds of textures. I'm not hearing anything I'd call unwanted aliasing. The complex interactions are kind of part of the point as far as I'm concerned. It's just awesome and I thank you so much for pointing me this way.

I've always called it the "20 mike mike effect" because in the old GIJoe comics, anytime they blasted off the Tomcat's 20mm cannon it would go "Vroooooom*" and then the asterisk would explain how the thing fired so rapidly you couldn't hear the individual rounds, but just the one steady tone.
ashcat_lt is offline   Reply With Quote
Old 03-02-2018, 08:57 AM   #16
Alkamist
Human being with feelings
 
Join Date: Dec 2011
Posts: 506
Default

Quote:
Originally Posted by ashcat_lt View Post
Just coming back to say that this basic premise is fucking genius! It's something I've been looking for for decades, and posted about a few times, and the answer was just right there in front of me in ReaVerb. For my purposes, ReaSynth works fine. The niave square wave just retriggers the impulse every time it crosses zero (flips polarity), so the theoretical fundamental is an octave above what the synth is playing, but there's so much harmonic splatter that it's kind of hard to tell depending on the impulse. Messing with pulse Width gives all kinds of textures. I'm not hearing anything I'd call unwanted aliasing. The complex interactions are kind of part of the point as far as I'm concerned. It's just awesome and I thank you so much for pointing me this way.

I've always called it the "20 mike mike effect" because in the old GIJoe comics, anytime they blasted off the Tomcat's 20mm cannon it would go "Vroooooom*" and then the asterisk would explain how the thing fired so rapidly you couldn't hear the individual rounds, but just the one steady tone.
I'm glad I could help!

Just as a tip, a way that I found to emulate what I'm talking about with any synth is to use a sawtooth wave, and highpass filter or low-shelf the bass out to taste.

I found that if you filter it properly, the end result ends up being very similar to the single sample pulse I wanted.
Alkamist is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:36 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.