Importing a waveform, from a graphic, into buffer~
Hi all - I'm not sure if this is possible, although from experience in Max, most things are...
I want to import a waveform, from a graphic (jpeg, tiff...), into buffer~ - so that I can use it as an oscillator in cycle~. I've attached an example graphic I would like to use. I'm guessing I'll need to remove the orange grid before I do anything, leaving the black waveform!
I'm looking at something analogous to Xenakis' UPIC system which allowed graphic waveforms to be used for any audio parameter - frequency, various envelopes, modulators etc., in a self-similar way.
Any clues with the graphic import?
Thanks all,
Rob

jit.matrix can be read out using the "getcell" command and numbers can be written to a buffer~ using peek~.
the rest is range scaling and some patience. ;)
Thanks for this Roman. I'm not getting anything meaningful out of jit.matrix, although I can display the image quite happily and unpack the data [unpack cell 0 0 val 0 0 0 0]. I just can't put that into a buffer~, or a jit.buffer~/jit.peek~. I've also had a look at table and itable but that's not happening either... I have converted the images into BW, leaving only the waveform.
The first important step is preprocessing, indeed.
When you have "around one" black cell per column, and maybe normalized values (only 0/255) in your matrix, then you can go to reading/writing.
A pseudo algorithm could be:
for each column:
- i = 0;
- while cell[i] == 255 (white) do nothing
- write i*(scaling-factor) in buffer (that's only when you get out of the while loop, i.e. when you read a "black" pixel, i.e. an "on" pixel in your scenario)
I'd try the "for each column" with [uzi], the "while loop" maybe with just and increment and a [sel] object, TBD.
not sure what was the cleanest way to program it, but in the given image i would
1. load it in a matrix and convert it to greyscale
2. read out vertical lines from that picture and bring them in the form of a list
3. check which list element is the darkest
you will not come around to get used to topics like "working with lists", "range mapping" and the sampling theorem (the forum is full of this stuff and so is the in-application search) in order to optimize it until it sounds halfway right to your ears, but it is doable.
of course you should not expect too much, because the resolution of this image will be like a 0,3 khz SR in terms of audio.
Thanks for this guys. It's looking pretty ugly for what I'm trying to achieve. I thought, years ago, there used to be a piece of software that allowed you to do this (it wasn't a Max external) but I can't for the life of me, remember what is was - or I dreamt it up! I've got it into the matrix. I need to work on the resolution. But haven't quite got it into a buffer properly yet. Getting there though.