Jump to content
IGNORED

NewColeco's Tiny Music


Recommended Posts

Hello everyone!

 

In 2018, I was working on a way to add music data as small as possible in my future projects without typing each note as a frequency and a volume effect. As a bonus, I've also considered to add vibrato and arpeggio support which sure increase the code size but do provide a richer sound experience.

 

To achieve this, I've simply extended the CV BIOS sound format by using its sound type 4 which is just a call to a routine. The routine is reading differently the sound data as my proposed new tiny sound format which reduces to (almost) 1 byte each note. I've coded this routine based on my needs and the way I compose music. Some details are written in the "sndtiny.asm" source file, and you are invited to look and modify the data in "snddata.asm" to figure out by yourself how the notes are coded.

 

The way I code music in my projects in based on CV BIOS sound format, the channels 0 and 3 are working together to play NOISE and BASS notes in a loop, these channels are not affected by this new format. The channels 1 and 2 are the melody channels and those do benefit from this new format by quite a lot for long music composition.

 

I have trouble to make this new sound format work with my music_update routine, so I'm also considering to write a more stable music sequencer in the future.

 

TINYMUSIC.thumb.PNG.4db383b16c9f24d9c2d9fba7adc5daea.PNG

 

The source code is entirely in assembly code and uses keywords only used by tniasm assembly cross-compiler. But it can be easily adapted to be compiled by other cross-compilers.

 

Version 0.1 Alpha TINYMUSIC.ZIP

Version 0.5 Alpha (bugfix) sndtiny.zip

Edited by newcoleco
  • Like 6
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Fixed an out-of-sync issue by simply make sure the duration counter in the init sound routine is reset to zero before trying to play any note.

 

Version 0.3 Alpha (just the tiny sounds routines again) sndtiny.zip

 

This version seems stable enough to try adapting part (about 5K data) of my compositions to tiny sounds format. I've selected the hardest one to adapt which is the elaborated Commando Chiptune music. There will be differences in the sounds quality of course but it should be close enough. And since I keep the bass and drum sounds data as is from the original composition, only the melody will be affected by this experiment. And, because of all these notes with arpeggio everywhere that were coded into multiple sounds swept codes for each note, tiny sounds format will make a big difference in size, like saving 20 or more bytes per 12 cycles duration notes. The size of the tiny sounds routines should be worth it right at the start of the Commando music.

 

To be continued...

Link to comment
Share on other sites

On 8/8/2019 at 3:03 AM, Mike Harris said:

I don't suppose you could create a simple interface that you type in a series of notes from some sheet music or a simple tune then it outputs compileable assembly code...

Just checking.

 

Music and Sound effects seem to be the hardest part of Coleco programing.

 

One step at a time - I'm getting closer to a stable sounds player with vibrato and arpeggio support.

 

This is just a spark, an idea of routines based on my way to compose music with a bonus of data optimization.

 

My goal is to code something stable I will use myself to compose even more music in the future.

 

And if there is any interest in using this experimental sounds format to compose musics, I'm sure talented programmers will figure out a way to make it easier to use.


 

  • Thanks 1
Link to comment
Share on other sites

8 hours ago, Mike Harris said:

My real fantasy would be if someone had the file and sound format to Video Tunes so we could use that to compose and retrieve the logic in Assembly.

There is a guy on Youtube named Steve Simpson that says he programed Video Tunes and I have reached out to him with zero success.

 

I have no idea what is Video Tunes.

Link to comment
Share on other sites

34 minutes ago, newcoleco said:

I have no idea what is Video Tunes.

LOL

 

It's an ADAM program that allows you to compose music, save it and I think print out the sheet music but don't quote me on that.

Graphics I think I have mastered.
Sounds and Music is still a mystery.
Just waiting on Tony Cruise's next two programing videos which is supposed to explain sound and music.

 

Edited by Mike Harris
Link to comment
Share on other sites

7 hours ago, Mike Harris said:

LOL

 

It's an ADAM program that allows you to compose music, save it and I think print out the sheet music but don't quote me on that.

Graphics I think I have mastered.
Sounds and Music is still a mystery.
Just waiting on Tony Cruise's next two programing videos which is supposed to explain sound and music.

 

Code now working for all three platforms i.e Colecovision, MSX and Spectravideo, article complete, just need to get a break from family stuff to actually record it :)

Link to comment
Share on other sites

15 hours ago, Tony Cruise said:

Code now working for all three platforms i.e Colecovision, MSX and Spectravideo, article complete, just need to get a break from family stuff to actually record it :)

 

You are fast!

 

Meanwhile, after hours of work, I've finally fixed a special tiny sounds routine bug and converted (most of) my ColecoVision Commando music based into tiny sounds. It sounds similar to the original without some nuances only possible by coding every notes by hand.

 

More than half the data size was saved by using this new format.

 

Bugfix : Removed the unneeded RESET " (ix+7),0 " that was stopping the special code 3 to play fully if the duration was more than 1 unit of time. This is important for the special drum code 0xfe and the freq and volume swept code 0x03 (see CV BIOS sound format).

 

Music Commando (src) with updated tiny sounds routines TinyMusic - Commando - src.zip

Music Commando (bin) both original and tiny sounds versions : TinyMusic - Commando - bin.zip

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

Pretty damn good....

Just as a viewer from the outside looking in...
 

Can that be adapted to a working game or does it take the entire processing power of the Colecovision?

I can pretty much guarantee you that not one of the original developers of the Colecovision would have ever dreamed this was possible.

Can you imagine if this kind of music came out from the beggining.

Coleco would have dominated the market.

Link to comment
Share on other sites

3 hours ago, Mike Harris said:

Pretty damn good....

Just as a viewer from the outside looking in...
 

Can that be adapted to a working game or does it take the entire processing power of the Colecovision?

I can pretty much guarantee you that not one of the original developers of the Colecovision would have ever dreamed this was possible.

Can you imagine if this kind of music came out from the beggining.

Coleco would have dominated the market.

Thank you!

 

Beside decoding the data written in the new format I've invented, and using a little bit of RAM to store pointers and instrument codes, these sounds are played by the ColecoVision BIOS sounds routine. Therefore, this doesn't use that much extra CPU power than regular CV sounds. By exploiting the BIOS power, I was able to plugin my routines and avoid adding too much codes in the ROM. All the sounds priorities and effects are for the most part from within the BIOS. 

 

In other words, this could have been implemented and used back in the 80s without a doubt.

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

  • 1 year later...
  • 4 weeks later...

I also am looking for a way to play back TinyMusic format in C.  Amy gave me the awesome music for Monster Bash but only in TinyMusic so i can save as much rom space as possible.  Anyone have a example on how to embed TinyMusic asm or any asm into a C project and how to call it?  I'm not a asm coder at all sadly. just C.  I'm looking to start up on Monster Bash again so i can get it done. I just need to get the music in the game and then get a few more k back from my sprites to leave room for level 3 and i'm done.

 

Please any info on how to run TinyMusic in C, let me know.  

 

P.S. Hope everyone has been doing well. it's been a while since I posted here.

  • Like 1
Link to comment
Share on other sites

12 hours ago, RKGames said:

I also am looking for a way to play back TinyMusic format in C.  Amy gave me the awesome music for Monster Bash but only in TinyMusic so i can save as much rom space as possible.  Anyone have a example on how to embed TinyMusic asm or any asm into a C project and how to call it?  I'm not a asm coder at all sadly. just C.  I'm looking to start up on Monster Bash again so i can get it done. I just need to get the music in the game and then get a few more k back from my sprites to leave room for level 3 and i'm done.

 

Please any info on how to run TinyMusic in C, let me know.  

 

P.S. Hope everyone has been doing well. it's been a while since I posted here.

Great to have you back and awesome news about Monster Bash.

  • Like 1
Link to comment
Share on other sites

If you're using SDCC and don't need to pass arguments, you can just mark assembly functions as extern (or just provide a void declaration) and call them directly. The assembly function needs to start with an underscore and using two colons will mark it global:

// C declaration:
void myfunct();

...

// call it
myfunct();

---

; asm side
_myfunct::
  ; do asm instructions here...

If the naming isn't appropriate or you can't change the assembly code, you can create inline assembly wrapper functions. 

void callmusicplayer() {
__asm
  ; asm code goes here
  call tinyplayer
__endasm;
}

It gets a little more complex if you need to pass arguments. You'll want to read the SDCC manual on calling conventions, but in the default mode everything is stored on the stack. I don't know tinymusic, but for instance if you need to pass a single unsigned char in a, you can do an extension of the above:

// arguments are pushed to the stack right-to-left, then the return address
// be careful when popping as the default C code will
// expect to clean up the stack... it may be safer
// to just move it. As you get more advanced, look at
// the section on naked functions for better control.
void callmusicplayer(unsigned char arg) {
__asm
  ; asm code goes here
  ld hl,#2   ; offset of arg on the stack (after return adr)
  add hl,sp  ; get the final address
  mov a,(hl) ; read the byte into accumulator
  call tinyplayer
__endasm;
}

There may be a quicker way to access the value, Z80 isn't my native tongue. ;)

 

Hopefully that gets you started.

 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Dude!  Thanks Tursi, i'll start messing with that tonight and keep the group posted in the next day or so!  I've been spending some time over the last week cleaning up some of the old code and got a little more rom space back, i have 7k free know to cram in level 3, music and simple title screen.  i want to see if i can get myself to about 8 or 9k free ideally before adding those but will again keep everyone posted.

 

Also, any chance there is a simple and super fast sprite X flip option I can use?  Half the sprites in the game are wasted to mirroring frames (Dracula walking left with 3 colors and then Right for all the same frames). I could literally reduce the game size almost by half if the coleco is capable of flipping sprites fast enough.  if a function in the c library exists, or if someone can show me how to use a asm version to hook into c, that might be cool to?!

 

Take care

Russ

Link to comment
Share on other sites

There is a flip sprite horizontal and or vertical in the library but it only works on 8x8 sprites. To flip the 16x16 sprites you have to flip the 4 8x8 sections of the 16x16 sprite separately. I was fooling with it and was unhappy with it.

 

I found it easier to just load a new pattern into the sprite definition on the fly.

 

You can make it seemless if you want to by using 2 different alternating sprites for odd or even frames.

 

i use a game counter 0-9  (10 total frames) to organize when things update.

On the even frames (0,2,4,6,8) use sprite pattern 0 & redraw the pattern in 1 once you swap 

On the odd frames (1,3,5,7,9) use sprite pattern 1 & redraw the pattern in 0 once you swap 

 

example. bat can use sprite pattern 0 or sprite pattern 1 depending on odd or even frame.

if bat is currently using sprite pattern 0 on and even frame then you can change the pattern in sprite pattern 1 without if being notice.

then on the odd frame (game loop counter )  you use pattern 1 and can replace the pattern in sprite pattern 0

 

you can also just replace the current sprite directly but you might notice glitches because it redraws the sprite pattern directly on screen. Sometimes its unnoticeable.

 

here is the code:  (1*32)  is sprite 1     (0*32) is sprite 0   and 32 bytes of data blocks

 

put_vram (sprtab+(1*32),upperbody,32);

 

Here is the 32 byte sprite data to replace the pattern with: Obviously replace the sprite data with your sprite data.

 

const byte upperbody[]=
{
0xC7,0xC7,0xC7,0x87,0x07,0x07,0x07,0x07,
0x07,0x07,0x06,0x0C,0x0C,0x40,0x00,0x00,
0xF0,0xF0,0xF0,0xF8,0xF8,0xF8,0x78,0x3C,
0x1C,0x0E,0x0E,0x0C,0x0C,0x40,0x20,0x00
};

 

 

 

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...