config-gamebuino.h

Creations

tikkel

NEW 7 months ago

Sorunome Sorunome

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] );

 

Sorunome

7 months ago

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

Sorunome

NEW 7 months ago

tikkel tikkel

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

tikkel

7 months ago

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

tikkel

NEW 7 months ago

Sorunome Sorunome

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

Sorunome

7 months ago

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

Sorunome

NEW 7 months ago

tikkel tikkel

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

tikkel

7 months ago

Ok, I understand the patterns now, but unfortunately I can not use it. It's like the gb.sound.fx(). The shortest sound can only last 20ms.
My sound effects have lengths between 8 and 20ms.
The method with the prefilled buffers (only 2kB each) seems to be most effective for me.
Why is it only at 20ms in the gb.sound-functions going on?

tikkel

NEW 7 months ago

Sorunome Sorunome

Ok, I understand the patterns now, but unfortunately I can not use it. It's like the gb.sound.fx(). The shortest sound can only last 20ms.
My sound effects have lengths between 8 and 20ms.
The method with the prefilled buffers (only 2kB each) seems to be most effective for me.
Why is it only at 20ms in the gb.sound-functions going on?

Sorunome

7 months ago

The idea was to play real-life notes instead of manually specifying frequencies. That being said, the patterns to use the extended periods, so you can go way higher, see the source: https://github.com/Gamebuino/Gamebuino-META/blob/master/src/utility/Sound/Pattern.cpp#L28

Sorunome

NEW 7 months ago

tikkel tikkel

The idea was to play real-life notes instead of manually specifying frequencies. That being said, the patterns to use the extended periods, so you can go way higher, see the source: https://github.com/Gamebuino/Gamebuino-META/blob/master/src/utility/Sound/Pattern.cpp#L28

tikkel

7 months ago

I browsed something else in the forum and came across this post from you: https://gamebuino.com/community/topic/fuzzy-sound
In it you describe the sound output as an interrupt routine that sets a 10bit DAC output (pulse modulation).
The interrupt routine consumes CPU time.
Is it possible to activate a real hardware oscillator on the Gamebuino instead? Most retro sound effects are simple combinations of rectangular frequencies.
It would be super cool to have such CPU time saving sound effects!
Can I use the tone library from Arduino? Which pin would I have to switch? Or better yet, an own implementation for Gamebuino?
Greeting from me

tikkel

NEW 7 months ago

Sorunome Sorunome

I browsed something else in the forum and came across this post from you: https://gamebuino.com/community/topic/fuzzy-sound
In it you describe the sound output as an interrupt routine that sets a 10bit DAC output (pulse modulation).
The interrupt routine consumes CPU time.
Is it possible to activate a real hardware oscillator on the Gamebuino instead? Most retro sound effects are simple combinations of rectangular frequencies.
It would be super cool to have such CPU time saving sound effects!
Can I use the tone library from Arduino? Which pin would I have to switch? Or better yet, an own implementation for Gamebuino?
Greeting from me

Sorunome

7 months ago

Unfortunately the samd21 is just an MCU for itself and, as far as soru is aware, doesn't support what you are wanting. What would need to happen is like an external sound chip (like old consoles used) and then communicate with that one via SPI or something,  as far as soru is aware

Sorunome

NEW 7 months ago

tikkel tikkel

Unfortunately the samd21 is just an MCU for itself and, as far as soru is aware, doesn't support what you are wanting. What would need to happen is like an external sound chip (like old consoles used) and then communicate with that one via SPI or something,  as far as soru is aware

tikkel

7 months ago

I mean a simple programmable timer that writes values (independently) to an audiopin or DAC register.
For example, a square wave: https://forum.arduino.cc/index.php?topic=454243.0

tikkel

NEW 7 months ago

Sorunome Sorunome

I mean a simple programmable timer that writes values (independently) to an audiopin or DAC register.
For example, a square wave: https://forum.arduino.cc/index.php?topic=454243.0

Sorunome

7 months ago

Just took a look at the library mentioned in there, they also just calculate the square waves with the CPU. So no gain is here. When a timer fires the CPU halts its normal operation to calculate the timer stuffs instead, that is the basic of interrupts

Sorunome

NEW 7 months ago

tikkel tikkel

Just took a look at the library mentioned in there, they also just calculate the square waves with the CPU. So no gain is here. When a timer fires the CPU halts its normal operation to calculate the timer stuffs instead, that is the basic of interrupts

tikkel

7 months ago

What a pity!

tikkel

NEW 7 months ago

Sorunome Sorunome

What a pity!