Pently: a flexible, space-efficient NES music player

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

dougeff wrote:I find volume control to be one of the most important effects. Every channel, preferred.
Would four levels (1/4, 1/2, 3/4, full) be enough for this? Or is there a musical use case for more?
Also, down the road, ot would be nice if we had a library of instruments, so every musician doesn't have to reinvent the wheel (or piano-ish volume envelope, for example).
I agree. Compose with pentlyas and let's build one.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Pently music player is coming

Post by dougeff »

How would that correspond to Famitracker's volume column? Something like...

D-F = 100%
9-c = 75%
5-8 = 50%
1-4 = 25%
0 = off

??
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

That'd be about right: 4, 8, B, F.

The thing motivating the limit of 4 levels is that the NES CPU is slow at multiplying, and I don't want to introduce a bunch of 256-entry lookup tables to make it fast. So I plan to make an engineering tradeoff among control, ROM space, and CPU time.
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Pently music player is coming

Post by dougeff »

Oh good. I feel good about the new, improved Pently. It seems to be filling in the short-comings of other music drivers. I may try to use it in the future, for game development.

I'm not sure how sound effects will work with it, but I really haven't tried yet. It sounds like you've gotten it to work with your own games, so I guess I'll probably figure that out too, when I get to that point.

Edit...
NES CPU is slow at multiplying....compromise
Agreed.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

Sound effects work in almost exactly the same way as the drum track. Each drum is made of one or two sound effects. Or did you mean you haven't had a chance to understand how drums work either?
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Pently music player is coming

Post by dougeff »

Sorry, I mean game-generated sound events. Collect a coin = ding.
nesdoug.com -- blog/tutorial on programming for the NES
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

In musicseq.pently, make sfx ding on pulse. Then do this from the game code:

Code: Select all

  lda #PE_ding
  jsr pently_start_sound
(The "PE_" part stands for "Pently effect".)

Thread safety caution: Some people like to run the music engine in the NMI handler to avoid audible consequence of slowdown. If you call pently_update_sound in the NMI handler, don't also call Pently API functions in the main thread; that'll cause undefined behavior if it interrupts itself. Instead, add commands to a list in RAM that the NMI handler processes.
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: Pently music player is coming

Post by Hamtaro126 »

Is there a any possibility of ''Go to Track #n'' and ''Go to Previously Buffered Track'' effects for pently?

Makes things easier for full-on jingle effects, such as the ''Time Running Out'' jingle in mario games!
AKA SmilyMZX/AtariHacker.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

From the manual's description of pentlyconfig.inc:
If PENTLY_USE_ROW_CALLBACK is enabled, the main program must .export two callback functions: pently_row_callback and pently_dalsegno_callback. These are called before each row is processed and when a dalSegno or fine command is processed, respectively. They can be useful for synchronizing animations to music. For pently_dalsegno_callback, carry is clear at the end of a track or set if looping.
So turn it on and use pently_dalsegno_callback to know when to restart the music.

Do you want more details?
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: Pently music player is coming

Post by Hamtaro126 »

tepples wrote:Do you want more details?
Yes... That would help a lot if more details are added
AKA SmilyMZX/AtariHacker.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

  1. When you start the song for a level, save the song number of the song for the level in a variable.
  2. When you play a temporary song that ends, such as a fanfare that time is about to expire, do not save its song number.
  3. In pentlyconfig.inc, change PENTLY_USE_ROW_CALLBACK = 0 to PENTLY_USE_ROW_CALLBACK = 1.
  4. Create a subroutine in your main program called pently_row_callback that does nothing (that is, immediately executes the rts instruction). This is required because the same configuration option enables both pently_dalsegno_callback and pently_row_callback
  5. Create a subroutine in your main program called pently_dalsegno_callback, and .export this subroutine. If called while carry is clear, this means that the temporary song that ends, such as a fanfare that time is about to expire, has ended. In this case, it should load the song number from variable in step 1, and if it's a valid song number, call pently_play_music.
If this is not enough, then as I wrote in this post:
Please give us more details on your requests for "more details". What parts of the post did you understand, and what parts of the post did you not understand? If you are unable to express what parts of the posts you did and did not understand, I will have to break up the explanation into smaller posts, as if this were a chat room instead of a forum, and ask you whether you understood each part.
Or did you want me to actually write the code for you?
User avatar
Hamtaro126
Posts: 818
Joined: Thu Jan 19, 2006 5:08 pm

Re: Pently music player is coming

Post by Hamtaro126 »

So from what i gathered... Follow how the NES Mario engines originally does things:

-Make and use a subroutine for Main to handle the two music buffers, One for main songs, and one for event (effect) songs
-Then store the songs in one of two buffers, Restore back to the main song when the event (effect) song finishes

I think it is good enough from here if so...
AKA SmilyMZX/AtariHacker.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

Many free software licenses require the license to be reproduced in full in all copies, such as the MIT License (Expat variant) currently used for Pently. This is why the NES Classic Edition's front end includes several pages of "Legal Notices". But then it can afford to do so because it has half a gigabyte of NAND flash for the Linux kernel, emulator, and game ROMs. NES games distributed on Game Paks, on the other hand, are in the tens to hundreds of kilobytes and may not have enough space to store a viewer for the entire software license in the binary. So the MIT License (Expat variant) alone might not be the best choice, as it requires the notice to be reproduced in all copies. This has already caused problems for use of Pently in ROM hacks.

There are a few other non-copyleft licenses. Before Pently moved to Git, I had been using a variant of the GNU All-Permissive License changed to limit the credit requirement to source code:
Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved in all source code copies. This file is offered as-is, without any warranty.
My project templates and the game RHDE: Furniture Fight still use this license.

If we find it useful to go with a better-known license, I was considering switching to the license of zlib, which similarly requires the full notice only in source code and encourages but does not require credit in object code. This license is also used by the Allegro 5 library, and it carries forth the spirit of the "giftware" license used by Allegro 4.

As the only contributor so far, I have the right to make this license change unilaterally, but I'm opening this to others' input because I'm nice. So comment here or in bug 10.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

Channel volume control is checked into GitHub.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Pently music player is coming

Post by tepples »

Post Reply