Config gamebuino h -- By Sorunome

config-gamebuino.h

Author :  Sorunome

With a file called config-gamebuino.h you can easily configure the library dependent per sketch! To use this feature simply create a file called "config-gamebuino.h" in the root of your sketch folder. After doing so, you will have to restart the arduino IDE to register the change. You will not have to restart it when just modifying config-gamebuino.h, only when creating.

Now, in this file you can do a lot of #define's to configure how certain stuff in the library compiles. Here are the defines, all are optional:

General Settings

  • FOLDER_NAME (string) - name of the folder in which the binary files will be located on the sd card, defaults to sketch name. Must be at least 4 chars long

Save Settings

  • SAVEBLOCK_NUM (int) - number of saveblocks (for a more detailed explenation, see my gb.save explenation), defaults to 64
  • SAVEFILE_NAME (string) - name of the savefile, defaults to "save.sav"
  • SAVECONF_DEFAULT_BLOBSIZE (int) - size of a save blob, if not specified differently via saveconf  (for a more detailed explenation, see my gb.save explenation), defaults to 32

Display Settings

  • DISPLAY_MODE (DISPLAY_MODE_RGB565, DISPLAY_MODE_INDEX, DISPLAY_MODE_INDEX_HALFRES) - mode of the display, defaults to DISPLAY_MODE_RGB565
  • DISPLAY_DEFAULT_BACKGROUND_COLOR (Color) - default background color of the display, defaults to Color::black
  • DISPLAY_DEFAULT_COLOR (Color) - default foreground color of the display, defaults to Color::white
  • DISPLAY_CONSTRUCTOR - An Image constructor to use for gb.display, default depends on DISPLAY_MODE

Record Settings

  • MAX_IMAGE_RECORDING (int) - Maximum number of images that can be recorded at the same time, defaults to 2

Sound Settings

  • SOUND_CHANNELS (int) - number of sound sources that can be played at the same time, defaults to 4
  • SOUND_FREQ (int) - frequency at which the interrupt runs, default is 44100
Author :  ragnarok93

Ok, so I want to set up 160x128 16 colors high res mode, I made a config-gamebuino.h file in sketch folder, restart IDE and now what I have to write to set that mode ? I wrote something like this in config-gamebuino.h file - 

DISPLAY_MODE(DISPLAY_MODE_INDEX);

But this don't work. 

And do I have to write something in main code file ?


Thanks for response in advice :).

Author :  ragnarok93

delete this xd

Author :  Aurélien Rodot

You should share how you did instead, to help the future people having the same question. I won't delete your post ;)

Author :  ragnarok93

I mean I did double post so you could delete it :D. I still dont know how to do it tho ! :D.

Author :  ragnarok93

Okay I got it, so in file config-gamebuino.h you have to write something like this -

#define DISPLAY_MODE(DISPLAY_MODE_INDEX);

@EDIT

But it stil don't change resolution to high-res 16 color :(. At least in online gamebuino META emulator :<.

Author :  Sorunome

#define DISPLAY_MODE DISPLAY_MODE_INDEX


And, as the post states, be sure to restart the arduino IDE after creating that file

Author :  ragnarok93

I did, but still this don't make change in resolution in online gamebuino META emulator :c.

Author :  Sorunome

 If it is only the emulator it might be an emulator bug. Try on real hardware ;)

Author :  ragnarok93

Im waiting for it ;). Today it was shipped ;).

Author :  tikkel

if i change the samplefreq. SOUND_FREQ ... comes an compile error?

config-gamebuino.h: #define SOUND_FREQ 58472

In file included from /home/makko/Arduino/libraries/Gamebuino_META/src/utility/Sound/Sound.h:28:0,
                 from /home/makko/Arduino/libraries/Gamebuino_META/src/utility/Sound.h:1,
                 from /home/makko/Arduino/libraries/Gamebuino_META/src/Gamebuino-Meta.h:40,
                 from /home/makko/Digger/Digger/Digger.ino:1:
/home/makko/Arduino/libraries/Gamebuino_META/src/utility/Sound/Sound_FX.h:70:48: error: non-constant in-class initialization invalid for static member 'Gamebuino_Meta::Sound_Handler_FX::LENGTH_SCALE'
  static const int32_t LENGTH_SCALE = 441 * 2 / SR_DIVIDER;
                                                ^
/home/makko/Arduino/libraries/Gamebuino_META/src/utility/Sound/Sound_FX.h:70:48: error: (an out of class initialization is required)
/home/makko/Arduino/libraries/Gamebuino_META/src/utility/Sound/Sound_FX.h:70:48: error: 'Gamebuino_Meta::Sound_Handler_FX::LENGTH_SCALE' cannot be initialized by a non-constant expression when being declared
Author :  Steph

The documentation stipulates a maximum frequency of 22050 Hz...

This is weird... since Soru indicates at the same time that the default value of SOUND_FREQ is 44100...

I must admit that I have trouble understanding....

Author :  Sorunome

Can you try to change that line to say static const int32_t LENGTH_SCALE = SOUND_FREQ / 50; please?

Author :  Sorunome

Woops, seems the doc is wrong! fixes it

EDIT: wait, the doc is correct. a bitrate of 44100 indicates a max. frequency of 22050, due to a sine wave going up and down, thus factor two difference

Author :  tikkel

...yes, it compiles then.  But the system sounds are now broken or the holy gamebuino crashes (hard error 2).

So i switched back to the default samplerate 44100 and downscaled the waves: 44100*sample/58472

Author :  Sorunome

Hmmm, soru'll have to look into it more, thanks

Author :  tikkel

I was looking to play very short sound effects. In MP3 something like that is not because of the compression. The FX function offered me an interesting approach, but unfortunately the samples were all too long in the end. And you can only play one sound at a time. So I take an audio buffer (2D array) and special procedures to prefill the buffer with "square waves". These are then simply played. Works great and takes little CPU time. You can use it to pre-generate all sorts of "old" sounds without load and handle files and play back a little CPU-heavy and several at the same time...

for example (for beginners like me), here I fill the buffer:

int sfx_length[3];        // length of the 3 sfx
byte sfx_buffer[3][3000]; // 2d array as buffer for 3 sfx, must be big enough!

#define SWEEP 0           // sfx 0

// SWEEP
peak=0;
for (i=0,j=0x30; j>0; j--) {
  for(k=0;k<j;k++)
    sfx_buffer[SWEEP][i++] = peak;
  peak = 0 + 255 - peak;  /
/ switch between 0 and 255
}
sfx_length[SWEEP] = i;

and play like this:

gb.sound.play( sfx_buffer[SWEEP], sfx_length[SWEEP] );

 

Author :  Sorunome

If you are just using square waves you could also use pattern playback, thus greatly reducing the amount of RAM you need

Author :  tikkel

... how does it work? Maybe a small example?
// pattern
int8_t gb.sound.play ([const] uint16_t * pattern [, bool loop = false])

Author :  Sorunome

it's the same as for the gamebuino classic, only that you have square waves only (no noise waves, no pitch slide etc.). Documention for that is here.

There is also a tracker available to create patterns more easily here.


Yes, this needs to be documented better