Thread: Running functions simultaneously

  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,708
    You have to create separate threads. Look up beginthreadex(), etc.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Ha! Quite right Salem. Don't think threads would be of much help.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(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, 07: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