6 Replies Latest reply on Jan 5, 2009 6:24 PM by the chuck

# sampleNearest() reading next leftmost pixels AFTER writing

I'm trying to understand how to use SampleNearest() correctly. I have an image that is 2048px by 1px. basically a byteArray that is 2048 units. To emulate this, I created a .png that is all black of size 2048x1. Here is basically what I want to do:

b = image, our input byteArray 2048 units in width, 1 unit in height.
index = current coordinate.x, because we don't care about the y coord because it's always 1.
freq = 262hz / 44100; a constant

b[index].r = b[index-1].r + freq;
if (b[index].r > 1)
b[index].r = b[index].r - 1;

Essentially, if we're working on pixel (25,0), this reads pixel (24,0) after being computed, and adds the freq constant to the value.

I'm trying to understand how to do this with sampleNearest and outCoord(), but am missing something.

dst.g = float (0.0);
dst.b = float (0.0);
float index = outCoord.x;
float newC;
float oldC;
if (index == float(1.0)) //the first leftmost pixel. always start at 0...
{ oldC = sampleNearest(src, outCoord);
newC = oldC.r; }
else
{ //ok to read the nearest pixel to the left
oldC = sampleNearest(src, outCoord() - float2(1.0, 0.0) ); //get the next nearest left pixel
newC = oldC.r + freq;
if (newC > float(1.0))
{ newC = newC - float(1.0); }
}
}

I'm thinking that the problem is that PixelBender is not sequential in how it calculates values. as in, I need to calculate coordinate (24,0) and write it to the final image, before I can compute coordinate (25,0), which is calculated based on coordinate (24,0)'s final value.

It would be really great if this forum didn't remove indentations and spaces in text... the AttachCode button completely sucks, because you can't actually SEE where the attached code is going to show up. some BBCode tags would be way easier to work with...
• ###### 1. sampleNearest() reading next leftmost pixels AFTER writing
oooo, success:

Sawtooth as color

If you're curious what this means, It means that I basically have created the foundation for having PixelBender act as an Oscillator for a synthesizer in Flash.
• ###### 2. Re: sampleNearest() reading next leftmost pixels AFTER writing
Congrats, very cool. Glad that you got it working.

A couple things if people hit the same snags:
1) Pixel Bender pixel centers are at half pixel values. For example, the upper leftmost pixel is not at (0,0), it is at (0.5, 0.5)
2) You have to assume that every pixel runs at the same time (because they might). You can't base the value of one pixel in the output image on another value in the output image. That won't work. If you need to do something like that, you'd need to arrange your pixel bender filters as multiple passes on the same image.
• ###### 3. sampleNearest() reading next leftmost pixels AFTER writing
I'm trying to use Tinic's disassembler/assembler to make it work with AS3 per his PixelBender as SoundMixer tutorial, but it won't disassmble, and gives a rather ambiguous error message:

(itof) invalid source register type

I know that Tinic created those assembler's/disassembler's to help with debugging pixelBender kernels. Perhaps he has a say in what is causing this particular kernel to not be decompile-able? Here's the updated Kernel:

• ###### 4. Re: sampleNearest() reading next leftmost pixels AFTER writing
I figured out via the disassembler that the exporter does NOT like type conversions being inline. the line:

float freq = float (frequency) / float (44100.0);

was causing the problem, because frequency was created as type int. So, although it was compiling, it was not exporting for Flash correctly. Converting the frequency parameter to type float corrected the problem, and the pbj is now able to be disassembled.
• ###### 5. Re: sampleNearest() reading next leftmost pixels AFTER writing
FYI, you can't take Tinic's assember/disassembler as the gospel, even he says that in his blog post. That is not the code used by the player nor the Toolkit. Modifying your code to work with that code is no gaurantee.
• ###### 6. Re: sampleNearest() reading next leftmost pixels AFTER writing
Kevin, what's the ETA on single channel Pixel inputs/outputs for PixelBender within Flash?