Nop90 Posted July 6, 2019 Share Posted July 6, 2019 (edited) 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 July 6, 2019 by Nop90 2 1 Quote Link to comment Share on other sites More sharing options...
Nop90 Posted July 26, 2019 Author Share Posted July 26, 2019 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. Quote Link to comment Share on other sites More sharing options...
enthusi Posted July 26, 2019 Share Posted July 26, 2019 In Lacims Legacy my audio routine also restricts itself to three channels while samples are played back straight from cart. I currently update the music outside of the IRQ to avoid clashes. Quote Link to comment Share on other sites More sharing options...
Nop90 Posted July 26, 2019 Author Share Posted July 26, 2019 Seems I fixed it. Just need to make some more test. Quote Link to comment Share on other sites More sharing options...
Nop90 Posted July 27, 2019 Author Share Posted July 27, 2019 Yes, seems ok now.playpcm.zip 3 Quote Link to comment Share on other sites More sharing options...
Nop90 Posted July 27, 2019 Author Share Posted July 27, 2019 Found another side effect: when playing a sample the system timer goes faster. @karri when you implemented it, did you use time 5? Quote Link to comment Share on other sites More sharing options...
+karri Posted July 27, 2019 Share Posted July 27, 2019 Sounds like the system timer does not check its interrupt mask. A bug in cc65 libraries perhaps? The system time should use VBL interrupt. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.