VS2012如何控制声卡播放某一频率的声音
VS2012怎么控制声卡播放某一频率的声音?
我想做一个电子琴的小应用,可是找不到合适的API。
记得有个Beep函数可以播放某一特定频率的声音,可是它是通过蜂鸣器实现的,大部分笔记本都没有蜂鸣器,最主要的是蜂鸣器不能模拟其它音色。
另外在网上得知有个winmm.lib库可以进行多媒体处理,但我以前只用过PlaySound函数播放wav音频文件,不知道有没有可以播放某一特定频率的函数。
------解决思路----------------------
找个音频播放API, 比如openal, 比如在windows上面还是推荐XAduio2,
所有windows平台都支持, 然后用一个函数写一个正弦波wave缓存, 我以前写过,
但是重装系统后没了.
------解决思路----------------------
仅供参考,尽管是VB6:
------解决思路----------------------
我有一个为自己游戏写的小音频库, 把demo1改成了播放某频率了. 当然需要vs2015。
win7以及以下的话还需要DXSDK. 不过可以作为参考吧.
https://github.com/dustpg/WrapAL/blob/master/demo/demo1.cpp
我想做一个电子琴的小应用,可是找不到合适的API。
记得有个Beep函数可以播放某一特定频率的声音,可是它是通过蜂鸣器实现的,大部分笔记本都没有蜂鸣器,最主要的是蜂鸣器不能模拟其它音色。
另外在网上得知有个winmm.lib库可以进行多媒体处理,但我以前只用过PlaySound函数播放wav音频文件,不知道有没有可以播放某一特定频率的函数。
------解决思路----------------------
找个音频播放API, 比如openal, 比如在windows上面还是推荐XAduio2,
所有windows平台都支持, 然后用一个函数写一个正弦波wave缓存, 我以前写过,
但是重装系统后没了.
------解决思路----------------------
仅供参考,尽管是VB6:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 1590
ClientLeft = 60
ClientTop = 345
ClientWidth = 5190
LinkTopic = "Form1"
ScaleHeight = 1590
ScaleWidth = 5190
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 375
Left = 360
TabIndex = 1
Text = "Text1"
Top = 360
Width = 4455
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 1800
TabIndex = 0
Top = 840
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long
Private Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'--------------------------------------------------------
Dim notes(1 To 8, 1 To 2) As Variant
'--------------------------------------------------------
Private Sub Form_Load()
Randomize '此语句应在初始化时调用一次即可
notes(1, 1) = "C4": notes(1, 2) = 60
notes(2, 1) = "D4": notes(2, 2) = 62
notes(3, 1) = "E4": notes(3, 2) = 64
notes(4, 1) = "F4": notes(4, 2) = 65
notes(5, 1) = "G4": notes(5, 2) = 67
notes(6, 1) = "A5": notes(6, 2) = 69
notes(7, 1) = "B5": notes(7, 2) = 71
notes(8, 1) = "C5": notes(8, 2) = 72
End Sub
'--------------------------------------------------------
Private Sub Command2_Click()
Dim lMidiAPIReturn As Long
Dim tone As Integer
Dim mlmidiouthandle As Long
Dim volume As Long
Dim channel As Long
Dim i As Integer
Dim a As Integer
Dim b As Integer
Dim t As Integer
Dim s(8) As Integer
For i = 1 To 8
s(i) = i
Next
'随机打乱s(i)的顺序 即洗牌
For i = 8 To 2 Step -1
a = i: b = Int(Rnd() * i) + 1
If a <> b Then
t = s(a): s(a) = s(b): s(b) = t
End If
Next
mlmidiouthandle = 0
lMidiAPIReturn = midiOutOpen(mlmidiouthandle, -1, 0, 0, 0)
volume = 90
channel = 0
Text1.Text = ""
For i = 1 To 8
Text1.Text = Text1.Text + CStr(s(i)) + " " + notes(s(i), 1) + ", "
Text1.Refresh
tone = notes(s(i), 2)
lMidiAPIReturn = midiOutShortMsg(mlmidiouthandle, &H90 + ((tone) * &H100) + (volume * &H10000) + channel)
Sleep 100
Next
lMidiAPIReturn = midiOutClose(mlmidiouthandle)
End Sub
------解决思路----------------------
我有一个为自己游戏写的小音频库, 把demo1改成了播放某频率了. 当然需要vs2015。
win7以及以下的话还需要DXSDK. 不过可以作为参考吧.
https://github.com/dustpg/WrapAL/blob/master/demo/demo1.cpp