您的位置:

c语言调用声卡,c语言调用声卡发声

本文目录一览:

如何针对声卡编程发出特定频率的声音

蜂鸣器编程的话,有个API函数,VB中的声明为

Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

调用方法是Beep 声音频率,持续时间(毫秒为单位)

比如 beep 2000,1000

如果是声卡编程的话,也有相应的API函数,比如你可以用DirectSound(也就是DirectX的一部分),功能比较强大,也很专业。事实上,如果你使用的是专业级的声卡和音响设备,它可以在一定范围内回放出超出人耳听觉范围的声音。当然也可以用简单一点的API,以下是几个需要的函数:

Private Declare Function midiOutGetDevCaps Lib "winmm.dll" Alias "midiOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As MIDIOUTCAPS, ByVal uSize As Long) As Long

Private Declare Function midiOutGetNumDevs Lib "winmm" () As Integer

Private Declare Function MIDIOutOpen Lib "winmm.dll" Alias "midiOutOpen" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long

Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long

Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long

Private Declare Function midiOutGetErrorText Lib "winmm.dll" Alias "midiOutGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long

Private Const MAXERRORLENGTH = 128 ' max error text length (including NULL)

Private Const MIDIMAPPER = (-1)

Private Const MIDI_MAPPER = (-1)

'MIDIOUTCAPS结构描述了Musical Instrument Digital Interface(MIDI)输入设备的性能

Type MIDIOUTCAPS

wMid As Integer

wPid As Integer ' 产品 ID

vDriverVersion As Long ' 设备版本

szPname As String * 32 ' 设备 name

wTechnology As Integer ' 设备类型

wVoices As Integer

wNotes As Integer

wChannelMask As Integer

dwSupport As Long

End Type

Public Sub note_on(ch As Integer, ByVal kk As Integer, v As Integer)

' 发音主函数。参数分别为通道编号,音调,速度

Call midi_outshort(H90 + ch, kk, v)

End Sub

Sub midi_outshort(b1 As Integer, b2 As Integer, b3 As Integer)

Dim midi_error As Integer

midi_error = midiOutShortMsg(hMidi, b3 * H10000 + b2 * H100 + b1)

If Not midi_error = 0 Then

Call midi_outerr(midi_error)

End If

End Sub

Sub midi_outerr(ByVal midi_error As Integer)

Dim s As String

Dim x As Integer

s = Space(MAXERRORLENGTH)

x = midiOutGetErrorText(midi_error, s, MAXERRORLENGTH)

MsgBox s

End Sub

在visual c++中用C语言编程时要打开计算机的扬声器用什么函数

C本身没有让声卡发声的函数,这个需要平台,比如Windows下的directsound。 你要做的是利用C语言调用这些api。

如何用C语言(或C++)关闭声卡驱动和打开声卡驱动,求代码

你是说控制声卡声音吗?

直接用c很麻烦,不过有个变通的方法。

搜索nircmd,下载,这个命令有很多功能,可以使用这个:

增大系统音量2000个单位值 (最大65535) nircmd.exe changesysvolume 2000

降低系统音量5000个单位值 (out of 65535) nircmd.exe changesysvolume -5000

设置系统音量为最大 nircmd.exe setsysvolume 65535

系统音量静音 nircmd.exe mutesysvolume 1

取消系统静音 nircmd.exe mutesysvolume 0

改变当前系统静音设置(静音和非静音之间切换) nircmd.exe mutesysvolume 2

main()

{

system("nircmd.exe mutesysvolume 1");

}

这样就可以是上卡静音了。

如何用C语言播放音乐

首先要解压缩音频文件,这些文件的格式一般都是标准化的可以在网上面找到解压方法.

然后把解压得到的音频数据输出到声卡,这里需要硬件I/O操作的知识.把数据送到特定的I/O端口,然后声卡才能发声.