简体   繁体   English

C ++中的SDL静音音量

[英]SDL mute volume in C++

How can i mute volume with SDL in C++? 如何在C ++中使用SDL静音音量?
The speakers are connected into the headphone jack socket. 扬声器已连接到耳机插孔。 If volume unmuted i can hear background noise, but when i mute (with 'amixer set Headphone mute') it stops. 如果音量未静音,我会听到背景噪音,但是当我静音(使用“ axerer设置耳机静音”)时,它会停止。 I tried Mix_VolumeMusic() and Mix_Volume() to set the volume to zero to achieve the same, but it just change the music voulme, the noise is still there. 我尝试将Mix_VolumeMusic()和Mix_Volume()设置为零以实现相同的音量,但是它只是改变了音乐的声音,噪音仍然存在。

Environment: 环境:
Debian Sqeeze Debian Sqeeze
Package: libsdl1.2-dev 软件包:libsdl1.2-dev
Version: 1.2.14-6.1 版本:1.2.14-6.1

I don't think SDL has a mute function beyond what you're doing, although I'm not even seeing those functions in the documentation on the libsdl.org website. 尽管我什至在libsdl.org网站上的文档中都没有看到这些功能,但我认为SDL没有静音功能。 From looking at the API, I'm guessing it just controls an internal software mixer (PCM volume control is in the SDL 1.3 wishlist), but you can check this by adjusting the volume and bringing up the system volume settings with alsamixer (<Esc> key to exit). 通过查看API,我猜想它仅控制一个内部软件混音器(PCM音量控制在SDL 1.3愿望清单中),但是您可以通过调整音量并使用alsamixer调出系统音量设置(<Esc >键退出)。 A dirty workaround would be to use a system call to execute the amixer program. 肮脏的解决方法是使用系统调用来执行混合器程序。 You'll need to have #include <stdlib.h> and run system("amixer set Headphone mute"); 您需要具有#include <stdlib.h>并运行system("amixer set Headphone mute"); . Beyond that, I would look into something else like alsa for a real mute and write your own mute function, so it can be easily replaced later. 除此之外,我还会考虑使用alsa等其他工具来实现真正的静音,并编写自己的静音功能,以便以后可以轻松替换。 If you need to support Windows, you could write your #ifdef _WIN32/#else/#endif block inside it. 如果需要支持Windows,则可以在其中写入#ifdef _WIN32/#else/#endif块。

While I don't advocate fixing software problems with hardware, it looks like a better sound card might be in order. 虽然我不主张通过硬件来解决软件问题,但似乎可能需要更好的声卡。 Also, you'll probably get better sound if you're using the rear jacks on a computer than the front ones. 另外,如果您在计算机上使用后部插孔,则可能比前部插孔获得更好的声音。 I've always picked up a lot of noise from the thin sound cables that plug into the motherboard. 我总是从插入主板的细声音电缆中拾取很多噪音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM