pradipna: Nice work!
I hope you (and WingsORC) keep your projects up, its nice to see people working on new emulation projects & keeping the programming community active. Looking at this thread brings me back..
pradipna: Nice work!
I hope you (and WingsORC) keep your projects up, its nice to see people working on new emulation projects & keeping the programming community active. Looking at this thread brings me back..
Thank you Shizzy.And Good Luck with your projects that you are currently working on...
Last edited by pradipna; October 22nd, 2011 at 04:05.
Thanks too. My emulator shows only a glitchy asteroids intro so farbut well the progress is steady!
Hi, I've been slowly plugging away on a gameboy emulator since june. I've made a lot of progress but sound emulation is a very new thing to me. I've emulated the first 2 channels and they sound something like a piano player who always hits the adjacent key... I used SDL_audiospec while following codeslinger's master system sound code and I ended up with this:
where playbackBuffer is copied into the audio buffer in my SDL_audiospec's callback routine, and updateBufferLimit is the interval measured in clock cycles between the times that the tone is stored into playbackBuffer. The value calculated for updateBufferLimit should make playbackBuffer completely filled by the time SDL requests its audio buffer to be refilled, but it tends to vary. When bufferPosition < BUFFERSIZE equals false, the tone doesn't get put into the playbackBuffer since the array has been filled already, and this seems to happen too often, which I believe is what makes the music sound sloppy.Code:updateBufferCount += cycles; if (updateBufferCount >= updateBufferLimit) { if (bufferPosition < BUFFERSIZE) playbackBuffer[bufferPosition] = tone*3000; bufferPosition++; updateBufferCount = updateBufferLimit - updateBufferCount ; }
If there is any better way to program this, I'd love to know, since I've never done anything like this before. Maybe something other than SDL would work better, or I could just be doing it wrong...
I don't have any experience with SDL so I can't really help you on that. I am using xAudio2. The way I am emulating channel 1 and 2 is like this, I have created 4 buffers with different wave duty (12.5%, 25%, 50% and 75%). When game wants to play sound from channel 1 or 2, I just copy the required wave duty buffer to xAudio source buffer and loop it infinitely at given frequency. And stop it according to sound length register, or sweep frequency overflows etc etc...
Drenn,
Have you checked out:
http://slack.net/~ant/libs/audio.html#Blip_Buffer
It's written using SDL, and really helpful for audio emulation of older systems. Blargg also has a really simple example of the Game Boy PAPU sound chip emulator, written in C/SDL (if you're feeling less adventurous).Blip_Buffer implements an efficient band-limited sound buffer for high-quality emulation of sound chips. After setting the source clock rate and output sample rate, sound waves are made by specifying the time points where amplitude changes occur.
Thanks for replying
As it turns out,
should have beenCode:updateBufferCount = updateBufferLimit - updateBufferCount ;
An honest mistakeCode:updateBufferCount = updateBufferCount - updateBufferLimit;
It sounds loads better now, just a little... how to say... unclean? Not as crisp as it should be. Blip Buffer sounds perfect for an emulator, I'll probably use that when I'm feeling less lazy. For now I'm happy with the result, I just need to emulate sweep and noise. I may be back to ask about the details of sweep, since my previous attempt at emulating that ended badly.
Edit - gah, now the frequency for channel 3 sounds too low in some cases, like the intro in mario deluxe. Screw it, I'll use blip_buffer!
Last edited by Drenn; November 1st, 2011 at 00:43.
I am SO close... it sounds nearly perfect, like a real gameboy... except that channel 3 has an annoying tendancy to be a little bit off-tune sometimes. It completely wrecks a few songs
Weirdly, for channel 3 the pandocs say:
but the value that works for me isCode:Frequency = 65536/(2048-x) Hz
Does anyone else have this? Could this be screwing up the frequency just slightly? It's driving me crazy!Code:frequency = (65536/(2048-x)*32) Hz
Edit - Ohh, the 32 is for the 32 samples. Still, the off-tune channel 3 remains at large... here's my code:
Sorry for the mess. It's possible the error's not in there, but unlikely. It's the only channel giving me problems.Code:// Channel 3 if (chanOn[2]) { static double polarity[] = { -1, -0.8667, -0.7334, -0.6, -0.4668, -0.3335, -0.2, -0.067, 0.0664, 0.2, 0.333, 0.4668, 0.6, 0.7334, 0.8667, 1 } ; if (chanVol[2] != 0) { // Read the sample from ram int wavTone = ioRam[0x30+(chan3WavPos/2)]; wavTone = chan3WavPos%2? wavTone&0xF : wavTone>>4; // Add the sample to the output if (chanToOut1[2]) toneSO1 += (polarity[wavTone])*(0xF >> (chanVol[2]-1)); if (chanToOut2[2]) toneSO2 += (polarity[wavTone])*(0xF >> (chanVol[2]-1)); } chanPolarityCounter[2] -= cycles; // Update polarity if (chanPolarityCounter[2] <= 0) { chanPolarityCounter[2] = clockSpeed/(65536/(2048-chanFreq[2])*32); chan3WavPos++; if (chan3WavPos >= 32) chan3WavPos = 0; } // Check that it hasn't timed out if (chanUseLen[2]) { chanLenCounter[2] -= cycles; if (chanLenCounter[2] <= 0) { chanOn[2] = 0; chanPolarityCounter[2] = 0; clearChan3(); } } }
Last edited by Drenn; November 4th, 2011 at 03:30.
Ok, I have finally decided to release the new version of my emulator. Here's a feature list:
Features:
---------------------
-> Can emulate GameBoy and GameBoy Color hardware.
-> Sound Emulation (excluding Vin output)
-> Keyboard and JoyPad input support.
-> MBC1, MBC2, MBC3 and MBC5 support.
-> Real Time Clock emulated.
-> Battery Pack support. Save format is compatible with VBA-M.
-> Save State
-> VisualBoy inspired Turbo Button. Press Space to speed up the game.
I have increased the compatibility too. I am going to keep this project aside for now and work on a new one.
If anyone's interested, download it from here: http://www.pradsprojects.com/dinoboy.html
I've been working on a GB emu recently. I've got Tetris and Super Mario Land working great. Now I'm trying out Blargg's tests... It's telling me my "ADD SP,n" and "LD HL,SP+n" are broken somehow, but it doesn't say what the problem is, and I can't find it. Does adding to SP affect flags differently or something?
I tried copying what VBA does, but it doesn't seem to have helped. (I didn't even check if VBA passes that test either... >.>) bgb passes all the tests, but its source doesn't seem to be available.
'Zig' Bus Lines. Moving for great justice since AD 2101.
There are 11 types of people in the world: Those who can count in Binary and those who can't.