1

I'm using MCI to do some sound-related stuff, and everything works, except I cannot alter the volume. I have the following code:

mciSendStringA("open res/theme.wav type waveaudio alias maintheme", nullptr, 0, nullptr);
MCIERROR error = mciSendStringA("setaudio maintheme volume to 50", nullptr, 0, nullptr);

error is 261. The program works fine but the volume does not change. Any suggestions on what's wrong? (Two pages of google searching and there's nothing)

4 Answers4

1

According to the documentation:

setaudio command

The setaudio command sets values associated with audio playback and capture. Digital-video and VCR devices recognize this command.

...

lpszAudio
Flag for audio playback and capture. The following table lists device types that recognize the setaudio command and the flags used by each type.

digitalvideo
vcr

Your audio playback is using a waveaudio device, which does not support the setaudio command.

In order to set the volume of audio playback, you will have to switch to the WaveOut API for playback, then you can use waveOutSetVolume().

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0

Error 261 according to these error codes is an MCIERR_UNRECOGNIZED_COMMAND error. The error in itself is pretty self explanatory: You are sending an unrecognized command.

Nooble
  • 562
  • 7
  • 17
0

This isn't really a solution but just a workaround. It works perfectly fine if you use mp3 files. To load an mp3 file:

mciSendStringA("open [file].mp3 type mpegvideo alias [soundalias]", nullptr, 0, nullptr);

The setaudio instruction will then work. However, I don't know if there's a way of getting this to work with wav files...

0

I also ran into a similar issue earlier, I was able to Play/Pause/Loop mp3's with MCI. But failed to Adjust the volume. But Adding a WaveOut API solved problem.

HWAVEOUT hwo;
waveOutSetVolume(hwo, dwVolume);

where dwVolume according to microsoft docs can be from 0x0000 to 0xFFFF
and if the device supports left and right audio playback 0xFFFF becomes 0xFFFFFFFF and vice versa

for eg:

SILENT = 0,

LOW = 858993459,

NORMAL = 1717986918,

MEDIUM = -1717986919,

HIGH = -858993460,

VERY HIGH = -1

(these sample values are decimals converted from its original hex value such as 0x11111111. use long long int when declaring variables)

A5H1Q
  • 544
  • 7
  • 15