How can I run code when using sampled audio playback in GBDK c?

I am making a game for GameBoy in GBDK and I am trying to add sounds to the game. GBDK has a function that plays sounds from an array of values, the only problem is that when playing the sound the rest of the script freezes. Is there a way to make them work at the same time?

+6
source share
1 answer

Unable to run code when using sampled audio playback . This is due to the fact that it actually uses a full processor for preview playback. If you want to use the usual sound effects, you need to either pause the game during the game, or use a different method. I will try to generalize using a different reproducing method below, but it is rather complicated, and I am not an expert.


Using "normal" sound effects

This is a kind of WIP - I'm not too good at it, but it should let you get started.

To use sound effects, you need to record in the sound registers GameBoy. This is located in GBDK hardware.h , which is automatically enabled with links to gb\gb.h But (of course) the registers do not have any documentation. This information is contained in the GB Cribsheet . There is also this documentation file for sound recordings (unfortunately, it behaves strangely in window encodings - Open with something other than a notepad), as well as other information found on the Devrs.com sound documentation .

Disabling GBSOUND.TXT:

Addresses through which sound channels can be accessed:
$ Addresses: (Description), (Case Reduction)
$ FF10 - $ FF14: Channel 1, referred to as NR10-NR14
$ FF15 not used, probably there will be a reverse mode for channel 2
initially
$ FF16 - $ FF19: Channel 2, referred to as NR21-NR24
$ FF1A - $ FF1E: Channel 3, referred to as NR30-NR34
$ FF1F not used, there will probably be a scan for channel 4
initially
$ FF20 - $ FF23: Channel 4, referred to as NR41-NR44
$ FF24 controls Vin status and volume, calls NR50
$ FF25 selects which output each channel goes to, Called as NR51
$ FF26 is a status register and also controls the power of the sound circuit.
Called NR52
$ FF27 - $ FF2F are not used.
$ FF30 - $ FF3F is the space of load registers for 4-bit samples for the channel
3

In GBDK, registers are called NR10_REG , NR11_REG , NR12_REG , ect.

Also, try looking at an example sound.c program that doesn't compile for me, unfortunately. I can edit this to include additional information.


To answer the @franklin question:

What begs the question, how does the gameplay play the game and sound at the same time?

Usually they do not do this with sample reproduction. For example, if you look at PokΓ©mon Yellow, a Pikachu scream will be made with a sample reproduction. But while this is playing, nothing else is being done. On the other hand, things like regular background music are performed using other audio equipment (sorry, not a very detailed wiki link). Similarly, while sound effects are moved using a noise channel (also used to play a sample), they are not actually sampled sound. Thus, the game can continue.

+2
source

Source: https://habr.com/ru/post/976226/


All Articles