Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting a song in an arbitrary position. #40

Open
RodrigoCard opened this issue Oct 5, 2023 · 4 comments
Open

Starting a song in an arbitrary position. #40

RodrigoCard opened this issue Oct 5, 2023 · 4 comments

Comments

@RodrigoCard
Copy link

RodrigoCard commented Oct 5, 2023

In my game, I have one music for the stage and one for the pause menu.
I just reload the corresponding music on (un)pause.

I want to restart the stage music where it was on pause, but the current music position is lost when loading another song. So how can I do that?

Two things:

  1. I see there is no hUGE_Get_position or something similiar, but I suppose you can calculate that, but how?

also, is it possible to implement a hUGE_get_position()?

  1. I see there is a hUGE_set_position(unsigned char pattern); in the header, but how to use that? what pattern refers to?

Thanks!

@SuperDisk
Copy link
Owner

I just made a modified version you can try: https://github.com/SuperDisk/hUGEDriver/actions/runs/6444707503

This adds hUGE_current_order which is the current order that is being played. hUGE_set_position takes a number which represents what order to change to, I guess pattern is a misnomer here.

image

@RodrigoCard
Copy link
Author

Great!!! But I run into a linking problem with the new symbol when trying to use it
?ASlink-Warning-Undefined Global '_hUGE_current_order' referenced by module 'gameplay' make: *** [Makefile:41: out/mygame.gb] Error 1

@SuperDisk
Copy link
Owner

https://github.com/SuperDisk/hUGEDriver/actions/runs/6489024190

Sorry about that, try this.

@RodrigoCard
Copy link
Author

I finally got some time to test this properly.
The code compiles and links without any problems now.
And it ALMOST works... :)

I'm using it like this:
declarations:

extern const hUGESong_t test_music;
extern const hUGESong_t pause_music;
unsigned char test_music_position = 0;

inside my main game loop:

if(JUST_PRESSED(J_START) && can_pause && gamestate_time>60) {
        paused=!paused;
        if (paused)
        {
            test_music_position = hUGE_current_order;
            hUGE_init(&pause_music);
        } else {
            hUGE_init(&test_music);
            hUGE_set_position(test_music_position);
        }
    }

hUGE_dosound() is being called on vblank

So, I just store the hUGE_current_order in test_music_position and use hUGE_set_position with that. Is that right?

Anyway, it kinda works, but the position start drifting after a few unpauses, and skips waaaay out of bounds eventually, producing garbage audio and after some time, making the game crash:
Captura de tela 2023-10-12 174120

Suspecting some kind of misalignment, I shifted a few bits to see what happened and this was what worked best for me:
hUGE_set_position((test_music_position>>1)+1); (which is not correct either but doesnt crash.)

Any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants