Simple A/D model…
I’d like to make a simple example, having Max ‘sample’ its own sine wave (complete with aliasing). Seems like it would be as simple as:
[cycle~] > [snapshot~] > [~number] > [dac~]
But I’m getting all kinds of odd results. One issue is that [snapshot] won’t take float for an interval, so I’m limited to 1 ms for a ‘sampling rate’ (I did try fooling with an interval of samples, as well). Basically, just wanted to be pointed in the right direction in Max, if this isn’t it, or be alerted to other things that might keep things from working as-expected. I’ve got a vector size of 64, and overdrive + in audio interrupt are on.
I don’t think you can use snapshot for this as its output is relegated to the timing constriants of the Max scheduler, rather than the dsp scheduler. Even if you convert snapshot’s output back into a signal, the result is dependent on Max scheduler settings.
Maybe use sah~ and a control signal like train~ to get your sampling interval– the example below aliases very well indeed…
----------begin_max5_patcher---------- 564.3ocyV1siiBBEG+Z8ofvkabIhef5d29brYxFDosrwhMJlsyLY5y9BnV6r w5Xa5XFuvfG.4+424b.d00AlWcj2.A+.7KfiyqtNNVSFCN8e6.2SOxJoM1gA ks6y40Putt1TIUMhW3ltvXjeuY8fDxRtxNE7nwpV0f0fdqGnJ1Ngb6uq4LUm PvIwnL8SZrGHffBss8.w95+O.mg7AO0OYQgUSU4+463jAM0sHpmOv69cPgTA 8.vbpbK77TMJWR2aGC7m0BZIzzwattlWdKkF7+pW7gUVwOZcAnplJjmtEHEd qPJHxGkZHSjlLXDwzLzCDQlERjqBoFwVolAqKmZn6tIJELIkvykJkfv95GhG HCiBMM0TJLdVJE+QT5ASmFV0A9YPj2tYfCjn4n.iVxXUsRquFNMa7mICJzGk n4QPhFE3PjeecFNMAEnsiC7.jTTjgYASwor6wW4uTPYm80EDcmwCxv1vnMaA DEO7dJsl9.yZ+1IfOB+Im2R5JoMwlvwJ8nY2CLYkyauBetL.e+zweN5fGoS5 Hclurl.enN+lxJsf+TOHLPmMGapD0GDhSPDSk3GdPXzUSBzJlt1mDxdlUxOA z6AuZ6yqwyPSR3r6y+fJWrCCVJj++MorB0X+8bqopslMrTC2cALJwBdiRHoJ Qk7xA8twrSTTvkWVmrWTbnReUmdM.dZxf3hkT7BjT1WOIkrpRJZIwMx5RokH o30URjkpI7pookTwQ9Rpn6Mto+3M2+grs7h0 -----------end_max5_patcher-----------
Wow, you’re right-on Terry, thanks! I read a little more, so I now I think I see that snapshot~ is really useful to get out of the signal-rate domain, but that’s not quite what I want to do here. I didn’t know about sah~, which is much more on-target. I am finding that- particularly as the input freq gets beyond the midrange- I’m hearing aliasing (or at least artifacting) well below where I would expect to (Nyquist). For example, even a freq as low as 90 hz will sound much different at 44.1 kHz vs. 1000 hz sample rates. Am I missing some particular theory here (I’m sure I am, which is part of the point), or is this more about massaging Max?
If you want to emulate a digital to analogue converter using his approach in Max you’ll also need a low pass filter (after the sah~ output) that has a cutoff frequency a little below half the sampling rate (the sah~ rate) with a steep rolloff– then you’ll get the ‘correct" kind of aliasing. maybe cascade a whole bunch of low pass filters. This will smooth the waveform from its stepped appearance.
Hmm…would this be anti-aliasing filter(s) stage of an A/D you’re referring to? Or is it a different one I can look into? I haven’t put the anti-aliasing filter in, because AFAIK there should be no aliasing below 1/2 the sample rate with a sine wave. And that filter would need to be *before* sah~, correct? I’m actually aiming for a model A/D (as opposed to D/A), generating a tone at whatever the system sample rate it (44.1) and getting Max to re-samples it at 8 kHz or 1 kHz or whatever. Just want to be sure I’m understanding you correctly, thanks again!
in audio sampling, you have two LP filters– the antialiasing filter for signals coming in (a to d) and the smoothing filter for signals going out (d to a)– you will need an emulated smoothing filter because your actual sampling rate is much higher than your emulated rate, and you need to smooth out the discontinuities in your waveform.
I thought the point of your patch was to actually create aliasing, but if you don’t want that then put a filter in before the sah~ , with a cutoff freq at half the sample-hold rate.
Actually coming back to play with this again. So, is this in the right direction? It’s surprising to me that the smoothing filter would need to be this steep. Even with this, there is clear aliasing within about 1/2 an octave of the Nyquist freq. But maybe that’s the deal…?
----------begin_max5_patcher---------- 1217.3oc4YlzjaZDE.9rzuBBGcISnWAxs7GHGRNlJkKDpkFbwlAzDM1kme6o W.DyTZoGV5gXeQ.8zCu26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 2dHwj1em8Cp3COySqClce1we98HZPWZQr6z6xdE9zeAVK5bg0c5nKIfUt3yQ n5M55DL8cchGcl8dMKrPpNJax5Ywl3l+T+iOyO77Gdihz2cRNC6j3rW+crkx SL9KAWU9wxnVKp8aiZcVP6XU0wYxyHo+jBdwjdHd2NVV+npcwUhUvcWeIbR0 GOyoNd5fGeioOn.czGywGj17ArfzGOioOZ4NavnKjN3w0b5iFpC5dpSZ7thb 9F.ax.B40eZ6HA.Hckkf7xzADUinWabU8bw2cj7pc6Ngtnt5XzPisFH1V2Rx mPqPXYdvETJEjASw4qKeLz5EVW9XF8Ap05k4JQJNgx6pOPCVxFpi9PVXw6Xi EeAH5pOlgO5fG5hSa.KmZWxETCoO5pNKm1q.ly2AniyCXfpiZmvgEEOxJqZd kRMwNM7y4kxCSbi7w3L0ixc5aWxdLtc9H4Hgk7cpWy2l9wR0F4O4SsWKjy2W +eH7MR5M -----------end_max5_patcher-----------
This isn’t really aliasing – this is more like heterodyning or creating sidebands.
You’ll see this in analog synths and especially in radios too, so it’s not caused by "nyquist-bumping", from what I can tell.
I was amused by how *well* this patch does sidebands, actually.
----------begin_max5_patcher---------- 540.3ocyV9sjaBBEF+Z8ofgKasT.+euqOGc5zgnzD1wfYPx1r6NqO6EPMa1V yTiI0IdgCb.47wON9ou36AWUef2.AeA7Mfm2K9ddtP1.d888faYGJpXMtoAk 7eUu5AXP2PZ9AsK7maATzPT49sBYEW6dBZevcLcwFgb8OT7BcWFooXTVt4JJ .DhiPgCsiP3..Eivfu+1RVuWOrlj9nhRWxMB5Sjvgr+yZoVx1xcC8UkfUMLR 2JneZGuK+vFwZoY3iYw9nMhmcCSnHrM5q991aAWGe9XKffHWCfnooGATT7L. D8tFPJlrrEfQQixHxDYTTNx1LKN.jPmAiv20LRqXBY6n.JbhukQyQoXLlPME QIV.QxOKfni.nj4Cn..bESt9LfhbKAUCaS6E+tVHEQLnAmXvjAYTacTloc7+ .SiUGEeqqilGd3OWxJtJRDQcdwcFN16mAB3+FBYva2A5GrVCjq5HM+D6S7ke jldebhdF9T7TQEu0rwv3KERDCXNBoSrGRmAjH+egjaNvJg7O+kE21xF+8jqo dupXHO85C711oj2nERlVTKOcNwuaRaDkkb4ok3khF1pJtaWO9Q3jkCdJ5gtb 5gNE8Dtb5IbJ5IY4zS7DzS5xImjoVNSVD8jNA4jsXzYppYNroyHhsa2ibUS+ R5Dhwr9gZksaRfqqP100YVBU7GECyOxEgoL9wZiY7dUmY4grDy2MM44U+ey9 9wgq -----------end_max5_patcher-----------
Well, that’s certainly irritating to know. :/
I don’t get it, I thought this would be a (relatively) simple & straightforward undertaking in Max, and it’s been the complete opposite. I’m no DSP engineer, but I do feel like I get the most basic guts of an ADC, and that’s all I’m looking to accomplish. Can anyone fill-in a blind spot?
the blind spot may be that D/A and A/D conversion is done on dedicated chips, and it’s because of this that it works.
So I don’t think you can ever get that sound without actually going out of the d/a and then back into the computer – that’s simple enough.
Now, from a pedagogical standpoint snapshot might actually work fine, just run the cycle~ at a much slower rate (like, 0.1 hertz, for instance), and then run it into a scope~ or something, so you can see the steps. *see*, mind you.
Then you can use the original cycle~ and the resulting resampling to *modulate* a second cycle~, letting you hear what’s going on inside the waveform, even though it’s below audiorate.
I see your point, but I’m a little fuzzy on the concrete problem. Are you saying it’s a pure speed problem? I got the idea that might the case with the Max scheduler (1 ms), so I moved it all to signal-rate (which is probably should have been in the first place). I have tried much lower freq (not 0.01 hz) and it sort of works, just not anywhere near what I’m expecting. Even at 1/2 of the Max scheduler rate, surely it’s accurate enough to re-sample well-below the (re-sampled) Nyquist freq? I’ve certainly pushed MSP much harder before…
Forums > MaxMSP