Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Simple custom music with FX and beat - simple demonstration

    Creation share codes
    3
    4
    451
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sigixxx last edited by

      Hi,
      if someone would be interested in using some FX sounds or even beats in your custom music melodies instead of using poor "playNote", here is a simple code that demonstrates how this could be maybe possible.
      Please, use headphones for listening beats properly in the included sample.

      The source code is easy and short. As you could see, you would have a lot of processing time for additional "game processing" like drawing sprites and so on, because there is 0.4 sec sleep per cycle in which the program do nothing. This means that this could be used as a background music - with some normal sample of course :)

      The donwload code (when/if will be approved) is: 52DQ3MND58

      The basic princip is as follows:
      Instead of playing music tones with "playNote" function, you can play them with "playAudio" function. In "playAudio" you specify handle to fx sound - music instrument that will be used and the speed of playing. To play this fx sound in corresponding note/octave you can set the speed to appropriate value that corresponds to the note.
      Example:
      "Gijs De Mik/FX_Bleeps_01" fx sample is recorded as "A4" note with 440Hz frequency.
      If i want to play this fx sample as note B4(494Hz), i will simply play it more faster 494 /440 = 1.123 of original speed. That is it :)

      Please, take this just as an idea for experimenting with music possibilities in Fuze.

      The source code is bellow:

      /* 
      Project: BMusic
      Authos: Sigi (Mildik)
      
      This program demonstrates possibility of using FX sounds as instruments 
      in your custom melodies. Beats are also included but, please, 
      use headphones in order to hear them properly.
      
      Feel free to use this code as wish.
      */
      
      melodyGO =  "MRUY  UZYW  MRUW  UYWT  MUWY  YZYW  MTUW  WYWR            " //main melody
      melodyGO2 = "   FIMRMIFKMQMKFIMRMIFKMQMKFIMRMIFKMQMKFKMQMKFIMRMI       " //accompaniment melody
      
      //The following fx are used as instruments, you can test some others if you want
      hnd = loadAudio("Gijs De Mik/FX_Bleeps_01") //fx used in melody as instrument 1
      hnd2 = loadAudio("Gijs De Mik/FX_Bleeps_26") //fx used in melody as instrument 2
      hndB = loadAudio("Gijs De Mik/FX_BombDrop_01") //fx used in melody as beats
      playAudio(0, hnd, 1, 0.5, 0.3, 1) //testing
      print("Demonstration of custom music with some beats... \n")
      print("Please, use headphones in order to hear the sample properly")
      int mLen = len(melodyGO)
      int mInd = 0
      
      //-----MAIN LOOP-----
      loop
      	update()
      	sleep(0.4) //you have plenty of time to do some graphic stuffs
      	mInd = processMelody3(melodyGO, melodyGo2, mInd, 0.2) //processing melody
      	if (mInd >= mLen) then mInd = 0 endif
      repeat
      
      //--------------------------------
      //Function that process melody coded in string
      function processMelody3(ref mDat, ref mDat2, ref ind, vol2)
      	int i
      	int oldInd = ind
      	for i = 0 to 2 loop
      		val = 1
      		ind = oldInd
      		if (i) then while val and (val < 32) loop val = chrVal(mDat2[ind]) ind += 1 repeat 
      		else while val and (val < 32) loop val = chrVal(mDat[ind]) ind += 1 repeat endif
      		if (val > 64) then
      			val -= 65
      			if (i) then //for melody 2
      				playAudio(2, hndB, 1, 0.5, note2Freq(60 + val) / 440, 1) //beats
      				playNote(1, 4, note2Freq(60 + val + 96), 0.03, 50, 0.5)
      			else //for melody 1
      				playAudio(3, hnd2, 1, 0.5, note2Freq(60 + val) / 440, 1)
      				playAudio(4, hnd, 0.2, 0.5, note2Freq(60 + val - 12) / 440, 1)
      			endif
      		endif
      	repeat
      return ind
      
      1 Reply Last reply Reply Quote 1
      • S
        sigixxx last edited by sigixxx

        I have added second simple music track into this demo so now you can switch between track 1 and track 2 by pressing/holding 'A' or 'B' :)
        Again, please, use headphones in order to hear it properly.

        And i have forgot...
        If you want to use your own melodies you can use my app FuzeImporter to convert melodies written as notes in txt file into the coded text that is processed by "processMelody" function. This is what i am using in all my games.

        Example:
        g1 - a#1 - d2 - d#2 - d2 - a#1 -
        g1 - a#1 - d2 - d#2 - d2 - a#1 -
        f1 - a1 - c2 - d2 - c2 - a1 -
        f1 - a1 - c2 - d2 - c2 - a1 -
        d#1 - g1 - a#1 - c2 - a#1 - g1 -
        d#1 - g1 - a#1 - c2 - a#1 - g1 -

        is coded by FuzeImporter into the line (this string i am then using in the melody for track 2 and is processed by "processMelody4" function):
        "T W [ \ [ W T W [ \ [ W R V Y [ Y V R V Y [ Y V P T W Y W T P T W Y W T "

        link to the FuzeImporter [free of charge :) ]:
        [www.ti.me.cz/fuze/FuzeImport.gz](link url)

        fimporter_melodies.jpg
        fimporter_melodies2.jpg

        1 Reply Last reply Reply Quote 5
        • pianofire
          pianofire Fuze Team last edited by

          We don't normally encourage links but I will allow it in this case!

          1 Reply Last reply Reply Quote 2
          • SteveZX81
            SteveZX81 F last edited by

            Just need a tutorial to build one of these little gizmos now. ;)

            1 Reply Last reply Reply Quote 1
            • First post
              Last post