Kong [1.0.3]

Here it is with some short rests inserted:

const byte score[] PROGMEM =
  0x90,57, 0x01,0xA4, 0x80, // Note A2,  Duration 420
  0, 50,                    // NOTE_REST, Duration 50
  0x90,61, 0x01,0x18, 0x80, // Note C#3, Duration 280
  0, 50,                    // NOTE_REST, Duration 50
  0x90,65, 0,140, 0x80,     // Note F3,  Duration 140
  0, 25,                    // NOTE_REST, Duration 25
  0x90,67, 0,140, 0x80,     // Note G3,  Duration 140
  0, 25,                    // NOTE_REST, Duration 25
  0x90,65, 0,140, 0x80,     // Note F3,  Duration 140
  0, 25,                    // NOTE_REST, Duration 25

Could use miditones as a starting point for a tool to convert these patterns automatically into Playtune format:

I have a bigger problem! I am running out of memory.

Could store all the tunes on the flash chip then? :wink:

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

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


@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


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.