Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Xeda112358 on February 06, 2012, 05:14:55 pm

Title: GraMusic (Grammer)
Post by: Xeda112358 on February 06, 2012, 05:14:55 pm
So I made this music player in Grammer >.> The download includes two quick samples. I'll be back in a few hours if anybody has questions :)
Title: Re: GraMusic (Grammer)
Post by: Yeong on February 06, 2012, 05:51:11 pm
It looks nice :o
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 06, 2012, 07:16:12 pm
Thanks :D And it interprets the data, too (it doesn't compile anything yet), and it still works quickly :) I found out that prgmTEST1 is a part of "Ode to Joy" and apparently I have a few notes off D:
Title: Re: GraMusic (Grammer)
Post by: Sorunome on February 07, 2012, 10:50:06 am
Looks cool! But why isn't this in the grammer section?
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 07, 2012, 02:16:11 pm
There isn't a Grammer section D: Also, apparently this still needs a bit of work >.> It works and I found it to work nicely, but it isn't overly amazing XD
Title: Re: GraMusic (Grammer)
Post by: Keoni29 on February 23, 2012, 05:31:36 pm
Geez lots of music software around these days. It'd be nice to have some games with music in them.
Title: Re: GraMusic (Grammer)
Post by: Yeong on February 23, 2012, 05:33:49 pm
Challenge accepted :P
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 23, 2012, 09:39:54 pm
O.O Usually it is difficult to do, but simple sound effects should not be hard :)
Title: Re: GraMusic (Grammer)
Post by: Sorunome on February 24, 2012, 04:57:07 am
There isn't a Grammer section D: Also, apparently this still needs a bit of work >.> It works and I found it to work nicely, but it isn't overly amazing XD
http://www.omnimaga.org/index.php?board=202.0
Title: Re: GraMusic (Grammer)
Post by: Stefan Bauwens on February 24, 2012, 05:18:05 am
There isn't a Grammer section D: Also, apparently this still needs a bit of work >.> It works and I found it to work nicely, but it isn't overly amazing XD
http://www.omnimaga.org/index.php?board=202.0
I think she meant like a grammer forum. ;)
Looks cool Xeda. I just can't tell of the screenshot how it sounds. :P
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 24, 2012, 06:47:02 am
:P Also, I was not sure if Grammer programs should be uploaded there or here :/
Title: Re: GraMusic (Grammer)
Post by: Keoni29 on February 24, 2012, 10:18:48 am
O.O Usually it is difficult to do, but simple sound effects should not be hard :)
No sfx aren't hard to implement indeed, but music is possible. (maybe not with grammer, but with ASM or even Axe it'd be possible.)
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 24, 2012, 10:25:37 am
Full background music would be pretty difficult as sound uses most of the CPU time. It would definitely work for simple games, but complicated games would be much slower :/ I hope somebody manages it, though! (As a note, the Grammer sound works about as fast as assembly) GraMusic sound does not work as fast as it could because it interprets the data instead of preparsing it :/
Title: Re: GraMusic (Grammer)
Post by: DJ Omnimaga on February 24, 2012, 10:42:57 am
Generally grammer projects goes in the calc projects and ideas section. There isn't a Grammer projects section yet due to the small amount of such project so far. Eventually there will most likely be one, though, like Axe.

This seems nice by the way. I wonder if Grammer music can be used in the very middle of a game in action?
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 24, 2012, 10:47:46 am
I'm sure somebody like Yeong could do it :D I have made sound at main menus before using a slower version of Grammer :]
Title: Re: GraMusic (Grammer)
Post by: DJ Omnimaga on February 24, 2012, 11:03:36 am
Ah that's nice. Were the sounds playing as small beeps like in Pyoro, though? Or were they full length notes not stopping when stuff is happening?
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 24, 2012, 11:05:54 am
Oh, just beeps, but I think I could get it to play notes pretty easily now. Before, I did it on a very old version of Grammer that had really crappy sound support. It might actually go well for back ground music in my checkers game since a lot of it is waiting for user input o.O
Title: Re: GraMusic (Grammer)
Post by: DJ Omnimaga on February 24, 2012, 11:10:04 am
Ah ok. I remember some Axe programs played full notes instead of beeps and despite the sound quality being lower it still sounded quite OK. It would really be nice to see a calc game with background music.
Title: Re: GraMusic (Grammer)
Post by: Keoni29 on February 24, 2012, 11:17:28 am
Can't we just bind a timer to the port so that the program doesn't freeze every time a note has to be played? Also, I made this a while ago:
www.youtube.com/watch?v=7kK_vRbiibc (no comments about my voice please :P)
It plays the sfx on another calc so that they won't cause the game to freeze for a while.
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on February 24, 2012, 02:23:19 pm
You cannot easily "bind a timer to the port" per se, but you can play notes at a set time interval based on the game loop. For example, if I do this for Checkers, I will let it play through music data one note at a time while waiting for a key press.
Title: Re: GraMusic (Grammer)
Post by: DJ Omnimaga on February 24, 2012, 02:34:24 pm
Can't we just bind a timer to the port so that the program doesn't freeze every time a note has to be played? Also, I made this a while ago:
www.youtube.com/watch?v=7kK_vRbiibc (no comments about my voice please :P)
It plays the sfx on another calc so that they won't cause the game to freeze for a while.
Yeah I remember that and it was great. Of course that wouldn't work for everyone, though, since not everyone can afford to buy a second calc, let alone carry two calcs to play a game. :P
Title: Re: GraMusic (Grammer)
Post by: Yeong on February 24, 2012, 06:14:51 pm
What I'll do is use one note as a "Pause".
(That's the way you can put music with MuseInc XD)
That way, music can "naturally" flow while the game is running.
If you make a song that has a continuous 32nd note or something (if the note is longer than that, make use of rests XD), it'll flow kinda nicely, imo,
However, the program should be fast enough X.o
Title: Re: GraMusic (Grammer)
Post by: DrDnar on March 11, 2012, 12:50:57 am
Can't we just bind a timer to the port so that the program doesn't freeze every time a note has to be played?
Sure. The the calculator totally has a southbridge (http://en.wikipedia.org/wiki/Southbridge_(computing)) that can handle DMA (http://en.wikipedia.org/wiki/Direct_memory_access). It even has a PCM (http://en.wikipedia.org/wiki/PCM) wave buffer.

OK, sarcasm aside, sound synthesis is difficult because it has to be done via pure bit banging (http://en.wikipedia.org/wiki/Bit_banging). You could set up a crystal timer interrupt to handle changing the port status at a fixed rate, but it will sound terribly out of tune. The reason is that the maximum frequency that you can get interrupts to fire at is 32768 Hz. As a result, you have to quantize the period of each note to intervals of 116384 of a second. The human ear can hear frequency distortions of less than 1%. With such a synthesis technique, the error from the correct frequency will begin to exceed 1% around middle C.

If you're wondering, the quantized frequency of a frequency fn quantized to a half-frequency of fs (here, 16384) is fq(fn, fs) = fs/round(fs/fn)

The ideal frequency of piano key m is fm(m) = 440 * 2^((m-49)/12)

The percent distortion for a particular note n quantized to a half-frequency fs is fe(n, fs) = (fq(fm(n), fs) - fm(n)) / fm(n)

Go ahead and graph this on your calculator and you'll see the graph cross the 1% line for the first time at G#3.

Incidentally, this is why even simple delay-loop based music sounds slightly distorted. It's not the fact that the frequencies will differ from the ideal by a small percentage, it's the fact that those percentages are all different that makes the music sound out-of-tune. (Also, the square waves take some of the blame.)
Title: Re: GraMusic (Grammer)
Post by: Yeong on March 18, 2012, 05:23:08 pm
any progress in here? :D
If it progress a bit, I'll add something in museinc that lets convert museinc appvar into gramusic format. :D
Title: Re: GraMusic (Grammer)
Post by: Xeda112358 on March 18, 2012, 05:31:06 pm
Actually, it might be better if I make this compatible with the MuseInc format >.>