Shop OBEX P1 Docs P2 Docs Learn Events
Spin2Cpp authorities: could this be translated easily? — Parallax Forums

Spin2Cpp authorities: could this be translated easily?

Ken GraceyKen Gracey Posts: 7,386
edited 2017-02-26 04:53 in Propeller 1
Hey guys,

I've been playing around for quite a while with Chip's original FFT frequency analyzer code as modified by Pete Hemery. I built the Propeller Demo Board microphone circuit on a breadboard with a FLiP module and I'm using PST to display the note and frequency. I made a short video https://youtube.com/watch?v=Y4sjqXE9yjA which has since been improved to also display the correct note in Bb (clarinet) transposition, but you'll see it's right on with the frequencies.

I'm thinking about adding a couple of Blockly blocks for a C library if this Spin/ASM would readily translate it to C. The top Spin file doesn't really do what I want it to do yet - it would normally display the A4 frequency and the percent sharp/flat. All the variables are present along with a lot of other stuff I'd still need to remove from the code. Transposition could be handled in Blockly.

The goal would be to have a simple tuner in Blockly, but also the ability to control things with an instrument.

Recently, you guys (Dave Hein) did an amazing job porting the S3 spin files to C - and we've just about got Blockly switched over to the new C libraries.

I'm wondering if you'd be able to tell me about the feasibility of converting the attached file to C trough Spin2Cpp. It's not the final source code I'd like to use, so I'm just looking for some "gotchas" and pitfalls before I continue. If you think it would convert, I'll get the top Spin file in order and then come back here with the official request.

What do ya think?

Thanks,

Ken Gracey


Comments

  • Ken,

    Just for fun, spin2cpp produced the C code from your Spin project and it was pulled into SimpleIDE and built as a project. Here's the .zip...

    dgately
  • Thanks Dennis - I'll give it a look today. - Ken
  • The translation could probably be improved with the --gas flag, but when I did that on Float32.spin it revealed a bug in spin2cpp. I've updated the latest spin2cpp release (3.5.1) to fix that bug and also add some additional dialog options to spincvt.

    Eric
  • The other place where the translation is weak is that it still uses the Float32 object instead of translating directly to C math operators. That's a bit tricky, so it will probably be a while (if ever) before spin2cpp does that, because it could change the semantics a bit. But editing it by hand it should be possible to improve things like:
    oct = Float32_Fadd(&self->f32, lnote, Float32_FFloat(&self->f32, 4))
    
    to
    oct = lnote + 4.0
    
    if one is careful with the types of all the variables (changing "int32_t" to "float" where appropriate).
  • Eric, interesting. This would reduce code space and cog requirements significantly, right?
  • Ken Gracey wrote: »
    Eric, interesting. This would reduce code space and cog requirements significantly, right?

    I don't know about code space (that would probably be a wash) but it would free up the cog that was being used for Float32.

    Eric
  • That makes sense - that cog would be made available. I'll get that top object tidied up more and remove some of the stuff we don't need and then get a look at the math routines.

    I'll need some help from somebody at that point. Coding isn't the best use of my time in Parallax - not because I'm expensive but because I'm pretty slow at it and it makes for very bad value engineering from the employer's perspective. All coding brains were allocated to Chip in our family. But I'll take the traits for completion :) just a little jab for fun.

    Ken Gracey
  • Cluso99Cluso99 Posts: 18,069
    Ken Gracey wrote: »
    That makes sense - that cog would be made available. I'll get that top object tidied up more and remove some of the stuff we don't need and then get a look at the math routines.

    I'll need some help from somebody at that point. Coding isn't the best use of my time in Parallax - not because I'm expensive but because I'm pretty slow at it and it makes for very bad value engineering from the employer's perspective. All coding brains were allocated to Chip in our family. But I'll take the traits for completion :) just a little jab for fun.

    Ken Gracey
    ROFL
Sign In or Register to comment.