views:

106

answers:

9

Good day good-looking computer people,

I might be asking a bit too much, but here it goes.

I'm trying to do a bit of reserve engineering on this sound library. Looking at the main.cpp file (which I have posted below) it has two methods, setup and play. I'm a bit confused as to how this is working:

  1. When you run the Xcode project, shouldn't there be a main function that is the first method called? I don't see that here.

  2. The play function is being called (because I hear music), but it must be from elsewhere since in needs the argument output. Where could it be being called from?

To try to be a bit more specific, this is my question:

  1. If the program isn't starting from a main method in the main.cpp file, where else could it be starting from ?

#include "maximilian.h"

double outputs[2],moreoutputs[2]; //some track outputs
double filtered, ramped, filtered2; 
osc buffertest,ramp;
mix mymix,bobbins;//some panning busses
double env[4]={200,0,0,50};//the kick drum pitch envelope data
double env2[6]={10000,0,9000,5,0,5};//the hi hat pitch envelope dat
envelope b,f;//two envelopers
sample beats;


extern int channels=2;//stereo-must be supported by hardware
extern int buffersize=256;//should be fine for most things
extern int samplerate=44100;//SR must be supported by card. It's always the default

void setup() {//some inits
    b.amplitude=env[0];//starting value for envelope b
    f.amplitude=env2[0];//same for f
    beats.load("/Users/ericbrotto/Desktop/beats.wav");//put a path to a soundfile here.           Wav format only.
    printf("Summary:\n%s", beats.getSummary());//get info on samples if you like
 }

 void play(double *output) {//this is where the magic happens. Very slow magic.
    filtered2=beats.play(1*(1./34), 0, beats.length()); 
    bobbins.stereo(filtered2, moreoutputs, 0.5);//invert the pan
    output[0]=outputs[0]+moreoutputs[0];//stick it in the out!!
    output[1]=outputs[1]+moreoutputs[1];
 }

Thanks!

+3  A: 

A main method is required and must have the name main unless you tell the compiler otherwise. It is possible that the main method gets included through a header or is implemented by a macro.

Space_C0wb0y
+1  A: 
  1. You're dealing with a library, not a standalone program. It doesn't have a main function, since it won't run on its own. When a developer uses a library, such as this, his application calls out to the library's functions (such as play).

  2. I don't entirely understand from what you hear music. What have you compiled? An example program? In that case, that example program probably does have a main function and at some point calls the library's play.

gspr
Oops, I see that my answer doesn't really consider the code the question asker posted. Sorry about that, I'll leave the answer as a general comment about libraries.
gspr
@gpsr: This is what the community wiki tick is for (at least in my opinion).
Space_C0wb0y
@Space_C0wb0y: Good point. I've learned something today :-)
gspr
A: 

main is either getting defined in the the maximillian.h, something it includes, or it is already compiled into the maximillian library.

Michael Anderson
+2  A: 

If the program isn't starting from a main method in the main.cpp file, where else could it be starting from ?

From a main method in a different source file or pre-compiled library, probably, or definitely.

PigBen
This nailed it on the head. It was in a different source file. Although I must say I wish I could accept more then one answer because I got a lot of insight from all of these responses. THANKS EVERYBODY!
Eric Brotto
+2  A: 

in the directory where you unpacked the library -

find . | xargs egrep "main"

It has to be there somewhere... ;)

Nim
A: 

what i understand from it is the cpp file for the implementation of this library's header it is not a complete program but when you use this lib in your program you have to do is

1) use its setup method to setup or load the file u want to play

2) you have to call play to play the sound

that it about this/.

moon
A: 

For your question

If the program isn't starting from a main method in the main.cpp file, where else could it be starting from ?

Global objects and static members of classes will be initialized before call to main() function.

For below code

class Test
{
public:

};

Test* fun()
{
    return new Test;
}

Test *p = fun();

int main()
{
}

For initializing pointer p, fun() will be called before main() function.

bjskishore123
+1  A: 

Put a breakpoints on the front of each function, run the app, and examine call stack when breakpoint is hit.

Daniel Mošmondor
A: 

Line 491 of maximillian.cpp

learnvst