Author Topic: Struggling with CPC sound queues... Cannot find examples  (Read 216 times)

0 Members and 1 Guest are viewing this topic.

Offline Fabrizio

  • CPC464
  • **
  • Posts: 19
  • Country: fr
  • Liked: 3
Hi everyone!

I am trying to add a couple of simple short sounds to my game CROSS CHASE, which is written in C.

I have tried use CPC sound queues in Assembly but I only get a random crackling sounds.

It is not clear to me how I should use the queues. I have found documentation but I cannot get a simple working example.


I need a short simple one tone sound and a short simple noise sound.

For example, how do I select the noise generator? How do I select non-noise?

I have tried:

void __explosion_sound(void)
{
#asm
   EXTERN firmware


   jr explosion_code
   
   explosion_data:
      defb 8,0,0,142,0,150,12,20,200 
   
   explosion_code:   
      ld hl,explosion_data
      call firmware
      defw 0xbcaa   
#endasm      
}





Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.148
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 1968
Re: Struggling with CPC sound queues... Cannot find examples
« Reply #1 on: 11:10, 10 October 17 »
I will make an example.

But first I will need to understand it because I've never used it  :D
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Fabrizio

  • CPC464
  • **
  • Posts: 19
  • Country: fr
  • Liked: 3
Re: Struggling with CPC sound queues... Cannot find examples
« Reply #2 on: 12:20, 10 October 17 »
The reason why my code does not work comes probably from the fact that it has to work as embedded Assembly in C and then it has to be compiled with Z88DK.
That is why I am using an interposer ("firmware") to access the rom routines.
Maybe that is not enough. Maybe I need to disable interrupts... I have no idea..
 
I don't mind using other routines. I only need a couple of simple short sounds. I don't mind if the sound are not asynchronous because they are supposed to be short. I am open to other solutions. Can't I write straight on the sound chip registers as I do for the MSX?
« Last Edit: 12:27, 10 October 17 by Fabrizio »

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 726
  • Liked: 289
Re: Struggling with CPC sound queues... Cannot find examples
« Reply #3 on: 22:30, 12 October 17 »

The firmware needs the interrupts to be enabled to use the sound queues (because they're literally interrupt driven code) so that's definitely not the issue. I don't have an assembly example (I'd usually bypass them in that case) but could probably knock one up at the weekend if Kev doesn't have time. One of the little "gotchas" when going via the firmware is that the parameter order doesn't match that of BASIC's SOUND command.


If you don't want/need the queueing capability then you can just talk straight to the AY yourself, but alas it's not quite as easy as writing to a port because the AY hangs off the back of the PPI. If you're happy with the firmware remaining active, you can just call MC SOUND REGISTER (&BD34) to squirt a value to one of the AY registers. If you'd rather avoid the firmware, then you have to go the slightly more circuituitous route for which there is probably an example somewhere on the wiki. Unless you actually call any of the firmware's audio routines I don't *think* it will matter that you bypass it (unlike with e.g. setting colours)

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.148
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 1968
Re: Struggling with CPC sound queues... Cannot find examples
« Reply #4 on: 14:18, 15 October 17 »
I am currently dissassembling the OS to get a better idea of how the firmware sound system works.

It has a queued of 4 'sounds' per channel. If sound is not held. The firmware will update it every 100hz.
Holding it silences the sound. Releasing it will restart the sound that is being played the - 'it will start exactly where it left off' is not quite correct. The waveform out of the AY will not be exact but it will replay from the exact volume/tone envelope position (provided it's not a hardware envelope that is).

You can request your event to be called as soon as they queue has an empty slot, so you can then fill it with more sounds. So in theory you can setup events in basic to fill the sound queue and keep it playing music and by queuing 4 at once you can keep it busy from basic.

The queues can be flushed per channel, or you can setup sounds and then request that both sounds are only played when both channels reach the same sound in the queue = 'rendezvous'.

It's a simplified 3 channel tracker effectively.

In theory it'd be possible to convert aks to firmware sound if you were crazy enough and get it playing back using firmware functions.

I'm making up a library that will be easy to use from z88dk and sdcc.


My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 726
  • Liked: 289
Re: Struggling with CPC sound queues... Cannot find examples
« Reply #5 on: 18:13, 15 October 17 »
I've always thought the advanced features of Locomotive Basic, such as the interrupt driven sound queues and other event handling were some of the great strengths of the machine for Basic programmers. It always surprises me how overlooked they seem to have been over the years.