Kong [1.0.3]

I have ArduboyTones already on the game - I wonder if ArduboyPlayTune is bigger?

Could … but was really hoping to make a ‘classic’ game.

2 Likes

@uXe , I just did some comparisons between ArduboyPlayTune and ArduboyTones.

To write a simple program to play one note for 1/2 second in ArduboyPlayTune compiled to 8,590.
The equivalent simple program in ArduboyTones compiled to 7,604.

I simply do not have 1K to spare in my game without gutting some graphics or features. I think I will have to stick to simple sound effects.

1 Like

No worries - ArduboyPlaytune seems like it has been neglected for a long time, so with some effort there may be optimisations to be found (@Pharap)?

Also, all of these patterns are single channel, so could do them with ArduboyTones:

; Pattern $01, barrels BGM
301: 2A 80 1C 84 0E 88 8A 88 00

; Pattern $02, pie factory BGM
302: 16 84 0B 84 84 00

; Pattern $04, rivets BGM
311: 18 84 0C 80 80 00

; Pattern $05, running out of time
317: 10 B8 B4 B0 00

; Pattern $06, hammer time
31C: 12 90 09 90 90 12 90 90 94 90 94 90 94 09 94 94
32C: 12 94 94 98 94 98 94 00

; Pattern $08, scored points
335: 09 B0 B2 B4 12 BA B6 00
1 Like

Looking at an old thread of yours, it seems like ATMlib2 might be the way to go? You get multi-channel, and it can apparently be trimmed down using defines to compiling in under 1K? Which would free up several thousand K for ‘more important things’! :smile:

Sorry … those numbers are the totally compiled sizes - including the whole Arduboy2 library. J Garcia and I were never able to get ATMLib2 down to anything near the small size of ArduboyPlayTune or, better yet, ArduboyTones.

Gotcha! :confounded:

Well, using ArduboyBeep to play two tones on two pins for 1/2 second compiles to 7006 bytes… and would just need a small function to handle feeding in the next tone in the sequence (this is essentially what I did to get tone sequences working on the Arduino GBA Cartridge). I am not going to keep pushing for this if it is not what you want, but I am confident it can be achieved! :slight_smile:

Size or speed optimisations?

Bear in mind I’m still completely useless with sound programming.

Maybe a very silly remark, excuse me if this is not possible…

Size wise, could tune down the library (pun intended).
What i mean to say is remove the unused functions from the library, only leave the functions the game uses?
So a custom kong tune library.

The compiler already optimizes for unsued code so there won’t be any benefit here.

1 Like

:blush: what i thought, a silly remark.

My thought was that some libraries do a great job, but can sometimes be overly complex.
I you look at the Mario tune sketch, that’s floating around this only uses pitches.h and 2 functions (sing and buzz) and no more.
Or am i oversimplifying things? (i guess, yes)

Well the functions digitalPinToPort(pin); digitalPinToBitMask(pin); and portOutputRegister(pin_port); take a bit of space with their lookuptables.

Replacing them with Arduboy values will save a bit a space.

But you can’t use both libraries at the same time as they both use the same timer 3 interrupt vector

1 Like

Size.

There is no need to use both - Playtune can do everything Tones can do, and more. It seems like the only reason Tones is more commonly used is because the format for a Playtune score array is more convoluted than the format for a Tones sequence? (and because Playtune was written to use Timer1, so you can’t use PWM on the RGB LED (for blue and red) at the same time)

ArduboyPlaytune could be modified to use hardcoded pin numbers and direct pin manipulation. This would reduce code size. However, as it is the library is not Arduboy specific, so can easily be used with different pins on other hardware.

I wrote ArduboyTones to provide something that produced less code and possibly smaller scores, when you only want to play simple beeps and/or monotonic sequences.

Later, I added the BeepPinX classes to the Arduboy2 library for something even smaller when all you want is single tones.

I am determined to free up enough memory to use ArduboyPlaytune.

Thanks @MLXXXp … I haven’t had a chance to look at the code and I am not sure I would know what to change. If you can point me to potential change, I will give it a go!

You’ll need an understanding of how to control the pins directly by writing to the port registers. ArduboyPlaytune already directly manipulates the registers (rather than using the Arduino pin functions) but it uses variables rather than constants when doing so. This is where some code could be saved (although I can’t say how much. It may not be very much).

Also, if you’re going to hard code the pins, you can save more code by hard coding the timers as well. (Again, I can’t say how much.)

I would look at the ArduboyTones library as an example of directly controlling specific pins.

If you’re going to do this, I suggest that you copy the ArduboyPlaytune source and make a custom version as a local library that’s part of your sketch, with renamed files and classes. (Be sure to follow the MIT licence it uses.)

Thanks for the feedback, I will probably look at it tonight.

Wrote a sketch that uses ArduboyBeep to read and play the multi-channel patterns in their native format without conversion:

Compiles to the same ~8500 bytes that Playtune did - but this is doing more than just one note for 1/2 second… and storing the patterns in their native format should be a lot more efficient than the Playtune score format?

Also, I edited the pattern to have the duration before every note pair - so this should be even smaller once keeping-the-previous-duration-for-all-notes-until-a-new-duration-is-found gets written in…

2 Likes