如何开始用 C++ 编写音乐可视化工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/819953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:25:37  来源:igfitidea点击:

How to start writing a music visualizer in C++?

c++openglaudiovisualization

提问by victor

I'm interested in learning to use OpenGL and I had the idea of writing a music visualizer. Can anyone give me some pointers of what elements I'll need and how I should go about learning to do this?

我对学习使用 OpenGL 很感兴趣,并且有了编写音乐可视化工具的想法。谁能给我一些关于我需要哪些元素以及我应该如何学习做到这一点的指示?

采纳答案by RandomNickName42

If you use C++/CLI, here's an examplethat uses WPF four (fourier that is;) display.

如果您使用 C++/CLI,这里有一个使用 WPF 四(即傅立叶;)显示的示例

He references this site(archived) that has considerable information about what your asking, here's anoutline from the specific page;

他引用了这个站点存档),其中包含有关您所询问内容的大量信息,这是特定页面的概述;

How do we split sound into frequencies? Our ears do it by mechanical means, mathematicians do it using Fourier transforms, and computers do it using FFT.

  1. The Physics of Sound
    • Harmonic Oscillator
  2. Sampling Sounds
  3. Fourier Analysis
  4. Complex Numbers
  5. Digital Fourier Transform
  6. FFT

我们如何将声音分成频率?我们的耳朵通过机械方式来完成,数学家使用傅立叶变换来完成,而计算机使用 FFT 来完成。

  1. 声音物理学
    • 谐波振荡器
  2. 采样声音
  3. 傅立叶分析
  4. 复数
  5. 数字傅立叶变换
  6. 快速傅立叶变换

Ahhh, I found this(archived) a few minutes later, it's a native C++ analyzer. Code included, that should get you off and running.

啊,几分钟后我发现了这个存档),它是一个原生的 C++ 分析器。包含的代码,应该会让你开始运行。

回答by Led

My approach for creating BeatHarness (http://www.beatharness.com) :

我创建 BeatHarness ( http://www.beatharness.com) 的方法:

  • record audio in real time
  • have a thread that runs an FFT on the audio to get the frequency intensities
  • calculate audio-volume for left and right channel
  • filter the frequencies in bands (bass, midtones, treble)
  • 实时录制音频
  • 有一个线程在音频上运行 FFT 以获得频率强度
  • 计算左右声道的音量
  • 过滤频段中的频率(低音、中音、高音)

now you have some nice variables to use in your graphics display. For example, show a picture where the size is multiplied by the bass - this will give you a picture that'll zoom in on the beat. From there on it's your own imagination ! :)

现在您有一些不错的变量可用于图形显示。例如,显示一张大小乘以低音的图片 - 这将为您提供一张可以放大节拍的图片。从那里开始,这是您自己的想象力!:)

回答by basszero

Are you trying to write your own audio/music player? Perhaps you should try writing a plugin for an existing player so you can focus on graphics rather than the minutia of codecs, dsp, and audio output devices.

您是否正在尝试编写自己的音频/音乐播放器?也许您应该尝试为现有播放器编写一个插件,以便您可以专注于图形而不是编解码器、dsp 和音频输出设备的细节。

I know WinAMP and Foobar have APIs for visualization plugins. I'm sure Windows Media Player and iTunes also have them. Just pick a media player and start reading. Some of them may even have existing OpenGL plugins from which you can start so you can focus on pure OpenGL.

我知道 WinAMP 和 Foobar 有用于可视化插件的 API。我确信 Windows Media Player 和 iTunes 也有它们。只需选择一个媒体播放器并开始阅读。其中一些甚至可能有现有的 OpenGL 插件,您可以从中开始,这样您就可以专注于纯 OpenGL。

回答by PowerApp101

If you're just after some basic 3D or accelerated 2D then I'd recommend purchasing a copy of Dave Astle's "Beginning OpenGL Game Programming" which covers the basics of OpenGL in C++.

如果您只是在学习一些基本的 3D 或加速 2D,那么我建议您购买 Dave Astle 的“开始 OpenGL 游戏编程”的副本,其中涵盖了 C++ 中 OpenGL 的基础知识。

回答by Jem

For the music analysis part, you should study the basis of Fourier series, then pick a free implementation of a DFFT (digital fast fourier transform) algorithm.

对于音乐分析部分,您应该学习傅里叶级数的基础,然后选择一个 DFFT(数字快速傅里叶变换)算法的免费实现。

回答by Kirn Gill

You may want to consider using libvisual's FFT/DCT functions over FFTW; they're much simpler to work with and provide data that's similarly easy to work with for the sake of generating visuals. Several media players and visualization plugins use libvisual to some extent for their visuals. Examples: Totem (player), GOOM (plugin for Totem and other players), PsyMP3 2.x (player)

您可能需要考虑在 FFTW 上使用 libvisual 的 FFT/DCT 函数;它们更易于使用,并提供同样易于使用的数据以生成视觉效果。一些媒体播放器和可视化插件在某种程度上使用 libvisual 来实现他们的视觉效果。示例:Totem(播放器)、GOOM(图腾和其他播放器的插件)、PsyMP3 2.x(播放器)

回答by Kirn Gill

You can find implementation of FFT algorithms and other useful informations in Numerical Recipes in Cbook. The book is free AFAIK. There is also Numerical Recipes in C++book.

您可以在 C书的Numerical Recipes 中找到 FFT 算法的实现和其他有用的信息。这本书是免费的 AFAIK。C++书中还有Numerical Recipes

回答by bastianneu

From my point of view...check this site: http://nehe.gamedev.net/

从我的角度来看......检查这个网站:http: //nehe.gamedev.net/

really good Information and Tutorials for using OpenGL

非常好的使用 OpenGL 的信息和教程

edit: http://www.opengl.org/code/

编辑:http: //www.opengl.org/code/