Author Topic: Some audio stuffs  (Read 4097 times)

touko

  • Hero Member
  • *****
  • Posts: 953
Re: Some audio stuffs
« Reply #15 on: November 06, 2015, 04:21:57 AM »
Thanks tom for clarifying about the cpu used for PCM , i was not sure about the number of percent,this is why i deleted my answer for chris ..
Of course i spoke only for PCM and my values are for PCM only .

Quote
It was at 33% when it had to reload the bit shifter (decompress the samples), which if I recall is every three samples or so.
i probably use the same method to compress samples .
1 sample in the first 5 bit of the 1st byte
1 sample in the first 5 bit of the 2nd byte
and the 3th packed in the 3 last bits of the first byte, and the 2 last ones in the 2nd byte, in fact only the 3th sample needs to be shifted .
Of course you lose 1 bit, but your sample is reduced by 33% ..
« Last Edit: November 10, 2015, 09:41:36 PM by touko »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Some audio stuffs
« Reply #16 on: November 06, 2015, 04:30:14 AM »
I found over the years that good game developers, don't necessarily produce the most optimal code or design - to put it nicely. I've attempted to understand the thinking and philosophy of Japanese programmers in the 80's and 90's, and I'm just at a complete loss. I know there are factors keeping them from optimizing and fine tuning every little thing, but as a programmer and people that I known as programmers - there's this idea, this desire, this drive - that you want to create the best/fastest/whatever code possible; you want to push something to its limits. I guess that's a cultural thing and that's not what motivated most Japanese programmers at the time (with exceptions of course. There are always exceptions). 

 I read an interview with one of the guys that worked with Nintendo to get 3D on the SNES (originally meant for NES - the MARIO chip), and how he ended up moving to Japan and working directly with Nintendo programmers and producers for a number of years. He mentioned that game developers, like Miyamoto, would often take a game back to ground zero - many times during its development. If that was the case, I can see how optimizing stuff would be a waste of time during the development cycle. But to me, that shows that the producers were simply dictating to the programmers rather than working with them. Like I said, I really don't know.

Quote
So that adpcm player you posted a video of playing that Mega Man cover would be doable cpu-wise in an RPG then? It'd be a cool way to do snippets of voice acting in cinemas (which I assume are even less intensive) or for repetitive bgms.
Yeah, but it doesn't save a whole lot space (although the final sample output quality is better).

 There are a lot of things you can do with an traditional JRPG that you couldn't normally do with an action game. For instance, you don't need to run the game at 60fps. It doesn't really benefit from it. But imagine what you could do with essentially a 14mhz cpu (basically what it translates into; twice the cpu cycles per "frame")? You already know the limitations of some of the graphics on the PCE; mainly tile flipping and layer priority (different than parallax). For instance, you could do tile streaming engines, where not only would it solve the tile flipping issue - but you could also create unique sets of tiles on the fly by compositing small details (later gen SNES games use multilayer BGs as a single BG to do this). Sprites could be AND'd in realtime with masks to create priority on a per pixel basis (I did a routine that can do this at 2% cpu resource per 16x16 cell sprite). All kinds of graphic effects for the overworld. The same could be applied to battles, etc.   

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Some audio stuffs
« Reply #17 on: November 06, 2015, 04:35:32 AM »
Thanks tom for clarifying about the cpu used for PCM , i was not sure about the number of percent,this is why i deleted my answer for chris ..
Of course i spoke only for PCM and my values are for PCM only .

Quote
It was at 33% when it had to reload the bit shifter (decompress the samples), which if I recall is every three samples or so.
i probably use the same method to compress samples .
1 sample in the first 5 bit of the 1st byte
1 sample in the first 5 bit of the 2nd byte
and the 3th packed in the 3 last bits of the first byte, and the 2 last ones in the 2nd byte, in fact only the 3th needed to be shifted .
Of course you lost 1 bit, but your sample is reduced by 33% ..


 AZ is using a full 33% for a single channel though. You have it down to 3-4% per channel, right?

touko

  • Hero Member
  • *****
  • Posts: 953
Re: Some audio stuffs
« Reply #18 on: November 06, 2015, 05:00:36 AM »
Quote
AZ is using a full 33% for a single channel though. You have it down to 3-4% per channel, right?
Yes, 3/4% with banking, buffering,decompress and of course playing sample .

Even my first unoptimised pcm driver was far under 30%, may be 6/7%,i can not understand how coders could be satisfied with 30%.

« Last Edit: November 06, 2015, 05:09:35 AM by touko »

Sunray

  • Newbie
  • *
  • Posts: 18
Re: Some audio stuffs
« Reply #19 on: November 06, 2015, 06:08:02 AM »
Hello, my first post here.

What is the difference between HuC6280 and HuC6280A exactly? I've head different things like click reduction and panning fixes?

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Some audio stuffs
« Reply #20 on: November 06, 2015, 06:13:06 AM »
Touko, this should give you an idea.... ;_;

Code: [Select]
    phy
    phx
    pha
    sta $1403
    lda <$f1
    bne .skip
    lda #$01
    sta <$f1
    cli
    tam #$02
    pha
    tam #$03
    pha
    tam #$04
    pha
    tam #$05
    pha
    tam #$06
    lda #$31
    tam #$02
    inc a
    tam #$03
    inc a
    tam #$04
    inc a
    tam #$05
    inc a
    tam #$06
    jsr $4000     ;jumps to DDA and music routine
    pla
    tam #$06
    pla
    tam #$05
    pla
    tam #$04
    pla
    tam #$03
    pla
    tam #$02
    stz <$f1
.skip   
    pla
    plx
    ply
    rti

 This is just the intro and extro code (TIMER routine). It's ridiculous because none of that overhead is needed for the DDA streaming part. And yet, there it is.

 To clear any confusion, music engine is tied to the TIMER interrupt and not the Vblank interrupt. But I think even an entry level programmer could see the issue here. All those bank mapping and saving, etc - none of it has anything to do with the DDA sample and the bank it comes from. And it's mapped every time @ 6991khz even if a sample isn't playing.
« Last Edit: November 06, 2015, 06:19:38 AM by Bonknuts »

touko

  • Hero Member
  • *****
  • Posts: 953
Re: Some audio stuffs
« Reply #21 on: November 06, 2015, 06:24:17 AM »
Quote
Touko, this should give you an idea.... ;_;
  :shock: LOL, it's crazy how it's very bad coded,i understand why it takes 30%  :mrgreen:
« Last Edit: November 06, 2015, 06:30:19 AM by touko »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Some audio stuffs
« Reply #22 on: November 06, 2015, 06:30:59 AM »
Yeah, it's bad. Not just that, but the Hsync routine is a mess as well. I'm surprised this game isn't in perma slowdown.

touko

  • Hero Member
  • *****
  • Posts: 953
Re: Some audio stuffs
« Reply #23 on: November 06, 2015, 06:40:05 AM »
Yeah, it's bad. Not just that, but the Hsync routine is a mess as well. I'm surprised this game isn't in perma slowdown.
:lol: right, i'll say more it's impressive in fact,it's like running a maraton with a mobil home attached ..

elmer

  • Hero Member
  • *****
  • Posts: 2153
Re: Some audio stuffs
« Reply #24 on: November 06, 2015, 06:56:59 AM »
I found over the years that good game developers, don't necessarily produce the most optimal code or design - to put it nicely. I've attempted to understand the thinking and philosophy of Japanese programmers in the 80's and 90's, and I'm just at a complete loss. I know there are factors keeping them from optimizing and fine tuning every little thing, but as a programmer and people that I known as programmers - there's this idea, this desire, this drive - that you want to create the best/fastest/whatever code possible; you want to push something to its limits. I guess that's a cultural thing and that's not what motivated most Japanese programmers at the time (with exceptions of course. There are always exceptions). 

 I read an interview with one of the guys that worked with Nintendo to get 3D on the SNES (originally meant for NES - the MARIO chip), and how he ended up moving to Japan and working directly with Nintendo programmers and producers for a number of years. He mentioned that game developers, like Miyamoto, would often take a game back to ground zero - many times during its development. If that was the case, I can see how optimizing stuff would be a waste of time during the development cycle. But to me, that shows that the producers were simply dictating to the programmers rather than working with them. Like I said, I really don't know.

I don't have the time (or interest) to write a long article to try to explain the history and the different development philosophies over the last 30 years ... but if you hang around the right bars surrounding GDC or E3 you'll probably find some old-timer to tell you about the realities of the industry.

Most programmers like a beer, and free beer definitely helps lubricate a discussion! :wink:

With your personal passions and capabilities, a big company would put you on the Engine team, where your talents would be used best.

In a small company you'd probably be a lead-programmer.

Either way ... you'll find that it's usually not cost-effective to over-optimize things, no matter how programmatically "beautiful" it is.

Having enough experience to know where to draw that line is something that usually comes with time ... and with working too many late nights in a row in order to hit a deadline.

When you're an amateur (or retired), then you get the freedom to do things however you like, and to spend as much time as needed to wring every-last-cycle out of a particular piece of code. As you already know, it's fun!  :)


Yeah, it's bad. Not just that, but the Hsync routine is a mess as well. I'm surprised this game isn't in perma slowdown.

And that's kind of the point ... in a lot of companies, "not-actually-causing-a-problem" really is "good-enough" when it comes to shipping a project.

When if comes to hitting a deadline, it's often cheaper-and-easier to just remove an enemy sprite or a background effect, rather than get a programmer to rewrite their code to make it faster.

Not all programmers are "great" ... and sometimes you'll find a "really-not-great" one on a team, particularly in the larger teams that some of the Japanese developers used.

Black Tiger

  • Hero Member
  • *****
  • Posts: 11242
Re: Some audio stuffs
« Reply #25 on: November 06, 2015, 07:03:20 AM »
Considering the reception the game has enjoyed (including being technically impressive to most people), Air Zonk really was good enough as it is. But it's fun to imagine what could be possible on PCE if a team really pushed the hardware efficiently.
http://www.superpcenginegrafx.net/forum

Active and drama free PC Engine forum

touko

  • Hero Member
  • *****
  • Posts: 953
Re: Some audio stuffs
« Reply #26 on: November 06, 2015, 07:41:06 AM »
@elmer: you're right, and i agree with you ..
But the code that bonk showed us, is really a pure shit, even with a deadline and commercial obligations,the reality is here .

Quote
Air Zonk really was good enough as it is
Of course, and it's the impressive parts IMO, nobody has thinked, how the code was bad when they were playing with this game(in fact it's just the opposite),i'am really surprised by the amateurism .
« Last Edit: November 06, 2015, 08:04:59 AM by touko »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Some audio stuffs
« Reply #27 on: November 06, 2015, 08:17:03 AM »
I don't think my XM PCM engine should really be compared to the average PCE game sound engine. Not that what I've done is amazing (it's not; anyone who can count cycles and optimize could do this - there's nothing revolutionary in my approach), it's just really tightly optimized. It looks more complicated that it is, in the source code, because of how it is made compatible for hucards - and PCEAS makes relocatable code a pain (this is where an intermediate object format would be great - linker). But it's just self-modifying code (nothing some PCECD games didn't do).


Quote
When you're an amateur (or retired), then you get the freedom to do things however you like, and to spend as much time as needed to wring every-last-cycle out of a particular piece of code. As you already know, it's fun!  :)

 I think that's one of the really fun things about coding on these old consoles. Seeing what they could really do. I think it's safe to say that the most popular systems of their era, tend to have thee examples of games that push the system just because of the whole dynamic of competing developers, pushing that bar. Maybe the other half of coding for these old consoles is just to put out something people will want and play. Maybe even fulfilling that childhood dream of make of game for your favorite system. But the PC-Engine is kind of a gold mine for exploring what can be done with it. Sometimes the approaches are extreme, but it's still fun. 

Quote
Having enough experience to know where to draw that line is something that usually comes with time ... and with working too many late nights in a row in order to hit a deadline.

 I always try to keep that in mind. It's all too easy to criticize after the fact. But there is always that part of me that feels; if you going to create something, present something, people are only going to see the end result. You can't go back fix it after the fact. And no amount of excuses (valid or not) will ever change the experience and impression of that presentation - what people got out of it. Trying to get a feel for where to draw that line, is difficult in my opinion. Especially when you can see nothing but promise and capability. Not just with coding, but with any sort of creation (literary works, art, music, etc). Finding balance with personal creations and being part of a team or company that sets restraints or limitations - it never leaves a completely satisfying feeling. I guess that's where hobbies are supposed to come in and fill that gap?

Quote
When if comes to hitting a deadline, it's often cheaper-and-easier to just remove an enemy sprite or a background effect, rather than get a programmer to rewrite their code to make it faster.

Sometimes, there are examples where companies should have taken that approach - lol. Instead, games flickered beyond belief or were plagued with slowdown (no console in specific). To me, that's a higher level design decision - the producer or managers ultimate responsibility.

Quote
But the code that bonk showed us, is really a pure shit, even with a deadline and commercial obligations,the reality is here .
Yeah. I try to limit my criticisms to stuff that's more on the extreme side of things. For PCE, it's usually sprite optimization - or rather approaching the system like an arcade machine with lots of sprite pixel line bandwidth.

Quote
Most programmers like a beer, and free beer definitely helps lubricate a discussion! :wink:
I don't know anyone in real life that codes. And if I did, it probably wouldn't be for old consoles. A beer and talking shop sounds great!
« Last Edit: November 06, 2015, 08:18:51 AM by Bonknuts »

ccovell

  • Hero Member
  • *****
  • Posts: 2245
Re: Some audio stuffs
« Reply #28 on: November 06, 2015, 11:30:33 AM »
Touko, this should give you an idea.... ;_;

Code: [Select]
    phy
    phx
    pha
 ...
    ply
    rti

 This is just the intro and extro code (TIMER routine). It's ridiculous because none of that overhead is needed for the DDA streaming part. And yet, there it is.

This looks to me like he's trying his darndest to make the game crash-proof in all situations -- for example, if you store MPR shadows somewhere upon interrupt, they could get overwritten when a second interrupt happens.  MPRs on the stack might be the fastest way when you have 2 or more simultaneous asynchronous interrupts going on.  (Although I didn't look at the rest of the Air Zonk code, so I dunno...)

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Some audio stuffs
« Reply #29 on: November 06, 2015, 01:37:53 PM »
I don't think it's testing for crashes (stack overflow). There's an internal state flag that prevents the routine from being called again, once CLI is executed inside it. So it can't be called inside itself. 

It's mapping banks for the main music routine to use. It's definitely a lot of banks. Maybe some of the samples are there as well (it doesn't have a lot of samples in the game - maybe it fits within 16k of that block). But it's definitely a large block map procedure.

 But my point is that the music routine only needs that support (banks) at the most - twice per frame. I.e. the music engine might run a song at 76hz instead of 60hz so you'll get a double call in a single frame once in a while. But that overhead is being called 116.7 times per frame, since the DDA routine is also using the timer interrupt. All they needed to do what prioritize for the DDA and map what's needed for what needs it, when it needs it. On the one or two instances it happens per frame, then map in that support.

 It's only one sample stream playing at a time. You only need to map in one bank for that. Maybe two if the tiny DDA routine really needs to be at $4000, but it should have been able to fit into the last bank. I dunno - priority and all that sort of thing.