Nif*_*fle 11 language-agnostic algorithm math audio graphics
我想有一些看起来像这样的东西.两种不同的颜色不是必需的.
Mac上的大胆http://audacity.sourceforge.net/about/images/audacity-macosx.png
我已经从两个int数组中的立体声wav获得音频数据(一个样本/毫秒),每个数组用于左右声道.我做了几次尝试,但他们看起来并不像我这样清楚,我的尝试得到spikey或紧凑的肿块.
有什么好建议吗?我在c#工作但是psuedocode没问题.
假设我们有
如果您做出任何其他假设,请在答案中写下来.
for(i = 0; i < L - 1; i++) {
// What magic goes here?
}
Run Code Online (Sandbox Code Playgroud)
这就是我应用Han提供的解决方案时的结果.(只有一个频道)
替代文字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;
}
Run Code Online (Sandbox Code Playgroud)
请注意,Value2Pixel 将样本值缩放为像素值(在 y 方向)。