[sdiy] Oscillator sampler with sorting capabilities concept
Jim Credland
jim at cernproductions.com
Sun May 19 20:19:24 CEST 2013
Well, here it is in bubble sort, python3. I've been stuck on a long train journey all afternoon with nothing better to do. It will generate output.wav in your current directory. It takes a random list of numbers and then progressively sorts until you get a sawtooth.
import random, wave, array
# Jim Credland, 2013
# generate a list of random numbers and sort them, playing back as we sort
class WaveFile():
def __init__(self, name):
self.wav = wave.open(name, "wb")
self.wav.setnchannels(1)
self.wav.setsampwidth(2)
self.wav.setframerate(44100)
def writeFloatBuffer(self,buffer):
# output one instance of the wave
a = array.array("h")
for i in buffer:
a.append(int(i * 65536 - 32767))
print(a)
self.wav.writeframes(a)
self.wav.writeframes(a) # I don't know why I have to call this twice - mystery bug fix
class WaveTable():
def __init__(self):
self.buffer = []
self.lastPosition = 0
self.completeFlag = 0 # set after bubbleSort goes through a whole
self.adjusted = 0 # used for checking whether array modified during bubblesort
def bubblesort(self):
p = self.lastPosition
array = self.buffer
if array[p] > array[p+1]:
array[p+1], array[p] = array[p], array[p+1]
self.adjusted = 1
p += 1
if p+2>array.__len__():
p = 0
if self.adjusted == 0:
self.completeFlag = 1
self.adjusted = 0
self.lastPosition = p
def fillWithNoise(self):
self.buffer = []
for i in range(400):
self.buffer.append(random.random())
##########
## BEGIN MAIN
waveTable = WaveTable()
waveTable.fillWithNoise()
wavFile = WaveFile("output.wav")
stepCount = 0
while waveTable.completeFlag == 0:
waveTable.bubblesort()
stepCount += 1
if stepCount % 256 == 0:
wavFile.writeFloatBuffer(waveTable.buffer)
print("Sorted in ", stepCount)
On 19 May 2013, at 16:30, cheater00 . <cheater00 at gmail.com> wrote:
> Jim,
> it's been quite some time since I've touched pd at all. I don't
> exactly remember what things sounded like back then.
>
> Paul,
> On Sun, May 19, 2013 at 2:45 PM, Paul Anderson <wackyvorlon at me.com> wrote:
>> I think it would probably sound like increasing amounts of static, until you get to the point of a saw. You'd be creating discontinuities in the wave, and those tend to sound like clicks.
>
> I guess it depends which sorting algorithm we're looking at. For
> bubble sort, once you've sorted a sample, it's going to be part of a
> sawtooth, which ramps down to finally culminate in the rest of the
> wave. The rest of the wave will have less voltage than the final point
> of this sawtooth. The rest of the wave is most likely going to stay
> continuous.
>
> I wonder what other sorting algorithms could sound like. Or other
> operations (most likely bijections) that happen on lists..
>
> Idea: convolve slave wave by master wave..
>
>>
>> A counter-proposal: Take the derivative of the wave, and use that derivative to control the slope(and hence frequency) of a sawtooth.
>
>
> Aka VCO->HPF->VCO? :)
>
> Cheers,
> D.
>
>
>
>>>
>>> I don't know if it would sound good, but I'm very interested. I'm also wondering what happens if you do one iteration of a sort between each cycle of a waveform. You could start with just noise … it might sound like a boring waveform cross-fade, but it might not :)
>>>
>>> How far did you get with the pure data implementation?
>>>
>>> cheers! J.
>>>
>>>
>>>
>>> On 18 May 2013, at 09:30, "cheater00 ." <cheater00 at gmail.com> wrote:
>>>
>>>> Hi guys,
>>>> I was wondering what you guys thought of this synthesis technique. Has
>>>> anyone tried this? Could it sound good?
>>>>
>>>> Here's a chat log between me and a fellow synthesis fan.
>>>>
>>>> have you ever tried running a waveform through a sorting algorithm?
>>>> That is, take each cycle and sort that. If you sort the waveform fully
>>>> you should get something like a saw. But you could limit the amount of
>>>> work the sorting algo can perform before the waveform cycle is
>>>> released. If you put this parameter on a knob then you could perhaps
>>>> have a somewhat-smooth transition from your current waveform to a saw
>>>> waveform.
>>>>
>>>> I think it could even work for analogue synths, you'd just need
>>>> somewhat of a buffer
>>>>
>>>>
>>>> you could have a sampler which works like this: it has a sync input
>>>> and a wave input from a VCO. when the vco outputs sync, it starts
>>>> sampling the waveform until the next sync. Once that's done, this is
>>>> called "a wave". Now for the output. Every time a wave is sampled, it
>>>> is placed on a queue (fifo). When a vco sync happens, the output
>>>> module takes the next wave from the fifo and starts outputting it. As
>>>> long as the wave is being output, syncs can be ignored (or instead, it
>>>> could jump to the next waveform at index 0, or to the next waveform at
>>>> the same index as it currently is). If there is only one wave left in
>>>> the queue, and the device is getting sync pulses over and over, then
>>>> it could either start outputting silence, or start outputting the last
>>>> wave it had in the queue.
>>>>
>>>>
>>>> this way it could work even delay-less (but would mangle the output in
>>>> a fun way)
>>>>
>>>>
>>>> Snd of course, while this happens the currently output waveform could
>>>> be mangled by: sorting, randomizing, sorting or shaping according to
>>>> the current waveform shape in a second sampler, etc.
>>>>
>>>>
>>>> could be fun when run on FM oscillators which change pitch.
>>>>
>>>>
>>>> So what "slaving to another sampler" would mean is that, in the master
>>>> sampler you have the sorting algorithm, and it moves sample 4 to
>>>> position 1. Then the slave sampler doesn't sort its own samples,
>>>> instead it just moves sample 4 to position 1, just like the master
>>>> sampler. I think this might only work if the wave are "normalized" to
>>>> some length, or alternatively if the waves in the slave get resampled
>>>> to the length of the master, or alternatively if the waves in the
>>>> master get resampled to the length of the slave. Resampling slave to
>>>> length of master would mean we either get a nice low-pass effect (if
>>>> the resampling is band-limited) or we get frequency-dependent aliasing
>>>> (if the resampling is not band-limited). The aliasing would not change
>>>> position in an inharmonic way like it usually happens when you alias
>>>> against a static sample rate (like when recording to a low sample rate
>>>> interface); instead aliasing would add a timbral quality which would
>>>> be constant across the keyboard, and work in a musical fashion.
>>>> Because both the master and slave waveforms are sampled at the same
>>>> clock rate, this aliasing process is immune to the clock rate of the
>>>> samplers.
>>>>
>>>> You could laso have the master send the current wave to the slave and
>>>> you could have the slave use it to wave-shape its wave with that. So
>>>> if the master has a rising saw, nothing happens, and if master has a
>>>> sine wave, then you get a sine shaper.
>>>>
>>>> If the master sends a wave, where the voltage level of the nth sample
>>>> is instead replaced by the index it has after being sorted, then
>>>> "slave sorting" could work simply by wave-shaping the slave wave by
>>>> that master "sorting index" wave.
>>>>
>>>>
>>>> Of course you could have the slave have its own sampling input and
>>>> sampling sync input, but then have its *output* sync to the master's
>>>> sync input or a dedicated output-module sync input. Then if the sample
>>>> memory is really long, and the sync happens every now and then, you
>>>> could have a stutter effect.
>>>>
>>>>
>>>> You could even have "markers" in the wave, which happen when a third
>>>> input is triggered. Then, once the output module get sync, rather than
>>>> jump to the beginning of the current wave it could jump back to the
>>>> latest marker or skip forward.
>>>>
>>>>
>>>> And if you have a long sample memory then you can just trigger the
>>>> input sync once and have a loop play forever.
>>>>
>>>>
>>>> I wonder what everyone thinks of this?
>>>>
>>>>
>>>> This is fairly similar to some of the stuff I did in Pure Data at some
>>>> point, but I've only now figured out how this could fit into the
>>>> context of a modular synth.
>>>>
>>>>
>>>> Cheers,
>>>> D.
>>>> _______________________________________________
>>>> Synth-diy mailing list
>>>> Synth-diy at dropmix.xs4all.nl
>>>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>>>
>>> _______________________________________________
>>> Synth-diy mailing list
>>> Synth-diy at dropmix.xs4all.nl
>>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
More information about the Synth-diy
mailing list