PCM engines

Posted in Uncategorized on November 9, 2015 by pcedev

I’ve already stated that I’m redoing the 4 channel XM engine, and it’s up and running with a few looped notes until I finish parsing a particular mod file for simple demonstration, but I also have another engine I threw it together over a couple of hours on the weekend; an 8 channel static PCM player. 8 PCM channels at 6bit (higher than the native 5bit) and still leaves 4 normal PCE channels. Yeah, a total of 12 channels.

The second engine required more support though. The first engine only required a small 384 word table. This second engine, because all the PCM channels are mixed in software, requires volume tables because multiplying each sample is waaayy out of the scope of the PCE – tables do the work even faster. The PCM format also needs to be in 2’s complemented numbers. The PCM data might be 6bit, but it’s in 8bit format as signed numbers. Maybe this is overkill, but it just feels cleaner than adding any possible side effect because it’s not centered (a relative centerline). I’ve done mixing in software before with unsigned samples, but the center line moves around (the waveforms still accumulate the same). It just doesn’t sit well with me, so 2’s complement signed format it is. But that means the volume table has to include all 256 entries even it only uses 6bit resolution/values. At 32 levels of volume control, that’s an 8k table. Doesn’t need to be ram; fits anywhere in rom.

But yeah, so it needs more support/tools surrounding it. I had to make a wave file converter in C. I needed to make one anyway, so this isn’t a total waste of time. So what does this engine eat up cpu wise? about 21-22% cpu resource. I kid you not. 8 PCM channels, at 6bit vs 5bit, and still have 4 PCE channels left over – all faster than Air Zonk does to play a single PCM channel. Yeah, Air Zonk has a horrible PCM routine that eats up 30-33% cpu resource. I couldn’t believe it, but I checked it about 20 times over, and each time was 30 to 33% (33% when it has to fetch a new sample to bit shift, 30% when it’s just playing that sample).

Keep in mind, none of these 8 channels in the second engine scale in frequency like the first engine. It’s actually nothing super special or radical. 8 channels are soft mixed, with volume control for each channel, into a single buffer. That buffer is played using two PCE DDA channels to output 10bit audio. That’s it. The other downside is that it’s mono. If you want stereo, you have to take away another two PCE channels for a second 10bit paired output. Not enough channels you say? Want stereo you say? Well, bump up that number up to 37.3% cpu resource and get 16 PCM channels – stereo. You still have 2 regular PCE channels left over. For an extra 5% cpu resource on top of that, I can make 4 of those stereo channels frequency scale XM style. So many options…

That’s ridiculous! What the hell would someone do with 16 PCM 6bit stereo channels!?  But hey, 18 channels on the PCE would make a great demo – no? Brag rights and all that sort of thing, I guess. Does the PCE have enough power to do more than 18 channels? Don’t ask. But yes. It does.

PCM player

Posted in Audio on October 31, 2015 by pcedev

That old PCM player that’s in the download in links section? No good. I was looking over it and realized that not only is it convoluted and complex, but the interface really doesn’t show how to use the damn thing. It’s a poor example.

So I revisited it. I’m going to attempt to modularize it into an easy library of sorts. I’ll include macros and routines for basic functions for controlling each channel. I also made it a little more friendly to memory page layouts compared to the fix bank requirement from before. This bumped the cpu resource up by 2.7%. In addition, I added dynamically controlled fixed frequency sample streaming for the last two channels. So 4 XM channels and 2 PCM streaming channels.

I refer to them as XM channels, because they use a linear frequency approach compared to period base system of MODs. It’s a phase accumulator. The nice thing about this, is that I don’t need a huge table to translate notes to frequencies. I actually only need a table of 12 notes at C3 (octave 3). Everything else can be derived by shifting that left or right. The phase accumulator is 19bits long with the top three bits being the whole number and the lower 16bits being the float part (fractional value). So I have a finetune table of 16 points between notes (plus or minus direction) for finetuning the wave form without the need of an external program. And lastly, I have 32 frequency steps in between notes. I could have more… waaayyy more given the 16bit fractional part of the frequency divider, but honestly from my experience 16 usually cuts the cake anyway, so 32 should be enough. The steps are for frequency sliding (or vibrato).

I’ll include a small command line utility that prep a wave file to the format needed for the player. The player supports loop points, so those would need to be included into the waveform directly for that support. I also don’t track the waveform by its length, but rather have an end of marker value in the stream itself. So those need to be included as well.

So the numbers I have for 4 XM channels is 29% cpu resource from the call to the RTI at 117 times per frame (1/60) – for all channels playing.  The frequency division is all handled inside the timer routine, so you would just need to provide the note to play.  For the 4 XM and 2 PCM, that number jumps to 36.6% if all six channels are playing. Still not bad at all. The timer interrupt is actually 6.991khz and not 7khz, but I reset the timer counter ever vblank to keep it in sync, and do an mid-between call to the timer routine – so it ends up being 117 calls per frame or 7.02khz. Honestly, if I skipped it and did 116 I doubt there would be an audible difference.


On the topic of audio, have you guys ever heard the PCE stream 55khz 5bit PCM using the channel’s waveform memory as a buffer? Check it out: http://pcedev.net/6280a/sgx_dump.wav   That was recorded from my SuperGrafx. Basically it’s a 1.7khz timer interrupt, which means an interrupt called 29 times per frame. Each interrupt call, just refill the buffer. On the SGX, you only need one channel to do this (or any of the core grafx consoles with the 6280a processor). The regular 6280’s need two channels to do this. Sounds pretty good for 5bit audio. Because of how audio tends to get filtered/blended at that higher range, you can actually interleave channel streams and have them mix together. You could do a ~64khz output setup, but have four streams feeding it in interleave format for a 4 channel PCM stream at 16khz each. Not bad at all, especially considering how light the cpu resource is compared to something like 7khz single channel output the old fashion way. But here’s the crazy thing, as if that wasn’t crazy enough, you can do this with two channels on the SGX and stream 10bit audio in the same fashion. Just let that sink in for a minute…

Email and server is back up..

Posted in Uncategorized on October 30, 2015 by pcedev

I’m currently reconciling all the stuff between my laptop and new desktop setup. I don’t think my laptop is going to survive much longer.

SamIam and I talked about the possibility of a dub for Spriggan Mark 2. That’s all I’ll mention at the moment on that.

I finished my final for one my classes, so things I’ve got more free time, which is one of the reasons why I’m setting up my desktop system; pce dev stuffs. In an attempt to get more organized, I’m going through and trying to make a list of all the wonderful things and possibilities of PCE stuffs that I want to do. I have a terrible time trying to keep track of all these things, so I need to organize them into a system. I tend to forget about things. It’s not that I lose interest, but I forget and pick up other interesting stuffs.

Anyway, just an update. Also, if you come across anything that appears damaged (file wise) for my links, let me know.

Email and file server is down

Posted in hacks, homebrew, NES2PCE, retro on October 17, 2015 by pcedev

My server account got suspended cause I didn’t pay the bill. Hopefully I can get it back online in the next few days.

I’ve been messing with PCE hardware this weekend. Also looking over what projects are due, what needs attention, and what is going to be put on the back burner (for time resource reasons).

That and just some gaming on the SGX+SCD. I was playing SMB (nes2pce) and realized I could optimized some of the nes2pce PPU emulation code. Anytime the cpu writes to vram, the internal emulation code has to do all these checks to make sure it’s transferring data to the right area (and how to interpret that data). I needed this because I found games could just load PPU tile, sprite, and tilemap stuffs all in one shot.

Of course this slows things down having to do all these checks. Sometimes it puts what would normally be the cpu in vblank time, into the start of active display. I figured one way to speed this up, is to have dedicated $2007 write functions. NES games tend to setup strings of data into a buffer to be updated during vblank (because game logic is processed during active display). This means it’s very rare that a string of data will cross a tile bank into a nametable area, etc. So for those areas of code, I could potentially use the faster and specific $2007 write functions.

Nes2pce code was never meant as general emulation for NES games to run on the PCE. It was to get the game up and running close as possible, to help the transition of replacing the original NES sprite and map routines into native PCE stuffs. Though none of the nes2pce stuffs I’ve released have these changes.

Ideally, the sprite and map routines should be hacked for direct PCE writes, by passing some of the PPU emulation. So the optimization I listed it kind of counter intuitive to the goal of nes2pce. But I just don’t have the time to alter each game for these kinds of changes. I used to have that kind of time, but I squandered it :/ Eventually, I will have that kind of time again – but will people really care about nes stuffs on PCE by then? One example is Dragon Warrior. It’s the first RPG I’ve ever played, so I have nostalgia for it. I’ve already hacked the map routines somewhat. The game is simple enough to keep modifying. But should I really put my time into it? This is the dilemma I’m faced with nes2pce.

Anyway, just thinking out loud.

Moved in

Posted in Uncategorized on September 7, 2015 by pcedev

I got my new place and starting moving stuff out of storage. PCE and SGX+SCD are setup. Just need to setup my dev PC.

PCE Chiptunes

Posted in Uncategorized on August 21, 2015 by pcedev

Check out the other videos (more PCE chiptunes).

Reporting in…

Posted in Uncategorized on July 24, 2015 by pcedev

Wow, it’s been a crazy year for me. I apologize for the lack of updates, but one of the keys to a successful semester is for me to remove all distractions. I have a 4.0 for these past three semesters (took a full summer semester; that nearly kicked my arse!) and have worked hard to achieve that GPA. Anyway, I’m just trying to catch up to see what’s happening in the scene and such. I’ve read the comments you guys have posted over the past few months (and approved them) – thanks! If you’ve been approved once, to have your comment show up, then you can post as many as you like without having to have them approved each time afterwards.

My Mom is doing a lot better now – the medication is working (though she has to take it for the rest of her life). She’s feeling sooo much better too. My older son had some serious trouble this past year and had to be hospitalized. He’s been diagnosed with crohn’s disease, which basically is where your own body/immune system attacks your digestive track/intestines. They became so inflamed that they weren’t pulling any nutrients/calories from his food; he was basically starving to death. He lost 60lbs, and all his blood work was dangerously off (had to be hospitalized), and could barely stand or walk. They were going to do surgery (to remove parts of his intestines), but the medication they have him on is currently working and he’s starting to gain back the weight (as of this past month). If you’re a parent, then I don’t need to begin to explain how it feels to watch your child go through this (he’s 19 year old, but he’s still my child). Once he gets his health back up, I’m gonna try to convince him to start on his computer science degree.

My younger son, 13 years old, just finished his first college class. He met the legal age for community college and so for his birthday I paid for him to take a math course over the summer at the same campus I’m attending. He just completed 7th grade, and he amazingly passed all the assessment tests into college level reading, writing, and math. He’s never had an algebra class, but I’ve taught him algebra stuffs since he was little. He tested right under college algebra, and so he took an Algebra-II class and passed it with an A; his first college class. If he took one math class each semester in college while attending regular school, he’d be done with all three calculus classes (Calc I, II, III) by the time he starts his 2nd year in high school. Crazy. I took trig this summer so I can start calc this fall, and so he learned a little trig this summer too. He definitely has a brain for math – lol.

Life sure is a roller coaster. And the best you can do, sometimes, is just hold on as tight as you can. Anyway, I have 20 days of “vacation” from school this August, so I need to catch up on some PCE related stuffs.


Posted in life on February 15, 2015 by pcedev

This year has been off to a terrible start. My financial aid got suspended (something stupid that only community colleges are subject to), and I had to appeal it. On top of that, they decided to add a 2 week delay to all financial aid. I almost became homeless as a result (I couldn’t find a place to rent either). On top of that, my mother found out in mid January that she has leukemia. She was given a months worth of trial chemo pills, which are normally $10,000 a month. She was waiting to hear back on an application to get it at a reduced price. She ran out of medication waiting for this application to go through. This past week they finally approved the application. Things have been really stressful. All three problems have now been resolved, but man… what a shitty start to a new year. I’m hoping to regain some measure of focus and order in my life now. Whew. When it rains, it pours? Maybe.

Update: November

Posted in Uncategorized on November 15, 2014 by pcedev

I’ve completely underestimated college. I’ve got some free time from one class finished up, but I’ve since filled that with work (trying to save cash like crazy). I’ve ran some numbers and at the going rate, I won’t have enough loan money and financial aid/grants to finish getting my degree (and I qualify for the max amount). I’ll run out around the last year or so. Working federal study (20 hours a week) only provides minimum wage and I’ve included that into the numbers and analysis as well. This means I need to maintain a highest GPA possible to hopefully qualify for yearly scholarships. Pima College (state community college) is only $1,700 year for 28 credits, but the U of A, where I plan to get my undergrad in Computer Science, is $11,000 a year. Neither of those numbers include books or obviously cost of living. On top of that, all math classes (Calc I,II,III, Linear Alg, Diff Equ) and *any* supporting science class all ~need~ to be have a ‘B’ or higher in grade completion, else I won’t be accepted in the last major part of the program; they aren’t messing around ;>_> That was an eye opener.

Anyway, point being – I won’t have as much free time as I would like or had originally thought. That doesn’t mean I plan to abandon PCE coding (I’m not), but my progress in college is the highest priority, and the free time I do get for do PCE stuff – will be highly selective. That means those projects that I have on going, like nes2pce stuff, will probably not see much action or attention (if any). I have winter break coming up, and I have summer break later on. Those are the times where I’ll probably be the most productive. Looking back now, I’ve clearly wasted time that could have easily been put to PCE stuffs. But hindsight is 20/20, as they say…


Posted in Game 2014, life on September 22, 2014 by pcedev

Not dead, not dead. This is my first semester, so it’s taking quite a bit to get used to being efficient with my time (studying/homework/etc). That, and I took accelerated Spanish. I will NOT make that mistake again. That Spanish class is actually eating most of my time (too much to remember and learn in a short period of time), but it ends early – medio octubre. Should have more free time then. I’m gonna continue taking Spanish as far as it will go. I’m hoping to get a grant to study abroad when I transfer to a larger university. Voy a viajar a España! También, a mí me gusta mucha la PC-Engine. And some Latin American countries too.

But yeah, Black Tiger is working out some ideas for the story for the game project. Things will be slow, for a little bit – but should pick up in October. And full force for winter break.