Jump to content
IGNORED

Playing PCM samples from cart


Nop90

Recommended Posts

In Nutmeg, my entry for the Lynx competition, I need to play a PCM sample without stopping the game (like I do in Xump). This is a feature in HandyMusic that plays the sample directly from the cart using the interrupt linked to COUNTER3.

 

Karri ported the HandyMusic code to CC65 (not yet public I think), but I already started my game using Chiper, so I decided to adapt the playPCM code to be in a standalone file and be somehow compatible with Chipper.

 

All the credits for the code goes to @TailChao for HandyMusic and to @karri for it's CC65 port. I only changed some registers to play on Channel3 (that I prefer for SFX) and to use the COUNTER5 that is not used by chipper (the same I did to make the fadein and fadeout compatible with Chipper)

 

To use it from C you need to declare three functions:

 

void __near__ __fastcall__ openn (int); // selects the SAMPLE File in the CART directory
void playPCMSample(void);
void stopPCMSample(void);

 

than you can play the sample with:

 

stopPCMSample(); // use this if you need reading cart while playing
openn((int)&SAMPLE0_FILENR);
playPCMSample();

the stopPCMSample() call is not strictly needed if you avoid playing a second sample (or trying to read something else from the cart) while the sample is playing.

 

the PCM sound needs to be a raw streem of 8Khz 8bit signed samples.

 

The code doesn't interact with the Chipper driver: simply avoid to play something in channel 3 with Chipper if yo wan to play a PCM sample, and everything should be ok.

 

Enjoy your coding.

 

 

 

 

playpcm.zip

Edited by Nop90
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...

Found a problem playing samples with a background music with short notes lenght (less than 30 in chipper). The music (playing  on channel 0,1 and 2) slows down for some time when the sample plays on channel 3. It doesn't seem a problem with the counters.

 

Trying to figure out why it hapens found a couple of minor bugs in the asm code. But still haven't found the cause of the main problem.

 

At the moment minimized the effect setting the lowest priority to the PCM player interrupt.

 

I'll post an updated version when I fix the problem.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...