Cocoa Touch 中的音调生成

发布于 2024-07-09 13:59:28 字数 90 浏览 16 评论 0原文

我需要产生一种可以操纵频率和波的音调。 总体目标是创建一架基本钢琴。 有谁知道我怎样才能实现这一目标?

我的开发平台是iPhone 2.x

I need to generate a tone that I can manipulate frequency and wave. The overall goal is to create a basic piano. Does anyone know how I can achieve this?

My development platform is the iPhone 2.x

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

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

发布评论

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

评论(6

鸵鸟症 2024-07-16 13:59:28

您始终可以从sin 波开始。 :-)

#include <cmath>

typedef double Sample;
typedef double Time;

class MonoNote {
protected:
    Time start, duration;
    virtual void internalRender(double now, Sample *mono) = 0;
public:
    MonoNote(Time s, Time d) : start(s), duration(d) {}
    virtual ~MonoNote() {}
    void render(double now, Sample *mono) {
        if (start <= now && now < start + duration) {
            internalRender(now, mono);
        }
    }
};

class MonoSinNote : public MonoNote {
    Time freq;
    Sample amplitude;
protected:
    void internalRender(double now, Sample *mono) {
        const double v = sin(2*M_PI*(now - start) * freq);
        *mono += amplitude*v;
    }
public:
    MonoSinNote(Time s, Time d, Time f, Sample a) : MonoNote(s, d), freq(f), amplitude(a) {}
    ~MonoSinNote() {}
};

You could always start with sin waves. :-)

#include <cmath>

typedef double Sample;
typedef double Time;

class MonoNote {
protected:
    Time start, duration;
    virtual void internalRender(double now, Sample *mono) = 0;
public:
    MonoNote(Time s, Time d) : start(s), duration(d) {}
    virtual ~MonoNote() {}
    void render(double now, Sample *mono) {
        if (start <= now && now < start + duration) {
            internalRender(now, mono);
        }
    }
};

class MonoSinNote : public MonoNote {
    Time freq;
    Sample amplitude;
protected:
    void internalRender(double now, Sample *mono) {
        const double v = sin(2*M_PI*(now - start) * freq);
        *mono += amplitude*v;
    }
public:
    MonoSinNote(Time s, Time d, Time f, Sample a) : MonoNote(s, d), freq(f), amplitude(a) {}
    ~MonoSinNote() {}
};
惜醉颜 2024-07-16 13:59:28

钢琴很奇怪。 罗伯特·穆格 (Robert Moog) 于 1980 年 3 月在《键盘杂志》中对此进行了描述。基频(最低频率部分)已调准,但每个高次谐波都比应有的更明亮(或“更尖锐”或更高音调),而且数量还在增加。

第二次到第九次谐波比基波响亮。 第十到第二十的声音也差不多。

基本面成交量上涨,然后下跌,然后又回来。 其他部分具有特有的上下形状。 部分交换能量,因此整体体积如您所期望的那样。 但这是一群部分交换能量的人。 我猜如果你得到了最低的几个权利和奇怪的不和谐传播权利,你会做得很好。

您可以观看软件频谱分析仪中的操作并了解您需要了解的内容。 加法合成可能是我解决这个问题的方法。

Piano is strange. Robert Moog wrote about it in Keyboard Magazine in March 1980. The fundamental (lowest frequency partial) is in tune, but each higher harmonic is brighter (or "sharper" or higher-pitched) than it should be, and by an increasing amount.

The second through ninth harmonics are louder than the fundamental. The tenth through twentieth are about as loud.

The fundamental swells up in volume and then dives, then it comes back. The other partials have characteristic up and down shapes. The partials exchange energy so the overall volume acts as you would expect. Buts it's a swarm of partials trading energy. I'd guess if you got the lowest few right and the weird inharmonic spread right you'd do OK.

You could watch the action in a software spectrum analyzer and learn what you need to know. Additive synthesis is probably how I'd take on the problem.

叹梦 2024-07-16 13:59:28

查看 Mobilesynth...应用商店中的开源合成器:http://code.google。 com/p/mobilesynth/

Check out Mobilesynth...an open source synthesizer in the app store: http://code.google.com/p/mobilesynth/

独留℉清风醉 2024-07-16 13:59:28

请查看 http://mda.smartelectronix.com/。 它们是一系列开源 VST 插件。 查看 Piano、ePiano 或 DX10 的源代码。 这就像您会发现的一样简单。

Check out http://mda.smartelectronix.com/. They are a series of open source VST plugins. Look at the source for Piano, ePiano or DX10. It's about as simple as you are going to find.

叶落知秋 2024-07-16 13:59:28

Apple 开发者论坛对此有一个主题(“音频合成")可能会提供一些见解。

Apple Developer Forums has a thread on this ("Audio Synthesis") that might provide some insight.

口干舌燥 2024-07-16 13:59:28

查看播放正弦波的 DefaultOutputUnit 示例代码。

/开发人员/示例/CoreAudio/SimpleSDK/DefaultOutputUnit

Check out the DefaultOutputUnit sample code which plays a sine wave.

/Developer/Examples/CoreAudio/SimpleSDK/DefaultOutputUnit

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