gpt4 book ai didi

algorithm - 如何可视化音频数据?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:26:54 24 4
gpt4 key购买 nike

我想要一个看起来像这样的东西。两种不同的颜色不是必需的。

audacity on mac
(来源:sourceforge.net)

我已经从两个 int 数组中的立体声 wav 获得了音频数据(一个样本/毫秒),左右声道各一个。我做了几次尝试,但它们看起来远没有这般清晰,我的尝试变成了尖刺状或致密的肿 block 。

有什么好的建议吗?我正在使用 C#,但伪代码没问题。

假设我们有

  • 函数 DrawLine(color, x1, y1, x2, y2)
  • 两个 int 数组,数据为 right[] 和 left[],长度为 L
  • 数据值介于 32767 和 -32768 之间

如果您做出任何其他假设,请将它们写在您的答案中。

for(i = 0; i < L - 1; i++) {
// What magic goes here?
}

这就是我申请 the solution Han provided 时的结果. (只有一个 channel )
alt text http://www.imagechicken.com/uploads/1245877759099921200.jpg

最佳答案

每个像素可能有 1 个以上的样本。对于映射到单个像素的每组样本,您可以绘制一条从样本组中的最小值到最大值的(垂直)线段。如果您放大到每像素 1 个样本或更少,这将不再起作用,并且“不错”的解决方案是显示 sinc 插值。因为DrawLine不能绘制单个像素,所以当最小值和最大值相同时会出现一个小问题。在这种情况下,您可以在所需位置复制单个像素图像,如以下代码所示:

double samplesPerPixel = (double)L / _width;
double firstSample = 0;
int endSample = firstSample + L - 1;
for (short pixel = 0; pixel < _width; pixel++)
{
int lastSample = __min(endSample, (int)(firstSample + samplesPerPixel));
double Y = _data[channel][(int)firstSample];
double minY = Y;
double maxY = Y;
for (int sample = (int)firstSample + 1; sample <= lastSample; sample++)
{
Y = _data[channel][sample];
minY = __min(Y, minY);
maxY = __max(Y, maxY);
}
x = pixel + _offsetx;
y1 = Value2Pixel(minY);
y2 = Value2Pixel(maxY);
if (y1 == y2)
{
g->DrawImageUnscaled(bm, x, y1);
}
else
{
g->DrawLine(pen, x, y1, x, y2);
}
firstSample += samplesPerPixel;
}

请注意,Value2Pixel 将样本值缩放为像素值(在 y 方向)。

关于algorithm - 如何可视化音频数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1035533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com