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

Audio support #2

Open
timheigames opened this issue May 11, 2022 · 7 comments
Open

Audio support #2

timheigames opened this issue May 11, 2022 · 7 comments

Comments

@timheigames
Copy link

A few days ago I released my port of PeanutGB as well. I was able to get audio working using the SDL example as a guide. I could probably make a pull request, but it's easier to explain it since you are more familiar with your code base.

You will need minigb_apu from the Peanut-GB SDL example. The only changes you need to make to minigb_apu is the audio_callback and update_square, update_wave, and update_noise . If you reference main.c and Ctrl+F for "sound", you will see all of the necessary set up for the sound callback. Basically it's just using pd->sound->addSource() and audio_init() from minigb_apu. You also have to remove the source when closing the rom or it will create problems.

@mierau
Copy link
Owner

mierau commented May 11, 2022

This is great. I will take a look at this today. Thank you!

@mierau
Copy link
Owner

mierau commented May 13, 2022

I've just published Gamekid 0.4 with your work added. Thank you!

@mierau mierau closed this as completed May 13, 2022
@timheigames
Copy link
Author

I was messing around with the audio callback yesterday because I noticed sometimes enabling audio would create stutters in certain situations. Specifically I noticed them in the opening cutscene of Pokemon Blue, but I wasn't able to figure out how to fix it. One thing I found was that the left and right buffers are already initialized to zero, so there's no reason to memset them. And according to the docs you are supposed to return 0 if the audio cycle is empty. I'm not sure if this really matters since it seems to work fine always returning 1. Maybe it's a battery optimization or something. Anyways, here is a more "correct" version of the audio callback.

int audio_callback_playdate(void *context, int16_t *left, int16_t *right, int len)
{
	update_square(left, right, 0, len);
	update_square(left, right, 1, len);
	update_wave(left, right, len);
	update_noise(left, right, len);

    for(int i = 0; i < len; ++i) {
        if(left[i] != 0 || right[i] != 0) return 1;
    }

	return 0;
}

@timheigames
Copy link
Author

It seems like Gamekid doesn't have the stuttering problem like mine does, at least in Pokemon Blue.

@mierau
Copy link
Owner

mierau commented May 13, 2022

I'm going to reopen this issue as I am disabling sound in Gamekid for now. Looking at the 32bit sound emulation @deltabeard has in the works, I may wait until that is more fleshed out and use that. Also finding the noise emulation is very off. The lightning bolts at the start of Link's Awakening use it and they just don't sound right compared to, say: https://www.youtube.com/watch?v=E0ErE4l1EKM

@mierau mierau reopened this May 13, 2022
@trialhero
Copy link

Audio works for me 100%, but it is about 70% of the speed expected. No pitch bending, just slower. Is this anticipated behavior for how far along audio support is currently?

@1753135250
Copy link

看来 Gamekid 没有像我这样的卡顿问题,至少在 Pokemon Blue 中是这样。

May I ask if you can save in the Pok é mon game?

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

4 participants