Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 使用徽标绘制声音_Vb.net_Visual Studio_Audio_Visual Studio 2013 - Fatal编程技术网

Vb.net 使用徽标绘制声音

Vb.net 使用徽标绘制声音,vb.net,visual-studio,audio,visual-studio-2013,Vb.net,Visual Studio,Audio,Visual Studio 2013,我现在正在使用Logo,我正在做一个项目,基本上我想把你录制的声音变成视觉效果,唯一的问题是当我去寻找代码时,它需要1:一个图片框和2:手动抓取声音.wav文件并放置它。我已经编写了代码来记录我的声音并将其转换成.Wav文件,我已经编写了代码来可视化它,就在我运行它时,它显示为一个粗大的正方形线条,而不是我显示的示例。注意:我不是在画框中画图,而是使用g.drawline(bleh,bleh,bleh,bleh)直接在表单中画图 (例如:) 我正在尝试运行的代码: 公共子DrawSound(x为

我现在正在使用Logo,我正在做一个项目,基本上我想把你录制的声音变成视觉效果,唯一的问题是当我去寻找代码时,它需要1:一个图片框和2:手动抓取声音.wav文件并放置它。我已经编写了代码来记录我的声音并将其转换成.Wav文件,我已经编写了代码来可视化它,就在我运行它时,它显示为一个粗大的正方形线条,而不是我显示的示例。注意:我不是在画框中画图,而是使用g.drawline(bleh,bleh,bleh,bleh)直接在表单中画图

(例如:)

我正在尝试运行的代码:

公共子DrawSound(x为整数,y为整数)


X和Y是形式的中间部分。我也会链接我从哪里得到代码,但我忘了在哪里,而且,我还修改了它,试图直接运行到表单中,而不是图片盒中。它起了点作用,哈哈(还有这么多未使用的DIM,但我所知道的是,一旦我删除了一个,所有代码都不起作用哈哈),所以有人能帮忙吗?

谢谢你告诉我你链接到的图像显示了一个非常快速的音频剪辑。。。在几毫秒的量级上。。。我建议你强制你的代码做类似的非常短的剪辑,你的可视化将以何种方式更紧密地匹配给定的链接我给定的代码绘制音频,就像我在发送的图像中显示的一样(这不是我的代码所做的,这是一个示例)。它和它不完全一样,但风格相同。刚才当我使用代码来使用声音时,应该波动的条都是最大的。它只是一个有条子的盒子。它不可能是我的音频敏感度,因为我在同一个未经编辑的代码上使用了它,它工作了。很明显,我有点不对劲,哈哈,我想出来了。我必须详细说明代码,并在绘图中绘制一个填充矩形。。。帮每个人一个忙,并在回答你的工作代码中发布。。。所以下一个人是。。。欢迎加入苏
    Dim samplez As New List(Of Short)


    Dim maxamount As Short
    Dim pic As New Bitmap(x, y)
    Dim ratio As Integer = (samplez.Count - 1) / (y - 1) 'If there are 10000 samples and 200 pixels, this would be every 50th sample is shown
    Dim halfpic As Integer = (x / 2) 'Simply half the height of the picturebox
    GC.Collect()
    Dim wavefile() As Byte = IO.File.ReadAllBytes("C:\Users\" & Environ$("Username") & "\Documents\Sounds\Mic.wav")
    GC.Collect()
    Dim memstream As New IO.MemoryStream(wavefile)
    Dim binreader As New IO.BinaryReader(memstream)
    Dim ChunkID As Integer = binreader.ReadInt32()
    Dim filesize As Integer = binreader.ReadInt32()
    Dim rifftype As Integer = binreader.ReadInt32()
    Dim fmtID As Integer = binreader.ReadInt32()
    Dim fmtsize As Integer = binreader.ReadInt32()
    Dim fmtcode As Integer = binreader.ReadInt16()
    Dim channels As Integer = binreader.ReadInt16()
    Dim samplerate As Integer = binreader.ReadInt32()
    Dim fmtAvgBPS As Integer = binreader.ReadInt32()
    Dim fmtblockalign As Integer = binreader.ReadInt16()
    Dim bitdepth As Integer = binreader.ReadInt16()

    If fmtsize = 18 Then
        Dim fmtextrasize As Integer = binreader.ReadInt16()
        binreader.ReadBytes(fmtextrasize)
    End If
    Dim DataID As Integer = binreader.ReadInt32()
    Dim DataSize As Integer = binreader.ReadInt32()

    samplez.Clear()

    For i = 0 To (DataSize - 3) / 2

        samplez.Add(binreader.ReadInt16())

        If samplez(samplez.Count - 1) > maxamount Then 'Using this for the pic
            maxamount = samplez(samplez.Count - 1)
        End If

    Next

    For i = 1 To x - 10 Step 2 'Steping 2 because in one go, we do 2 samples
        Dim leftdata As Integer = Math.Abs(samplez(i * ratio)) 'Grabbing that N-th sample to display. Using Absolute to show them one direction
        Dim leftpercent As Single = leftdata / (maxamount * 2) 'This breaks it down to something like 0.0 to 1.0. Multiplying by 2 to make it half.
        Dim leftpicheight As Integer = leftpercent * x 'So when the percent is tied to the height, its only a percent of the height
        g.DrawLine(Pens.LimeGreen, i, halfpic, i, leftpicheight + halfpic) 'Draw dat! The half pic puts it in the center

        Dim rightdata As Integer = Math.Abs(samplez((i + 1) * ratio)) 'Same thing except we're grabbing i + 1 because we'd skip it because of the 'step 2' on the for statement
        Dim rightpercent As Single = -rightdata / (maxamount * 2) 'put a negative infront of data so it goes down.
        Dim rightpicheight As Integer = rightpercent * x
        g.DrawLine(Pens.Blue, i, halfpic, i, rightpicheight + halfpic)
    Next
End Sub