Jump to content

Xuel's Photo

Xuel

Member Since 21 Aug 2008
OFFLINE Last Active Today, 2:31 PM

#4034108 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Yesterday, 10:28 PM

I can achieve the exact same result by going to System->Console Switches and enabling "Cart SDX", which would explain the ROM where the screen data should be. If you disable the aforementioned setting, all should be well, although output it not optimised for Altirra's POKEY emulation.


That was it! Thanks! Sounds good in Altirra with the following hacks: "e 44df d" "e 44e4 c".


#4032794 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Wed May 23, 2018 2:18 AM

Just drop the XEX and the PDM file into a FAT partition and run the PDM.XEX application using the XEX loader. You can run it from the SDX command line as well but the player loads at $1000 at the moment, so an exit to DOS is unlikely to be successful. It exits back to the SIDE loader just fine, though.


Could you point me to step-by-step instructions for setting this up in Altirra? I tried creating a 300MB FAT VHD with the files and adding a SIDE 2 device (w/ sload129.rom) pointing to it but when I run the XEX, the screen goes haywire:
 

screenshot.png
 
settings.png

I'm running the XEX by dragging it to Altirra. Do I need to run it from DOS/SDX?
 

I refrained from uploading the crude interleaving tool I wrote in C the other day since I'm certain Xuel can leverage a far superior toolchain. :) To recap: every 512 byte block (i.e. physical sector) of the file should be arranged thus:


Working on it... :)


#4029471 Can I learn to hack 5200 pole position controller code?

Posted by Xuel on Thu May 17, 2018 1:45 PM

  
Thank you. That is helpful. Would you or anyone else know of a book or internet based tutorial that would be an introduction to 8 bit/5200 programming that would include 5200 controller (analog/digital/trackball) programming? Or two sequential sources that would get me to the same point more or less?

 

The Altirra Hardware Reference Manual is a comprehensive Atari 8-bit computer and 5200 reference. The only other thing you need is a 6502 CPU fundamentals guide. Maybe this one is good? I haven't gone through it but superficially it looks OK.




#4029413 Can I learn to hack 5200 pole position controller code?

Posted by Xuel on Thu May 17, 2018 12:32 PM

In terms of the software, you would have to hack P.P's controller reading code (reading axes instead of buttons), and update also the game physics (so it not only recognizes "braking on/off", but "how much of braking". 

 

One way to handle braking without modifying the game physics too much would be to convert the analog braking value into pulse-width-modulated braking on/off. Varying the number of frames of braking "on" per, say, 20 frames would give you 20 levels of braking. So, for example, a very light braking could convert to braking "on" for 1 out of every 20 frames and full braking could convert to braking "on" 20 out of every 20 frames.

 

But maybe it's just as easy to modify the physics engine to handle variable amount of braking.

 

If I wanted to learn to hack the 5200 pole position rom controller code for a PC racing wheel with a homemade 5200 to 15pin PC adapter, is this a reasonable short term goal for learning to program for the 5200? I know pretty much nothing, like should I learn to do such a thing in BASIC or assembly? Where can I learn step by step to get to this point?

 

The end goal of this project would be to move the acceleration and braking from fire 1 and 2 to up and down, to have analog gas and brake that work on old PC wheels, to move the shifter to fire1 and fire2, since the PC wheel shifters are digital, and, finally, be able to fine tune trigger values for these four functions to work with variations in wheel voltage outputs.

 

Thanks!

 

You're going to need to disassemble the original game code into assembly so 1) you can understand how it works and 2) you know where to modify it.

 

Here's a quick disassembly the 8-bit computer version of Pole Position to give you an idea:

 

Attached File  pp.zip   301.34KB   10 downloads

 

I included my disassembler "dis" and xasm. I didn't label anything other than the standard OS and hardware memory locations. Disassembly is an art. You have to figure out what various parts of code do but the main thing is figuring out how the data and variables are laid out. Once you know which memory locations correspond to various aspects of the game it becomes much easier to understand what's going on throughout the code. For example, one byte may be used by the code to store the velocity of your car. Figuring out which one will help you unravel other bits of code since you'll see all the places that refer to that byte and then understand they must have something to do with either setting or reacting to the velocity of the car. It's a multidimensional puzzle.




#4027190 PWM experiments

Posted by Xuel on Sun May 13, 2018 9:58 PM

I have the same doubt about the setup. Probably Phaeron and Xuel can explain it better.
I would need to see some graphics to really understand how this technique works x)

 
I believe this is explained in the last paragraph of the "Linked Timers" section in the Altirra Hardware Reference Manual. You are taking advantage of the one-shot produced by channel 1 of a channel 1+2 linked timer setup. Setting AUDF2 to anything greater than or equal to 1 will work. That insures that channel 1 will behave as follows: it will pulse after AUDF1 cycles and won't pulse again for another 256 cycles. This occurs because AUDF1 keeps running without reloading even though it has underflowed. This occurs because when the timers are linked, they both reload only when AUDF2 has underflowed. Since STIMER is strobed every 114 cycles, you never reach that second pulse.
 

Yep, I assumed 114 cycles for a scan line, without the 4 cycles for the next STA STIMER (110 different values, range from 0 to 109 for every sample).


I think the max value is actually 100 not 109. phaeron's audio encoder for 60FPS video uses 100. See here. This probably has to do with the number of cycles required for resetting the counters with STIMER.




#4026961 PWM experiments

Posted by Xuel on Sun May 13, 2018 2:58 PM

That quantization stuff was the part the way rather clear to me (except maybe where the 109 comes from).

 

Beyond 109, the pulse doesn't occur before the next scan line resets everything again with STIMER. The effect is that you get clipping.




#4026894 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Sun May 13, 2018 1:08 PM

I'm coding up an IDE-based PDM player, and it would be useful to have a raw dump of the file included in the XEX player from the other evening. I installed SOX already but I'm all fingers and thumbs with the build process, and I don't need any interleave: just sequential bytes. Using the same piece of music would also be a good idea from the standpoint of testing. I wonder if Xuel could upload it?

The strategy I'm initially going for is - ironically - to buffer data in order to overcome the problem of waiting for data to become ready on the IDE controller. The player will issue a read, pull data from the buffer until the IDE data is ready, then - while playing the upper half of the buffer - pull two bytes from the data register and place them in the lower half of the buffer for every byte retrieved from the top of the buffer. With careful unrolling, this should eliminate any blips. ;)

 

Here is the source tune (elektric_funk.mp3) re-sampled to various sample rates for PAL and NTSC:

 

Samples

 

Each file contains a raw sequence of 8-bit samples as produced by sox.




#4025753 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Fri May 11, 2018 3:02 PM

Testing on my 1088XEL now.  Should have put on my HDD.  Takes forever to dump a MB of data even at 3X SIO :)

 

VOLUME ALERT at 0:29!!!

 

Awesome! So we can add 1088XEL to the list. BTW, I think you mean volume alert at 0.05. :)




#4025673 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Fri May 11, 2018 1:20 PM

Here's an XEX that uses 1088MB of RAM:

 

Attached File  ram1088.xex   1MB   43 downloads

 

You can press START during playback to switch between 1/16 duty cycle tuned for Altirra (white on black background) and 1/7 duty cycle tuned for phaeron's 130XE (black on white background). Maybe some folks can run on real hardware and verify that it sounds good in the black on white background mode?




#4023395 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Tue May 8, 2018 8:33 AM

Why don't you use AUDC3 for $1x coarse level ($x0) sample part instead of AUDC2 (AUDC3 is using to dutycycle control of AUDC1 wave and is always deaf)? I think your method could use only two channels: AUDC1 for fine 1/16 sublevels and AUDC3 for coarse level and left AUDC2 and AUDC4 for other sound (it's a shame that they can't be clocked by 1.77MHz :/, however what do you think about using 64kHz and 1/3 carrier for them?).

 

Great idea! Works like a charm:

 

Attached File  calibrate.xex   2.56KB   44 downloads

 

Could you elaborate on the 64kHz 1/3 carrier idea?
 




#4023340 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Tue May 8, 2018 7:01 AM

Not sure what's going on specifically yet... not enough resolution to see what's going on with the audio input and too chaotic to use the scope. Have to check whether high-pass timing might differ between the 800XL and 130XE. Unfortunately, only one MaxFlash cart makes switching between the two demos kind of painful.

 
Ugh. Hopefully not the nail in the coffin for getting this to work on real hardware.
 
Here's a calibration program:
 
Attached File  calibrate.xex   2.56KB   22 downloads
 
Maybe a different setting for Pulse Y would fix it on real hardware? I used 12 and 13 for X and Y in the original code. The X/Y values are used as follows:
 
    ; Set up 1/16 dutycycle HiPass on 1+3
    mvx optpulsex AUDF1
    mva optpulsey AUDF3
    sta STIMER
    stx AUDF3

Full code here.


#4023093 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Mon May 7, 2018 7:08 PM

This is exciting stuff, of course I am ignorant of the vast majority of the sound tech speak here. Now, would this process be limited to just two voice channels due to processing overhead, or could this be enhanced further with a second two voices doing the same thing, and possibly further enhanced with a second POKEY chip too?

 

The new method actually requires three channels, either 1,2,3 or 1,3,4. Channel 2 or 4 plays the high 4-bits. Then both 1.79Mhz channels (1+3) are paired via the high pass filter to create the 1/16 signal (effectively DC at 1/16 VCC) for the low 4-bits. That leaves one channel that could play normal 15KHz or 64KHz sound or 4-bit PCM.

 

You could definitely use a second POKEY to achieve stereo. I've actually experimented with that using PWM but I'll save that for a different thread some other time. :)

 

BTW, I share kool kitty89's reservations about calling this new method PDM since the pulse density is actually constant, not modulated. What shall we call this new method? PCM44?

 

BTW, another thing I realized is that you could vary the pulse signal from 1/16 to 16/16 as a master volume control on a 4-bit PCM sample. Kinda interesting. Not sure how useful it is since it would only work for one channel.




#4022968 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Mon May 7, 2018 4:06 PM

 

I just realized that kool kitty89 actually originally posted this back in 2015! So, huge thanks to you for bumping the thread.  :thumbsup:




#4022912 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Mon May 7, 2018 2:33 PM

I'm not sure if this technique is ever actually used in existing games or demos, but using 2 POKEY channels and two timers, it should be possible to get 8-bit linear PCM output through POKEY. Set one timer to the desired sample rate and set one 4-bit volume level for the upper 4 bits of a sample while the lower 4 bits go to the other channel. The second channel gets its volume then cut again to 1/16 by using the second timer to set the duration of the pulse to 1/16 of a sample period.

 

Is this method something you've seen used elsewhere? What gave you the idea?

 

It's so obvious now that I know it but I would have never come up with it on my own. Thanks for the mind expansion. :)




#4022904 Using Pulse Density Modulation for 8-bit PCM

Posted by Xuel on Mon May 7, 2018 2:27 PM

I went back and did my last "megamix" in pdm 8 bits at 15.7Khz.

I was already using one byte per sample so the memory consumption is the same and there is no carrier frequency.

I don't know about real hardware, but in emulation it sounds reeeeally nice.

 

Sounds excellent!

 

So amazing that this method has been there in POKEY this whole time and we're just now realizing it, amiright?!  Huge kudos to kool kitty89 for showing us the light. :)