It is currently Tue Aug 14, 2018 6:40 am

 All times are UTC - 7 hours

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Apu EmulationPosted: Sun Jan 23, 2005 7:50 pm

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
well, after al the advices and help from you guys i made a simple thing to hear sounds. I think its a good starting point.
i check when the channel timer register is written, and take the 11 bit wavelenght and convert it to herz with the following formula:
hz = 1789772.5 / DIVIDER / WaveLenght

Where DIVIDER is 16 for square and 32 for Triangle (i guess), then thanks to Charles Petzold "FillBuffer" function expample form his "Programming Windows" Book, i convert "hz" to PCM format.

The result? sound.. but very poor. I know disch told me about a way of taking all the outputs to sample correctly: as APU does.

But i didnt understand you well disch, if you could explain it to me very "step-by-step" i will preciate it.

_________________
ANes

Top

 Post subject: Posted: Sun Jan 23, 2005 8:11 pm

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1849
Calculating to Hz is a bad idea. Since the APU revolves around cpu cycles... you just have to execute the cycles as they come.

To emulate a Square Wave channel... you'll need vars to track the following (my 'aka' is what I'll be referring to those vars as later):

- The 11-bit written wavelength value (aka nProgTimer)
- A counter to 'count down' that wavelength value (aka nProgCount)
- The current Duty cycle (2,4,8, or 12... representing 12.5%, 25%, 50%, and 75% duty cycles respectively) (aka nDutyCycle)
- A counter to track the steps through those duty cycles (aka nDutyCount)

You'll need to do the following for every 1 CPU cycle (assuming channel is active):

- if nProgCount is zero...
--- increase nDutyCount by 1 (wrap at 15 ... 15->0)
- else, nProgCount is not zero...
--- decrease nProgCount by 1

the APU's output for this cycle is found by checking the following:

* if the channel is silenced by the Length Counter, or Sweep Unit --- output is 0
* else if nDutyCount is greater than or equal to nDutyCycle (in the 'negative' portion of the duty cycle) --- output is 0
* else, output is whatever the current Volume level is

now note... if using the simplest, low quality method of downsampling I mentioned earlier... you'll only be taking the output after every ~40.58 CPU cycles

Top

 Post subject: apuPosted: Sun Jan 23, 2005 10:43 pm

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
thanks disch, i will try implement that.

_________________
ANes

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 3 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: zeroone and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki