So I've been on a bit of a journey.
What's all the fuss about with AI and coding?
Can I use it with Free Pascal to create audio units for use in a synthesizer?
The answer turns out to be yes, but with some gotchas.
I used Claude and Cursor with their free version.
The very first unit I asked for was to read a wave file. It generated one that worked and could read wave files, cool!
However:
- It used magic numbers
- It generated classes that were probably in a library unit somewhere
I got it to extend the unit to create wave files and allow for WAVEFORMATEXTENSIBLE, which supports more than two channels. I've tested it with mono and stereo but not anything multi channel.
I then got it to generate oscillators - sine, square, sawtooth, triangle. That worked well, though I noticed the code was pretty simple, I could do it myself.
I then asked Claude to create a resampler, to convert between sample rates. Oh dear... it had lots of syntax errors that needed fixing, then once I got it to build, the output was noisy. I looked at the waveform it created and noticed lots of zero crossing glitches. Three times Claude tried to fix the bug, three times it failed. I gave up and tried Cursor.
Cursor generated code with syntax errors but once fixed it could resample quite nicely. The code was muchg simpler and I adapted it to handle more general cases.
I went further and created filters, freeverb and so on, and noticed a pattern. It could generate Free Pascal just fine but sooo many syntax errors!
I did learn one or two things - you can put const in class definition making class constants. The AI just missed the 'var' declaration afterwards.
My conclusion from all this?
AI can generate code and is a useful tool for that. However... it often generates code full of silly mistakes, and sometimes outright doesn't work!
I did wonder how good it was at spotting mistakes so I asked it:
What's wrong with this C++ statement?
It did spot what the problem was... but how come it couldn't fix the glitch error in resampling?
I keep reading about how AI is replacing coding teams and generating code at high speed - yet my own simple research seems to indicate that it's not at that level yet. I'm not spending money on a tool that isn't 100% reliable, and generates code that won't compile, and in one case, doesn't work properly!