Thread: Pre-generated sin array

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    106

    Pre-generated sin array

    Hi Guys,
    I am hoping it would be obvious to someone how this sin table was generated.
    This is from a retro plasma demo, and is running fine on a dsPic so fast now
    that I have to delay it. I thought it would be good to either declare the array, and then populate it (saving some program memory),
    or better still, loose the array altogether and calculate it on the fly.
    Any help would be appreciated.
    Cheers, Art.


    Code:
    WORD sin_table[91] =
    {
        0,   285,   571,   857,  1142,  1427,  1712,  1996,  2280,  2563,
        2845,  3126,  3406,  3685,  3963,  4240,  4516,  4790,  5062,  5334,
        5603,  5871,  6137,  6401,  6663,  6924,  7182,  7438,  7691,  7943,
        8191,  8438,  8682,  8923,  9161,  9397,  9630,  9860, 10086, 10310,
        10531, 10748, 10963, 11173, 11381, 11585, 11785, 11982, 12175, 12365,
        12550, 12732, 12910, 13084, 13254, 13420, 13582, 13740, 13894, 14043,
        14188, 14329, 14466, 14598, 14725, 14848, 14967, 15081, 15190, 15295,
        15395, 15491, 15582, 15668, 15749, 15825, 15897, 15964, 16025, 16082,
        16135, 16182, 16224, 16261, 16294, 16321, 16344, 16361, 16374, 16381,
        16384
    };

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    The table contains relative values for angles 0 thru 90 degrees. Basically, each value is floor(sin(x)) * 16384.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    106
    Ok, I will try it, thanks

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    With a PIC, you either consume program storage memory or RAM. Since RAM tends to be very limited in those small devices, I'd recommend keeping the hard-coded array, rather than calculating it on the fly, because it's going to take 180 bytes, which may be significant, if you're using one of the smaller PICs.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-25-2014, 10:15 PM
  2. i want my output to be generated
    By coolshyam in forum C Programming
    Replies: 3
    Last Post: 03-19-2005, 12:53 AM
  3. How is GUID generated?
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 03-12-2004, 10:38 PM
  4. Auto generated
    By Daniel decosta in forum C Programming
    Replies: 11
    Last Post: 09-28-2002, 05:35 PM
  5. sorting a randomly generated dynamic array
    By Led Zeppelin in forum C Programming
    Replies: 4
    Last Post: 05-03-2002, 09:10 AM