From: Babar S. <bab...@ya...> - 2003-08-06 09:10:54
|
Steve, Please check this might help you for Sound Volume and Recording Volume control for Open Sound System. Regards, Babar Shafiq Nazmi //Open Sound System #ifdef HAS_OSS #define DEFAULT_MIXER "/dev/mixer" int mixerDev; int mixerRecChan; int savedMixerRecChan; int ossRecVol; int ossPlayVol; #endif #ifdef HAS_OSS voice_function(string args) { mixerDev = -1; // make sure mixer isn't disabled if (args=="no-sound-mixer") return TRUE; string mixerDeviceName = DEFAULT_MIXER; if (args=="sound-mixer") mixerDeviceName = args; mixerDev = ::open(mixerDeviceName, O_RDWR); if (mixerDev < 0) { cout << "warning: Cannot open mixer device " << mixerDeviceName << ": " << ::strerror(errno) << endl; return TRUE; } char * mixerChanNames[] = SOUND_DEVICE_NAMES; int numMixerChans = SOUND_MIXER_NRDEVICES; // get the current record channel setting, and save it if (::ioctl(mixerDev, SOUND_MIXER_READ_RECSRC, &savedMixerRecChan) < 0) { cout << "warning: cannot get current mixer record channels" << endl; savedMixerRecChan = -1; } // if the user specified a record channel, then find it // otherwise, find the currently select record channel if (args=="sound-recchan") { string mixerRecChanName = args; int i; for (i = 0; i < numMixerChans; i++) if (mixerRecChanName *= mixerChanNames[i]) break; if (i == numMixerChans) { cout << "error: Cannot find record mixer channel " << mixerDeviceName << endl; return FALSE; } mixerRecChan = i; } else { int i; for (i = 0; i < numMixerChans; i++) if (savedMixerRecChan & (1 << i)) break; if (i == numMixerChans) mixerRecChan = SOUND_MIXER_MIC; else mixerRecChan = i; } string volStr; if (args=="sound-recvol") volStr = args; else if (args=="recvol") volStr = args; if (volStr.empty()) { ::ioctl(mixerDev, MIXER_READ(mixerRecChan), &ossRecVol); ossRecVol &= 0xff; } else { ossRecVol = (unsigned)atoi(volStr.c_str()); int volVal = ossRecVol | (ossRecVol << 8); ::ioctl(mixerDev, MIXER_WRITE(mixerRecChan), &volVal); } if (args=="sound-playvol") volStr = args; else if (args=="playvol") volStr = args; if (volStr.empty()) { ::ioctl(mixerDev, SOUND_MIXER_READ_VOLUME, &ossPlayVol); ossPlayVol &= 0xff; } else { ossPlayVol = (unsigned) atoi(volStr.c_str()); int volVal = ossPlayVol | (ossPlayVol << 8); ::ioctl(mixerDev, SOUND_MIXER_WRITE_PCM, &volVal); } } }//end of voice_function #else //for Win32 Code will be here voice_function(string args) { . . . } #endif ===== God is a great Programmer __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com |