ac/cpp 项目中如何调用 main 函数

发布于 2024-09-28 14:07:11 字数 1693 浏览 1 评论 0原文

美好的一天,漂亮的计算机人,

我的要求可能有点太多了,但就这样吧。

我正在尝试对这个声音库进行一些储备工程。查看 main.cpp 文件(我在下面发布)它有两种方法:设置和播放。我对它是如何工作的有点困惑:

  1. 当你运行 Xcode 项目时,不应该有一个 main 函数是第一个调用的方法吗?我在这里没有看到这一点。

  2. 正在调用播放函数(因为我听到音乐),但它必须来自其他地方,因为需要参数输出。它可能是从哪里调用的?

为了更具体一点,这是我的问题:

  1. 如果程序不是从 main.cpp 文件中的 main 方法启动,那么它还能从哪里启动?

#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];
 }

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

白云悠悠 2024-10-05 14:07:11

如果程序不是从
main.cpp 文件中的 main 方法,
还能从哪里开始呢?

可能或肯定来自不同源文件或预编译库中的 main 方法。

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.

清君侧 2024-10-05 14:07:11

main 方法是必需的,并且必须具有名称 main ,除非您另外告诉编译器。 main 方法可能通过标头包含或由宏实现。

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.

月亮是我掰弯的 2024-10-05 14:07:11

在你解压库的目录中 -

find . | xargs egrep "main"

它必须在某个地方......;)

in the directory where you unpacked the library -

find . | xargs egrep "main"

It has to be there somewhere... ;)

貪欢 2024-10-05 14:07:11
  1. 您正在处理一个库,而不是一个独立的程序。它没有 main 函数,因为它不会单独运行。当开发人员使用诸如此类的库时,他的应用程序会调用该库的函数(例如 play)。

  2. 我无法完全理解你所听到的音乐。你编译了什么?一个示例程序?在这种情况下,该示例程序可能确实有一个 main 函数,并且在某些时候调用库的 play

  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.

冷情 2024-10-05 14:07:11

main 要么在 maximillian.h 中定义,它包含一些内容,要么已经编译到 maximillian 库中。

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

咆哮 2024-10-05 14:07:11

在每个函数的前面放置一个断点,运行应用程序,并在命中断点时检查调用堆栈。

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

暮倦 2024-10-05 14:07:11

我从中了解到的是用于实现该库标头的cpp文件,它不是一个完整的程序,但是当您在程序中使用该库时,您必须做的是

1)使用其设置方法来设置或加载您想要的文件播放

2)你必须调用play来播放

关于this/的声音。

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/.

初熏 2024-10-05 14:07:11

对于你的问题

如果程序不是从 main.cpp 文件中的 main 方法启动,
还能从哪里开始

全局对象和类的静态成员将在调用 main() 函数之前初始化。

对于下面的代码

class Test
{
public:

};

Test* fun()
{
    return new Test;
}

Test *p = fun();

int main()
{
}

,为了初始化指针 p, fun() 将在 main() 函数之前调用。

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.

十雾 2024-10-05 14:07:11

maximillian.cpp 第 491 行

Line 491 of maximillian.cpp

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文