# jamshark70

## jamshark70's code

### FFT additive oversampling (graphical demo of the sampling theorem)

I originally wrote this to demonstrate what sampled audio really represents -- that is, if a series of samples represents the one and only band-limited function that passes through the sampled values, we could obtain the band-limited function by adding up the cosines given by a Fourier transform. Further, doing it additively, we could select ranges of frequencies and see, interactively, each frequency band's influence on the final waveform. - The Gibbs effect is obviously visible for any sequences of samples that have discontinuities in the value or slope (e.g. non-bandlimited sawtooth or pulse waves). x = Env([0, 0.75, -1, 1, 0], [0.1, 0.01, 0.4, 0.2]).discretize(128); - Inter-sample distortion is clearly visible for 0 dBFS pulse waves. ( var stream = Pstutter(Pseq([24, 8], inf), Pseq([1, -1], inf)).asStream; x = Signal.fill(128, stream); x.plot; ) - If you use a rectangular window and the window can't play continuously as a cycle, there will be a discontinuity from the end of the window to the beginning. The Gibbs effect is obvious here, too. This is good to demonstrate to students why phase vocoders should pretty much always use a windowing function (e.g. Hanning). x = Signal.fill(128, { |i| sin(i / 128 * 2pi * 1.1) }); - Try lots of input signals. It's quite dramatic how the partials reinforce each other in the right places, and cancel in the right places, and always add up. BTW this example has a lot of UserView tricks. Note, for example, that to do the animation, I had to set a state variable *outside* the scope of the drawFunc, and 'refresh' the UserView to update the frame. Usage: 1. Set 'x' to a Signal containing 128 or 256 values. 2. Run the long code block. 3. The range slider chooses a band of frequencies to include -- the audio equivalent is a pair of PV_BrickWall filters. 4. The left-hand button will add partials at timed intervals. 5. The right-hand button will add one partial, and animate the way that the new partial "bends" the waveform. This is *really* instructive!

### Method help re-ordering utility

22 Jul'16 20:34

If you have a large class with a lot of methods, you probably want to sort the methods in the auto-generated SCDoc template into an order that's meaningful for the end user (related methods grouped together, more important methods toward the top). But SCDoc syntax, with method::, argument:: and returns:: tags, makes it a bit harder to see where entries begin and end, and provides no overview of the list of methods. This GUI reads the METHOD:: sections from the auto-generated template and presents a list box containing the method names. 1. Get the list of METHOD:: sections, as a string, into the variable 'm'. If the string is in a disk file, use the upper code block to read it. 2. Run the second block. 3. Initially, the methods are sorted in ASCII order. The ^/v buttons allow you to change the order, or use "a" and "z" keys while focusing on the list box. 4. Close the window or click the "P" button to reprint the full templates, in the new order. Then you can copy/paste these back into the schelp file.

30 Jan'16 06:45