Tuesday, 24 February 2015

Hardware for the Cambridge demo / presentation

Shapeways were 2 days late shipping this, which means it will be *REALLY* risky to try to turn my only 3D print into a mould for pewter casting. So I won't, it can happen some time later.

Everything is sounding amazing. Better back it all up and hope I don't break anything between now and Friday ...

More detail : 
Raspberry Pi Model B+ running a bunch of PIANAs / PIANATRONs
IQaudIO DAC thing to squirt audio
Laser-cut base
3D-printed Pi bed via Shapeways - better late than never, but still annoyed about the late bit
3D-printed PIANA logo 

and underneath 4 little feet glued on. 

Really, this sounds awesome beyond words. 

UPDATE - OH NO, WHAT HAVE I DONE?! I had just the one 'PIANA' logo from Shapeways, it was perfectly acceptable, but I kind of wanted 2 as I want to take 2 full-feature units to Cambridge ... and making a second requires making it out of metal. Which requires a mould. Like a fool I've only gone and immersed my only 3D-printed 'PIANA' in icky goopy toxic silicone rubber to turn it into a mould for pewter casting. This had better work out ... the poor thing is drowning in there, covered in horrible rubber that is curing far too slowly for my liking. And once it's cured I need to turn it over and do it again for the other half of the mould. Then I need to get melting and hope the mould is good. 

Really, this may well be a triumph of optimism over realism A.K.A one dumbass move too far. 

Sunday, 22 February 2015

PIANATRON performance update

The old 'Half PIANA / half Tron' has been under active tweaking recently, but only on the Mac, and with less than a week to go to Cambridge I decided I had to get it built on the Pi and running.

So after some makefile wrangling and head scratching (WHY TABS?! WHY AREN'T SPACES OK?!?!?) I fired up 8 sample replay instruments on a Pi Model A (plus powered hub, but Model A for the hell of it), with 2 of the instruments active. All were 12 note polyphonic, each had 2 layers blendable via the mod wheel. So effectively, on your common or garden £25 computer - in fact Model A is only £20, isn't it? - this is a pair of entire, full-feature mellotrons. Plus 6 more eating up memory and lurking in the background. Two MIDI keys plugged in, independently playable.

And the CPU burden -  a whopping 12% of a 950MHz Model A. I should be able to run 5 or 6 Trons on here without a problem.

On a Pi 2 I should be able to run about 64 Trons. That's INSANE. It's insane for all sorts of reasons, but a Raspberry Pi costs £25. A Mellotron M4000D costs $1,999. That is a pretty disruptive hardware price point.

Saturday, 14 February 2015

The return of Teeny Tiny TV

For my presentation in Cambridge in 2 weeks I'm aiming to use a Pi Model B+ with the terrific IQaudIO DAC stuck on top. But I also have a 'show and tell' table, and I want to have a self-contained synth cluster, maybe 2, so folks can just bash along and make noises.

The easiest way to that is - minimizing cables, minimizing the number of HDMI TVs I need to drag with me - to bolt a Teeny Tiny TV onto a Pi. And the easiest way to do *THAT* is to take one of my numerous and now redundant 'Conductor' PCBs, use 'green stuff' to bond it to the base of the TV, solder the power wires from the TV to the jumper slot that I handily designed into the Conductor PCB, and then just plug it into the GPIO connector.

Works great. I can just leave this unaccompanied on a show and tell table in Cambridge, Kano wireless keyboard connected, CME XKey connected - because no matter how I try, I cannot convince Behringer to even respond to my emails, never mind loan me a nice UMA25S for the event - and let people just mess with it play tunes on it.

Here it is, more pictures to follow when I have some daylight.

Tuesday, 10 February 2015

Guitar, fat E string as a wavetable

Top, FFT => phase-align => deFFT. Bottom, incoming wavetable. 

You can see that they are related, but you'd never guess that they are the same thing. You can also see that the time-domain version is far from ideal. I try to find the strongest positive-going transition and align that at 0. But in this case I would be better off inverting the wave and using that giant negative transition about 3/4 of the way through. And the time-domain loop is clearly asymmetrical, spending much more of its time positive than negative. The FFT eliminates all those problems, and guarantees giving me the strongest transition at the beginning of the table, because all the sin waves line up on their first cycle. 

Good stuff, isn't it?

p.s. take a look at the top one, and squint - it's kind of a sawtooth with overlaid wiggles, which is what I'd expect from a guitar.

p.p.s there is no reason why this should not support live wavetable creation on the Pi ... inject audio, let it determine the fundamental(via a longish FFT), extract the right-sized slice of waveform, FFT it, phase-align it, iFFT it, then use it as a synth. Wouldn't THAT be cool?

UPDATE : the wavetable looperizer - the thing that FFTs a fragment of audio, then autocorrelates to find a tight loop match - was locking onto an overtone of the guitar, so I have now given it an option to drop an octave after the FFT, before the autocorrelate pass. It now captures a cycle of the wave that I recognise as the repeat, having stared at the waveform for a while in Logic.

And here it is, presented as above, post-FFT magic above, time-domain filtered below -

Monday, 9 February 2015

PICYCLE gets FFT filtering

There was an unpleasant but VERY infrequent glitch in PICYCLE, and it was related to rapid shifting between MIP maps, and it just got fixed.

The wavetable filtering had previously been done in the time domain, by progressively filtering the signal at each octave to kill high frequency energy. This was all well and good, but my implementation requires that to avoid glitching, I need to ensure that there is a positive-moving zero transition at location zero in the wavetable, at all octaves. And with arbitrary signals that condition couldn't be guaranteed, hence the occasional glitch.

BUT - if I assume that all the psychoacoustic stuff I have ever read is right, and that human hearing is phase-insensitive (and please, feel free to all shoot me down at once) then an FFT-based fix can be used.

a) Take the source wave.
b) FFT it.
c) For each frequency bin
  d) take the magnitude of the real and imaginary frequency components and stick it in the real part
  e) Zero out the imaginary part.
f) Inverse FFT it to get the waveform back

So in effect I have just phase-aligned all the frequency components of the wave by killing the cos component.

Then I get three effects at once.

Firstly, I get easy MIPping - by progressively zeroing out bins then performing the inverse FFT, I get a bandlimited wave at each octave.

Secondly, since everything is a sin I will have a positive zero transition at phase=0.0.

Thirdly, via some deep FFT magic that I can't explain in maths but that I intuitively get, as it is associated with the behaviour of phase-aligned sine waves, suddenly some kind of 'complex conjugate' effect appears in the time domain, and I get an outgoing waveform that is symmetrical but inverted around the phase=0.5 point.

So after FFT then inverse FFT the outgoing wave is visibly different to the incoming, but only in phase, there is no DC bias because I punch that out to zero, and as if by magic the wave immediately before the phase=0 transition is symmetrical with the wave after the phase=0.0 transition, at all octaves, so the zero transition is well-behaved and is always located exactly at phase=0.0.


My synthetic waves - square and saw and triangle, and the 'formant' things with buckets of harmonics - all come through unmodified but bandlimited, which is in fact not surprising as they are already of that 'complex conjugate' mirrored / symmetrical shape. Interestingly, having checked the veracity of that previous statement, I now discover that the 'formant' shapes do get slightly mangled / translated - they were like this -

and are now like this -

Same same but different. Fascinating, Jim. And the amplitude difference between these is something that I have now fixed.

$64,000 question - does it sound the same? I don't actually have an A/B test that will let me determine that yet, but it really, really sounds similar. And frankly my dear, I don't give a damn, as the FFT method is the only one that will let me fix the problem. Hence it has to stay.

The key thing is that the desired effect happens - no more clicks. In fact, it sounds ACE.

For your visual pleasure here's Caitlin going 'Aah', top version with FFT processing, bottom version with time-domain filtering. Comparing the differences is interesting. The downward-moving zero transition is not at phase = 0.5 in the time-domain filtered version, due to the asymmetry in the first and second halves of the wave. In fact in the original there is a whole zero-crossing pair in the first half of the waveform that doesn't appear in the second - the first half has less area below the curve than the second has area above the curve, so there is a DC bias, and under progressive filtering in the time domain the zero transition I need to make it click-free will move away from 0.0, and this one will click.

They really don't look the same, but they have all the same frequency compenents, albeit phase-shifted relative to each other.

I repeat - fascinating, eh?

Sunday, 8 February 2015

Raspberry Pi 2

So, off I go to the Costa Rican rainforest for less than 2 weeks, dodging deadly spiders and giant toads, I come back home and the Raspberry Pi just got 6x faster. Quite the surprise.

And to be honest, it is mixed news. On the plus side, PIANA is already multi-thread capable - multiple notes of polyphony can be synthesized on multiple cores, this is how the Mac and iPad versions work, with separate single- and multicore builds to ensure that slow single core systems (like the Pi) are not burdened by pointless batching, distributing and merging of audio render work packets. So once PICYCLE gets the same treatment, everything I have that needs multicore acceleration will be capable of extracting maximum performance out of a multicore Pi 2. I say 'that needs multicore acceleration' because the sample player is so stupidly fast a multicore optimization can wait until later in the year. Plus, suddenly a GUI can afford to be way richer and sexier (or, if you like, more badly-written and more flabby!) as you can throw a whole 900MHz Cortex A7 at that part of the problem, and still have 3 more free for synthesis. All of which is insanely great.

But ... there remain 3+ million single-core A, B, A+ and B+ units out there, all capable of being exceptional synthesizers / synthpop bands. They deserve some TLC, and deserve to be allowed to be as great as they can be. So single-core 950MHz ARM11 will continue to be what I benchmark against, and I will ensure that the single-core units remain first-class citizens. And I will only demonstrate Pi 1 units at the Raspberry Pi birthday party. Partly just for the heck of it - 'Blimey, look and listen to what an original Raspberry Pi can do when you tune the code hard enough!' - and partly because I'm frankly very annoyed. I spent £25 only 2 weeks ago on a Model B+ purely for this event, and now it's obsolete. Rats - I could have bought a LOT of ice cream and Nutella and bananas with that!! Really, a lot of bananas. So dammit, the good old Pi version 1 will be the showcase unit for the event, obsolete or not, and it will be no less awesome, despite suddenly being yesterday's hero.

Hope to see lots of you in Cambridge in about 3 weeks when I will make a right old racket with £25 worth of computer.

p.s. I wasn't kidding at the start of this, here is the deadly spider I dodged - descending from a tree on a thread, RIGHT IN FRONT OF MY FACE, at night, literally 6 inches from my nose. Had I been one second further along the path, I would have found myself with a Brazilian Wandering Spider a.k.a Banana Spider in my hair. Narrow escape, but a truly gorgeous little thing. OK - big thing.

Saturday, 24 January 2015

PICYCLE update

There was an irritating zippering noise in PICYCLE* that only appeared in the presence of rapid sweeps in parametric space, and that under typical mod wheel levels of rapidity - 10 or 20Hz modulation - was dominating the sound, a really horrible noise breakthrough. I eventually - last night in the shower, as always - worked out that it was exactly the same noise that had plagued PIANA for several weeks about a year ago, and that I could do something about it. I realized that it was a set of discontinuities caused by a few 'constant during the inner loop' assumptions, which then stopped being constant and jumped, in a highly discontinuous way, to different values at the next iteration of the inner loop. So, once it was root caused I knew how to fix it.

Except it turned out to be surprisingly complicated to fix. Not algorithmically, the algorithm is exactly the same secret sauce that de-nangered the PIANA oscillators - basically, discontinuities need careful management. But despite the 'simple fix', a surprisingly large amount of state needed to be managed, and switched inside the inner loop. But it is now fixed, and here's before and after audio for comparison. I don't have a recording of this as an example, but under slower parametric sweeps there's something you can hear, like a just-over-the-horizon thing, a sort-of-audible graunchy / 'buckling metal at the edge of perception' thing, but under these fast sweeps that you can listen to below, it's wretched. An ugly noise, like digital interference, and it gets louder and louder as the sweep frequency goes up.

This is just one oscillator running here so that you can hear what's happening, and it has an 8-wavetable 'twin trajectory' (or specifically, trajectory plus perpendicular) mode, with a 4-table X size and a 2-table Y-size. There is a very rapid sweep in Y (the short dimension, basically bouncing between the end points of a pair of tables), coupled with a not-quite-as-fast sweep in X, and the frequency sweeping up and down as well. All of which gives 3 potential discontinuity sources - X table shift, Y table shift and MIP level shift as the frequency of playback changes. Yes, there be MIP-mapping in here.

Here we are, with zippering noises (i.e. wretched - gritty, nasty Cadbury's Dairy Milk) :

And without (i.e. smooth as silk - luscious Swiss Truffles) :

And now I need to check performance on the Pi to see how much this has hurt me - I fear there may suddenly be a 40% performance droop ... but the quality is pretty great now, I have no fear of modulating these oscillators into the ground. No matter how hard I push them (within reasonable limts) they will be pretty much clear of artifacts, for sure clear of these discontinuity-based artifacts. And once again, for fear of repeating myself, I have to say - doesn't this sound like a resonant filter being opened and closed - like Eno and his solo during 'Blow Torch', that hilarious wiggle squee squaa beep beep squelch squoo - yet there isn't a filter anywhere near this, it's all about the spectral content inherent in the wavetables themselves. Smoothly gliding between wavetables results in the output spectrum tearing around as the parameter sweeps happen. Totally, totally brilliant. I think I shall very much love this little synthesizer when it gets a keyboard and some twiddleable knobs.

UPDATE : in a quite remarkable turn-up for the books, there appears to be no measurable performance droop associated with this additional state management and work. Maybe 1% more CPU is being burned, which is an additional 1 part in 12. Definitely worth it for this improvement. Excellent!!

UPDATE UPDATE : Phew. It gets better. Remarkably, in 'trajectory' mode - with a 1-D path for the wavetables, so there is a lerp rather than a bilerp - 4 note polyphony consumes only 7% of the Pi. That is amazing. Amazing. Basically, for 14% of a Pi I can run 2 copies, different tables, one detuned, one octave shifted, whatever - and generate VAST, moving, swirling sounds. Seriously, that is an amazing result. A couple of tiny glitches - like quiet vinyl pops on certain sweeps - in the linear version that I need to dig into, but nothing to worry about, and nothing that will affect performance to fix.

*pay attention at the back - PICYCLE is the new, jolly witty codename for the wavetable synth. Got that? Good.

Friday, 23 January 2015

Say hello to PICYCLE!

The wavetable synth just got a name. In fact 3 names in rapid succession, but she now has a permanent name. Permanent ish. A permanent codename anyway.

So - those with memories that stretch as far back as last week will remember that she was referred to in a Matt Smith / David Tennant kind of way as PIMEYWIMEY. Which was horrible, it hurt her feelings*, but I couldn't come up with anything better at the time. Then it struck me. UNICYCLE!! Because all her sounds will be generated from a single cycle of a complex waveform. See where I'm going there - UNI and CYCLE? Jolly neat if you ask me.

But even better - by running the 'twin trajectory' (ooh err missus) version of the wavetable oscillator - N waves in the X dimension, 2 in the Y dimension, she's got two whole parametric dimensions - she becomes BICYCLE. Yay!

And, she's a Pi, generating waveforms based on single cycles of samples. A Pi. Generating cycles. Hmm.

So she's officially PICYCLE.

Totally brilliant.

Now sadly there is an existing electric bike called PiCycle. But I think there is no danger of anyone realistically mistaking an electric transportation vehicle that retails at $6,000 with a £20 synthesizer. But even if there is - CALM DOWN, IT'S a CODENAME! OK?

So - officially, the wavetable synthesizer of the extended PIANA family is now "Codename PICYCLE"

*Yes, you CAN hurt a synthesizer's feelings.

Thursday, 22 January 2015

Wiggle - first sighting of wavetable synth

Wavetables wiggling ... very stupid test, 4 oscillators, each in 'bilinear' wavetable mode, each with a set of 4 different wavetables at each corner of a 2D parametric space, a slow sin wave moving in one dimension of the space, a rapid triangle moving in the other, a sin wave or 2 sweeping up and down through frequency space, all moving at different speeds. Yes, it still sounds like an alien with indigestion eating a synth sandwich, but considering there aren't any filters in here, it doesn't half sound like filters opening and closing. This could be a really nice synth once I have a keyboard hooked up to it and a mod matrix wired in. Very fast - OK, pretty fast - this test consumes about 10% of a 950MHz Raspberry Pi, implying a realistic 32 notes of wavetable polyphony with mod matrix / key response / other stuff overhead.

Correction : there is only around 54% of the Pi free due to other threads and other workloads, so don't expect more than 24 notes of polyphony from this particular configuration. Much more polyphony than the Virtual Analog synthesizer, and a good order of magnitude lower than the various sample replay options.

Wednesday, 21 January 2015

Quick remake / remodel of Pi base

The Model B+ demanded a slight tweak to the model I print off at Shapeways for my Pi bases. In fact this is nicer, as I can now integrate a micro-SD theft protection slot at the end, leaving the SD card encased. Not that anything would stop a thief determined to get their hands on a cluster of synths, but you have to try.