bool Win32RedBookDevice::getVolume(F32 * volume) { if(!mAcquired) { setLastError("Device has not been acquired"); return(false); } if(!mVolumeInitialized) { setLastError("Volume failed to initialize"); return(false); } U32 vol = 0; if(mUsingMixer) { mixerGetControlDetails(mVolumeDeviceId, &mMixerVolumeDetails, MIXER_GETCONTROLDETAILSF_VALUE); vol = mMixerVolumeValue.dwValue; } else auxGetVolume(mAuxVolumeDeviceId, (unsigned long *)&vol); vol &= 0xffff; *volume = F32(vol) / 65535.f; setLastError(""); return(true); }
void CD_FindCDAux(void) { UINT NumDevs,counter; MMRESULT Result; AUXCAPS Caps; CD_ID = -1; if (!COM_CheckParm("-usecdvolume")) return; NumDevs = auxGetNumDevs(); for(counter=0;counter<NumDevs;counter++) { Result = auxGetDevCaps(counter,&Caps,sizeof(Caps)); if (!Result) // valid { if (Caps.wTechnology == AUXCAPS_CDAUDIO) { CD_ID = counter; auxGetVolume(CD_ID,&CD_OrigVolume); return; } } } }
void Win32RedBookDevice::openVolume() { setLastError(""); // first attempt to get the volume control through the mixer API S32 i; for(i = mixerGetNumDevs() - 1; i >= 0; i--) { // open the mixer if(mixerOpen((HMIXER*)&mVolumeDeviceId, i, 0, 0, 0) == MMSYSERR_NOERROR) { MIXERLINE lineInfo; memset(&lineInfo, 0, sizeof(lineInfo)); lineInfo.cbStruct = sizeof(lineInfo); lineInfo.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC; // get the cdaudio line if(mixerGetLineInfo(mVolumeDeviceId, &lineInfo, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR) { MIXERLINECONTROLS lineControls; MIXERCONTROL volumeControl; memset(&lineControls, 0, sizeof(lineControls)); lineControls.cbStruct = sizeof(lineControls); lineControls.dwLineID = lineInfo.dwLineID; lineControls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; lineControls.cControls = 1; lineControls.cbmxctrl = sizeof(volumeControl); lineControls.pamxctrl = &volumeControl; memset(&volumeControl, 0, sizeof(volumeControl)); volumeControl.cbStruct = sizeof(volumeControl); // get the volume control if(mixerGetLineControls(mVolumeDeviceId, &lineControls, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR) { memset(&mMixerVolumeDetails, 0, sizeof(mMixerVolumeDetails)); mMixerVolumeDetails.cbStruct = sizeof(mMixerVolumeDetails); mMixerVolumeDetails.dwControlID = volumeControl.dwControlID; mMixerVolumeDetails.cChannels = 1; mMixerVolumeDetails.cbDetails = sizeof(mMixerVolumeValue); mMixerVolumeDetails.paDetails = &mMixerVolumeValue; memset(&mMixerVolumeValue, 0, sizeof(mMixerVolumeValue)); // query the current value if(mixerGetControlDetails(mVolumeDeviceId, &mMixerVolumeDetails, MIXER_GETCONTROLDETAILSF_VALUE) == MMSYSERR_NOERROR) { mUsingMixer = true; mVolumeInitialized = true; mOriginalVolume = mMixerVolumeValue.dwValue; return; } } } } mixerClose((HMIXER)mVolumeDeviceId); } // try aux for(i = auxGetNumDevs() - 1; i >= 0; i--) { AUXCAPS caps; auxGetDevCaps(i, &caps, sizeof(AUXCAPS)); if((caps.wTechnology == AUXCAPS_CDAUDIO) && (caps.dwSupport & AUXCAPS_VOLUME)) { mAuxVolumeDeviceId = i; mVolumeInitialized = true; mUsingMixer = false; auxGetVolume(i, (unsigned long *)&mOriginalVolume); return; } } setLastError("Volume failed to initialize"); }
int playWAVEFile(const char *lpszWAVEFileName) { static int init = 0; static HWND hwStopper; static int counter = 0; DWORD dwReturn; MCI_OPEN_PARMS mciOpenParms; MCI_PLAY_PARMS mciPlayParms; // Open the device by specifying the device and filename. // MCI will choose a device capable of playing the specified file. if(!init){ WNDCLASS wc = { 0, /* UINT style; */ SoundStopper, /*WNDPROC lpfnWndProc; */ 0, /*int cbClsExtra; */ 0, /*int cbWndExtra; */ NULL, /*HINSTANCE hInstance; */ NULL, /*HICON hIcon; */ NULL, /*HCURSOR hCursor; */ NULL, /*HBRUSH hbrBackground; */ NULL, /*LPCTSTR lpszMenuName; */ "SoundStopperClass", /*LPCTSTR lpszClassName; */ }; ATOM atom; wc.hInstance = (HINSTANCE)GetModuleHandle(NULL);; if(!(atom = RegisterClass(&wc)) || !(hwStopper = CreateWindow((LPCTSTR)atom, "SoundStopper", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL))){ MsgBoxErr(); return 1; } init = 1; } { WCHAR alias[5]; alias[0] = '0' + counter % 10; alias[1] = '0' + counter / 10 % 10; alias[2] = '0' + counter / 10 / 10 % 10; alias[3] = '\0'; counter++; mciOpenParms.lpstrDeviceType = "waveaudio"; mciOpenParms.lpstrElementName = lpszWAVEFileName; mciOpenParms.lpstrAlias = alias; if (dwReturn = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS, (DWORD)(LPVOID) &mciOpenParms)) { // Failed to open device. Don't close it; just return error. return (dwReturn); } // The device opened successfully; get the device ID. wDeviceID = mciOpenParms.wDeviceID; } { UINT num; DWORD vol; num = waveOutGetNumDevs(); if(num) auxGetVolume(0, &vol); num; } // Begin playback. The window procedure function for the parent // window will be notified with an MM_MCINOTIFY message when // playback is complete. At this time, the window procedure closes // the device. mciPlayParms.dwCallback = (DWORD) hwStopper; if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms)) { mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL); return (dwReturn); } return (0L); }