Running functions simultaneously

This is a discussion on Running functions simultaneously within the C Programming forums, part of the General Programming Boards category; Hello, i've only been programming a while. I'm trying to code an midi music improvisation program with separate functions for ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    1

    Running functions simultaneously

    Hello, i've only been programming a while. I'm trying to code an midi music improvisation program with separate functions for each instrument (which all work fine separately), but I can't work out how to make them all play at the same time. Basically, I have a function "random_lead" (which produces random midi lead notes) and i want it to play at the same time as "random_bass" (which improvise midi bass notes). Any thoughts would be much appreciated. Thanks!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    You have to create separate threads. Look up beginthreadex(), etc.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Sounds like you want to do audio mixing, not threads.

    Unless you're going for a truly random effect, running the same threaded program twice is unlikely to produce the same results.

    Perhaps a rummage here would help
    http://www.programmersheaven.com/zone10/index.htm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    Ha! Quite right Salem. Don't think threads would be of much help.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Running 2 functions simultaneously
    By blkhockeypro19 in forum C Programming
    Replies: 7
    Last Post: 04-19-2009, 12:48 AM
  2. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 06:05 PM
  3. Running Normal Functions inside of a class
    By Padawan in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 11:52 PM
  4. Expression Manipulator v0.2 (bug fixes, functions)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-26-2003, 04:52 PM
  5. trouble defining member functions
    By dP munky in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2003, 08:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21