简体   繁体   中英

SDL mute volume in C++

How can i mute volume with SDL in C++?
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. 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.

Environment:
Debian Sqeeze
Package: libsdl1.2-dev
Version: 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. 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). 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"); . 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. If you need to support Windows, you could write your #ifdef _WIN32/#else/#endif block inside it.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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