Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 5th Nov 2014 14:16 Edited at: 7th Nov 2014 02:59
After looking at jims examples of the new sound commands... i decided to try writting a simple mml player.

for now it only uses the 2 instruments
-drumkit
-piano

i am working on the export mml from midi code right now but for fun...try changing the play statements to a new song.

commands:

try making a new song...

here is the song included with it.


for those that dont know what mml(music macro language) is it can be referenced here:
http://en.wikipedia.org/wiki/Music_Macro_Language

not all commands are coded yet and i may do a spin off to allow balance change to go with it.


edit: Nov 6,2014 (fixed vol/balance)
This is the last update for the mml player: use it to see how a simple music sequencer could be made and how to stream music from it.

Attachments

Login to view attachments
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 5th Nov 2014 23:26
Well done! Works well.

The format is not very easy to read! (or write!)

How about a little collaboration?

-- Jim - When is there going to be a release?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Nov 2014 00:39 Edited at: 6th Nov 2014 00:48
Quote: "How about a little collaboration?"
sure!

Are you familiar with mml at all? it was used even with Qbasic for ms dos but was only beeps...lol! This also did not posses the ability to play multi tracks as this one does or change instruments.

i currently have my bigger music app porting the midi to these mml statements as it would be allot to write out manualy but could be done. Its the easiest way to convert your midi to play statements.

let me write a tutorial using it once i get the balance (stereo coded in) should be later tonight

edit: i also screwed up the lengths... in its current state it will not accept cdefgab without a length written with it and an octave specified,and tempo... doh! let me fix that asap

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Nov 2014 02:26 Edited at: 7th Nov 2014 02:43
ok turns out i cant get balance to work at all. Same as pitch using my current samples.

I wonder if you need a stereo sample in order to change balance as these are mono samples.

I also wonder if it needs to be a specific rate to work properly for frequency changing also?

Anyways here is the updated player. Now has 3 instruments.

1=piano
49=strings
128 or 0 =drumkit

edit: attachment removed

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Nov 2014 02:39 Edited at: 6th Nov 2014 02:46
ok @jim


So you have a total of 16 channels. Only one tone can be played per channel at a time. Examine the code above and notice ":" symbol. This changes what channel your writting music on. Now notice the "@" symbol. This is to change that channels instrument.

By default it now will have a tempo of 60 if you do not specify. But if you want to change it type "T120" or whatever you want to set the beats per min.

"O" sets the octave which is coded as 1 to 6 (6)being the highest tones.

Notes can be written like this:
CDEFGAB

or this:
C#EF-GB#AD-

or with lengths which i recommend using:
A16B16D32A32

length sizes:
(grabbed from code to explain sizes using note A for example)
"A1." if actual#=1.5 then length=48 //greatest length
"A1" if actual#=1.0 then length=32 (represents a whole note)
"A2." if actual#=2.5 then length=24
"A2" if actual#=2.0 then length=16
"A4." if actual#=4.5 then length=12
"A4" if actual#=4.0 then length=8 (1/4th note which = 1 beat per min)
"A8." if actual#=8.5 then length=6
"A8" if actual#=8.0 then length=4
"A16" if actual#=16.0 then length=2
"A32" if actual#=32.0 then length=1 //smallest

basicaly a dot says extend the time of the note by an extra 1/2

Try it out... and i will see if i can figure out this balance and pitch stuff.

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 6th Nov 2014 04:07
Brings back memories of the music language on the Radio Shack Color Computer. Those were fun times.

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Nov 2014 04:17 Edited at: 6th Nov 2014 04:17
oh yeah!...lol TRS-80 COCO 2 64k is what i grew up with

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Nov 2014 10:02
More comments later, but:

The balance certainly works on the PC. Check my little examples. Mono is fine.

Tuning should be a case of playing the note (or altering it) so that an increase of a semitone is approximately one twelfth. However, general practice uses a log scale to compute this. See the table low down here:

http://en.wikipedia.org/wiki/Equal_temperament

Note duration and how to handle sustain portions of the waveform I';; get back to later!

-- Jim - When is there going to be a release?
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Nov 2014 11:58 Edited at: 6th Nov 2014 11:59
You've done really well with this. A few points:

As far as I can see from looking at your code you are NOT using the new sound commands, which might explain why pitch and balance don't work!

The new stuff works with a Sound Instance. This is returned from PlaySound()
The commands don't work on the original ID of the loaded sound.

soundInstance as integer

soundInstance = Playsound(MySoundID, Volume, 0)

You then use SetSoundInstanceRate() on the instance, not the original

Here's the help on PlaySound():

Play the sound previously loaded into the specified sound number. This command can be called multiple times for the same sound ID and it will start multiple copies of that sound playing as instances. The command will return an instance ID that can be used to interact with this instance whilst it is still playing. When an instance stops playing then it is automatically deleted and can no longer be referenced. By default the sound is not looped.

Notice that the instance is dynamic and NOT valid unless the sound is actually playing.

Consequently a sound event that will be modified has to be a structure containing at least the sound ID and the instance:

type tNote
fID as integer
fInstance as integer
...
endtype

To play a sound at an altered pitch and pan is a three stage event:

1) Call Playsound() and set fInstance to the result
2) Call SetSoundRate() using the fInstance and the modified rate
3) Call SetSoundBalance() using fInstance and a float value from -1 to +1

Later, before trying to modify a sound it's obviously important to check if it's actually playing, using GetSoundInstancePlaying(fInstance)

There's a good reason for all of this: you can play multiple instances of one sound. But it does make it a little complicated to handle well.

-- Jim - When is there going to be a release?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 6th Nov 2014 14:31
oh thats how the new commands work...

i will update this tonight. I need to look at inventing some mml code to handle balance and pitch. I will also update my qmidistudio app to assist making the playstatements easier.

thanks allot jim.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Nov 2014 23:36 Edited at: 6th Nov 2014 23:38
Here's my take on this. It's NOT a criticism, just a discussion.

MML was designed for stone-age computers that largely only went beep. It's appallingly difficult to write, impossible to read easily, inflexibly linear, and was instantly superseded by the music possibilities on the Atari and Amiga. As a playback format it is very limited compared to the Midi format which still persists and drives a lot of music that we hear.

I can take a bit of manuscript paper and write a fugue or anything else. Since the middle ages this has been a way of notating music. I can still do that, and on the computer, using, for example Sibelius or Notion.

But people also use the system where you draw a block on a virtual keyboard tipped up vertically on the left.

People do not write a densely-packed string of letters and numbers. You simply cannot visualise it. Compared to a Midi track it's verbose and actually consumes more memory than it needs to. It is simply not a good way of entering music, and probably an inefficient way of storing it.

Simply writing a Midi player in AppGameKit is pointless: there are loads of good apps to do this. So what is the purpose?

As I see it, people want to add sound in a rich way to their game. That may include music. They want to do this because they do not want to use pre-recorded tracks. But that playback must be very efficient or their pretty sprite moves will slow to a halt.

Music is just a part of it. Music and ambient sound could adapt to the context, as it does in many AAA games. This needs to be programmable, not just a track, although it could use tracks. It needs to be interactive. It needs to be low-cost in terms of processor.

The possibilities of sound are always underestimated in game terms. Could we make some magic????

-- Jim - When is there going to be a release?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 7th Nov 2014 01:48 Edited at: 7th Nov 2014 01:49
yeah mml is very tough to compile a complete song... thats for sure..... not very useful either but it is neat to see it in text and hear it play back. Just not practical.

i will dump the mml and see if i can load some midi a different way for testing out the sound commands.

i will post again once i have something using the new sound commands.... but yes...mml is very terrible indeed.

lets see if i can come up with a midi sequencer at the end of this that will beat this project

http://forum.thegamecreators.com/?m=forum_view&t=202017&b=49
and i see jim that you have seen this thread in the past.

time to upgrade the player/editor with some new snd commands and go multiplatform

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 7th Nov 2014 02:32
yup! pitch bending and balance changing is now working very well.
turns out volume fading now works too! lol

I will try to come up with a more memory efficient cycle and then start working on a new midi sequencer.

if anyone wants to mess around with it...by all means here it is.


edit: 1 sec i will just post it on the top (first post)

SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 7th Nov 2014 15:07
@Jim... do you have any experience modifying a sound memblock ?

what would be really cool is if it was possible to come up with a sound font. A programmable sound to play back as an instrument.

this would be a much smaller foot print on the size of a music tracker if it used sound fonts instead of recorded sound files for instruments.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 7th Nov 2014 19:11 Edited at: 7th Nov 2014 19:12
Boringly long post follows:

I guess what you mean is algorithmically generating the instruments at run time. This would probably mean creating an analogue synthesiser. (Percussion might as well be samples, because they tend to be short).

The central problem is that to make anything decent you need quite a few virtual oscillators and envelope shaping. This takes some fairly heavy maths to do well. You need various noise generators, progressive ramping and all sorts of stuff.

As always - to do this on a PC or Mac would be possible using native code in C++ or Pascal, but I really do doubt if it's possible on average phone number 99876 or whatever, in a byte-code interpreter. I think the bottom line is that if the widget you're running on is powerful enough to do this, it probably has enough memory to use a sample bank anyway.

For a quick look at the issues:

http://www.youtube.com/watch?v=YsZKvLnf7wU

Csound is the premier go-to for electronic music, but do you think your average AppGameKit user could cope with this?:

http://csound.github.io/docs/manual/PrefaceWhatsNew.html

Personally, I would stop worrying about advanced sound synthesis for AppGameKit, because the howls of protest when it doesn't work on x, y, z will be louder than the music. Instead, having a very low CPU-cost system for people to add in T1 would be good for games. AppGameKit tends to be very graphics-orientated and from my observations people tend to spray thousands of sprites around the place and then wonder why their frame-rate has dropped. There are some quite naive users here who think they can make a fortune with yet another Flappy Birds clone. Dream on.

AGK is not and never will be a music engine.

What is more interesting for me is generating music from algorithms. I'm not at all well at the moment, so I can't really do the day-job, so it's a chance to play. So I'll spend a few relaxed hours looking at a neat generation system that will adapt on-the-fly to mood.

A memblock is a waveform in a memory buffer, so, yes I can do this. But much more interesting for me is an adaptive system.

I'm actually a writer, although I do have a software company! Many of you guys are far more equipped to do the maths than I am...

-- Jim - When is there going to be a release?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 8th Nov 2014 15:35 Edited at: 8th Nov 2014 15:37
hey... thanks for those links. Its very interesting to learn about that stuff and i see its massivly complicated. Your right and i think i will just stick with modifying recorded sound tones.

-volume
-balance
-rate

thats it

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Nov 2014 13:40
I just found this very good tutorial on sound synthesis for those who are interested:

http://beausievers.com/synth/synthbasics/

-- Jim - When is there going to be a release?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 10th Nov 2014 19:03 Edited at: 12th Nov 2014 03:28
edit:removed.... but look for this on ouya as part of an arcade pack im putting together!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Nov 2014 19:09
SM3D - You see what I mean about adapting the music to what's going on?

You don't need to use your entire sample range for a game - just the notes that are needed for that instrument.

-- Jim - When is there going to be a release?
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 10th Nov 2014 19:40 Edited at: 12th Nov 2014 03:28
edit: file removed ...

Login to post a reply

Server time is: 2024-11-25 11:31:27
Your offset time is: 2024-11-25 11:31:27