User Tag List

Results 1 to 6 of 6

Thread: Playing with random sample frequency

  1. #1
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,310
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)

    Playing with random sample frequency

    Hi All,

    I thought I would spice up my sound fx with random frequency changes. For some reason, my usual formula for picking a random number within a range seems to not work:

    Range Minimum + (Random(Range Minimum - Range Maximum))

    So if I want a random frequency between 100 and 105 I tried:

    100+(Random(100-105))

    For some reason, when I try this range, I am getting frequencies that are extremely low. Any idea why?

    Mobichan

  2. #2
    Clicker Multimedia Fusion 2 DeveloperiOS Export Module
    Nifflas's Avatar
    Join Date
    Jul 2006
    Posts
    2,613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Playing with random sample frequency

    It's because a normal high quality sample is played at a sample rate of 44100hz, not a sample rate of 100hz to 105hz. Some lower quality samples does often play at 22050hz or 11025hz.

    Second, you sound rather confused about how Random() works. You don't specify a range with a starting and ending number (and if you did, why would you start out with 100+ anyway?). Random(6) will generate a random number between 0 and 5. Random(100-105) is the same as random(-5) which is logical since 100-105 is -5, and this will at least on build 247 generate a random number between 0 and 65531.

    To generate a random number between 100 and 105, you need to use the expression 100+random(6)... but then, as you're dealing with sample rates, you'll probably want to stick to values around 44100 (or whatever the sample uses).

  3. #3
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,310
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)

    Re: Playing with random sample frequency

    Oooops, I didn't look at my notes correctly. The formula should be:

    Range Minimum + (Random(Range Maximum - Range Minimum)) or 100+(random(105-100))

    FYI, I got that formula from the FAQ page on the Clikwiki: http://www.mmfwiki.erathean.com/index.php/Random_numbers

    Thanks for the heads up about the frequency range. I thought 100 was the standard playback frequency because I set my sound to play at 100 and it sounded normal. Go figure.

    Cheers,

    Mobichan

  4. #4
    Clicker Multimedia Fusion 2 DeveloperiOS Export Module
    Nifflas's Avatar
    Join Date
    Jul 2006
    Posts
    2,613
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Playing with random sample frequency

    Ah, that makes more sense. Still, remember that random() is 0-based. Random(105-100) which is the same as random(5) returns a number between 0 and 4. This means that with the formula you use generates random numbers between 100 and 104 (not 105).

    I say this again, to generate a value between 100 and 105, use 100+random(6), it's shorter and makes more sense than 100+random(106-100) - yeah, the formula at the clickwiki is wrong too. You're just making something easy more complicated, even if you insist to use your formula you're including an extra pair of brackets that does nothing. When you're only using addition and subtraction, you don't have to worry about what order the numbers are calculated in.

  5. #5
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export ModuleUnicode Add-on
    mobichan's Avatar
    Join Date
    Oct 2007
    Location
    Buffalo, NY
    Posts
    3,310
    Mentioned
    28 Post(s)
    Tagged
    0 Thread(s)

    Re: Playing with random sample frequency

    Who do we need to inform to have the wiki corrected?

    Also, aside from having to type more, is there any performance increase to having a shorter formula?

  6. #6
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Playing with random sample frequency

    MMF formulas are interpreted and probably don't optimise out operations on constants, so a simpler formula will always be quicker. "106-100" would do a subtraction every time, even though the answer is always 6. I don't know how slow the interpreter is at interpreting brackets.

    Though to be completely honest, you're unlikely to notice math ops as a cause of slowdown. So many other bits of MMF are so much slower than one subtraction.

Similar Threads

  1. Channel / Sample frequency
    By Olivier in forum SWF/Flash Export Module Version 2.0
    Replies: 10
    Last Post: 12th April 2010, 11:07 AM
  2. Sample frequency limit
    By axel in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 24th June 2008, 09:12 PM
  3. Random Sample not playing
    By mussashimits in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 1st June 2007, 08:29 PM
  4. playing a Random Sample- possible?
    By mussashimits in forum The Games Factory 2 - Technical Support
    Replies: 12
    Last Post: 15th April 2007, 11:06 PM
  5. Get Original Sample Frequency
    By stuckboy in forum Multimedia Fusion 2 - Technical Support
    Replies: 17
    Last Post: 6th February 2007, 03:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •