Generative Music with GS?

floydianspiralfloydianspiral Member, PRO Posts: 308
edited November -1 in Working with GS (Mac)
Just wondering if you think it would be possibly AND plausable (performance-wise) to try and implement a generative method of music for my game. Essentially what I would want to do is this:

Have 4 actors placed on each corner of the screen each with a rule somehow implementing the game.time % = every 2 seconds > generate a random number between 1,50 and if = 1 > play sound1, if 2 play sound2, etc.

There would be different sound/random # bank on every actor and each would have a different time they play music at like every 5 seconds or every 10 seconds. Anyone mess around with this sort of thing yet? Also, if anyone knows what the equation would be for me to use game.time % x = every 2 second, every 5, 10, etc that would help also! Thanks.

Comments

  • floydianspiralfloydianspiral Member, PRO Posts: 308
    sorry but I gotta bump.
  • part12studiospart12studios Member Posts: 620
    Hi Floyd,

    Yea I think as long as you're working with samples, it would be plausable. I've been interested in some audio apps as well with GS. I don't have any advise on the how too's though unfortunately. I'm not aware of GS having any kind of sine wave generators or other fundamental synthetic capabilities.. but it sounds like you're not too concerned with pure audio generation as much as accurate manipulations of samples triggered by various "game rules".

    So yea about the sample triggering, it seems like audio is pretty responsive and I would imagine as long as you don't have too many sounds going off at once it will sound good. I only say "too many sounds" because it's not uncommon to find apps that don't account for excessive volume and end up distorting.

    Good luck!
  • ultimaultima Member, PRO Posts: 1,207
    it is certainly plausable and it seems like you just answered the rest of the questions yourself as well. give it a shot, i'm sure it'll work. please do show us the results, as it must be very interesting what kind of sample you choose and the out-come of it.
  • AjBlueAjBlue Member Posts: 215
    it would be awesome if someone had 2 part looping music where there would be a light begining sound with a meatier end sound, and when you enter a big zone in the game the big bass end sound kicks in instantly at the end of one of the sound samples, the 2 part loop would be used so it would be possible to transition into the tense moment faster without having the loop being 2 seconds long. like a 5 second sound clip for each part of the music, so the likelyhood that you will not hear the bigger sound in the zone would be normally more of a 3 second delay, if not instantly.

    allowing the music seemlessly change without the user realizing that the soundtrack change, but instead it subconsciously influences his emotions while playing the game.
  • old_kipperold_kipper Member Posts: 1,420
    Much is possible. I would suggest a few 'tricks'....

    120 bpm offers two beats per second and is really easy to set up

    fire the beat trigger (clock) from a single actor and have everything triggered off it. It avoids timing issues with repeated loops and any slippage.

    There is no tone generator but a single complete waveform is enough to build from. You can loop it, change it's pitch (look up the pitch relationships for tones via google), and overlay harmonics as separate samples. It can also be enveloped.

    cheers kipper
  • MammothMammoth Member Posts: 640
    This can work. Whenever I have tried to do stuff like this GS' memory leak has made the sounds a little off time.
  • floydianspiralfloydianspiral Member, PRO Posts: 308
    @Old_kipper...thanks! I found this somewhere in the forums and it seems to be working...just thought I'd re-share this for anyone interested:

    "Create an index/integer attribute called zero. Give it a value of 0.

    When zero=floor( self.Time *20)%2

    ...do stuff

    That will 'do stuff' every 0.1 seconds.
    Adjust the '20' to change that. Without the '20' it will do stuff every 2 seconds."

    @Mammoth...that's the concern I have: I think if I have a blank scene with not much going on it could be done, but running in the background of an actual game that already has a lot going on might destroy the FPS
  • MammothMammoth Member Posts: 640
    Rhythm games are deceptively hard to make. Especially with limited resources on mobile devices. Try to not use % it takes more memory than *
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    floydianspiral said:
    @Old_kipper...thanks! I found this somewhere in the forums and it seems to be working...just thought I'd re-share this for anyone interested:

    "Create an index/integer attribute called zero. Give it a value of 0.

    When zero=floor( self.Time *20)%2

    ...do stuff

    That will 'do stuff' every 0.1 seconds.
    Adjust the '20' to change that. Without the '20' it will do stuff every 2 seconds."

    Hey! who stole my code?! ;)

    Yeah as Kipper says picking the right tempo is key and 120 would be the easiest.

    The way I found to best trigger the audio is to have a set of conditions with the above rule included. When the conditions are met have a 'play music' boolean that is triggered.

    And a separate rule when play music is true, play sound (looped). Assuming you have loops that are at least a few bars in length.

    So in your case:
    when button is touched
    and when zero = (game.time*2)%2 [to start the loop at intervals of 1 second]

    change attribute play music to true

    Unless you want to have very short loops, i.e drum hits etc. In that case just use the the above code and it will loop the sound every amount of time you specify.

    That's what I used for Honey Tribe, but at a different tempo. It feels much nicer with all the sound fx and loops being in time.

    ----------
    image
    "Honey Tribe is not only a remarkably endearing little game, but it's also incredibly addictive." Pocket Gamer
    "...a touch above the rest in the endless running genre" 148apps.com
    Say hi on Twitter
    Like us on Facebook
    www.HoneyTribeStudios.com
  • floydianspiralfloydianspiral Member, PRO Posts: 308
    @HoneyTribe...yeah it was your code I found! Sorry for not giving credit ; ) this will help me a ton...I want to have 4 separate banks of sounds so that this rule happens for every 2 seconds...another every 4, another every 8, and another every 16...haven't tried it out yet but hopefully it's not too much of a memory drain... Thanks for all the help!
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    floydianspiral said:
    @HoneyTribe...yeah it was your code I found! Sorry for not giving credit ; ) this will help me a ton...I want to have 4 separate banks of sounds so that this rule happens for every 2 seconds...another every 4, another every 8, and another every 16...haven't tried it out yet but hopefully it's not too much of a memory drain... Thanks for all the help!

    No probs.

    If you want to save on overall pacakage size, use .ogg files.

    If you want to save on RAM usage/loading times use .caf

    (Someone did a test a posted the results somewhere around here)
  • JPickardJPickard Member Posts: 477
    This sounds absolutely fascinating. Keep us updated. :)
Sign In or Register to comment.