コード例 #1
0
ファイル: mic.c プロジェクト: boundarydevices/bdScript
static int openReadFd(int* pBlkSize,int channels)
{
	int readFd = open( "/dev/dsp", O_RDONLY );
	int const format = AFMT_S16_LE;
	int speed = FMT_dwSamplesPerSec;
	int recordLevel = 0;
	int recSrc;
	int recMask;
	audio_buf_info bufInfo ;
	int biResult;

	if (readFd<0) return readFd;
	ioctl( readFd, SNDCTL_DSP_SYNC, 0 );

	if( 0 != ioctl( readFd, SNDCTL_DSP_SETFMT, &format) )
		perror( "set record format" );

	if( 0 != ioctl( readFd, SNDCTL_DSP_CHANNELS, &channels ) )
		fprintf( stderr, ":ioctl(SNDCTL_DSP_CHANNELS)\n" );
	printf( "channels:%i\n",channels);

	if( 0 != ioctl( readFd, SNDCTL_DSP_SPEED, &speed ) )
		fprintf( stderr, ":ioctl(SNDCTL_DSP_SPEED):%u:%m\n", speed );
	printf( "speed:%i\n",speed);

	if( 0 != ioctl( readFd, MIXER_READ( SOUND_MIXER_MIC ), &recordLevel ) )
		perror( "get record level" );

	recordLevel = 100 ;
//	if( 0 != ioctl( readFd, MIXER_WRITE( SOUND_MIXER_MIC ), &recordLevel ) )
//		perror( "set record level" );

//	if( 0 != ioctl( readFd, MIXER_READ( SOUND_MIXER_MIC ), &recordLevel ) )
//		perror( "get record level" );

	if( 0 != ioctl( readFd, MIXER_READ( SOUND_MIXER_RECSRC ), &recSrc ) )
		perror( "get record srcs" );

	if( 0 != ioctl( readFd, MIXER_READ( SOUND_MIXER_RECMASK ), &recMask ) )
		perror( "get record mask" );

	if (0 != ioctl( readFd,SNDCTL_DSP_GETBLKSIZE,pBlkSize) ) {
                perror(" Optaining DSP's block size");
        }

	biResult = ioctl( readFd, SNDCTL_DSP_GETISPACE, &bufInfo );
	if( 0 == biResult ) {
//		unsigned	numReadFrags;
//		unsigned	readFragSize;
//		unsigned	maxReadBytes;
//		numReadFrags = bufInfo.fragstotal ;
//		readFragSize = bufInfo.fragsize ;
//		maxReadBytes = (numReadFrags_*readFragSize_);
		printf("frags cnt:%i, frag size:%i\r\n",bufInfo.fragstotal,bufInfo.fragsize);
	} else {
		perror( "getISpace" );
	}
	return readFd;
}
コード例 #2
0
int
oss_audio_get_ogain(audio_desc_t ad)
{
	int volume;

        UNUSED(ad); assert(devices[ad].audio_wfd > 0);

	if (ioctl(devices[ad].mixer_wfd, MIXER_READ(SOUND_MIXER_PCM),     &volume) == -1
	&&  ioctl(devices[ad].mixer_wfd, MIXER_READ(SOUND_MIXER_SPEAKER), &volume) == -1
	&&  ioctl(devices[ad].mixer_wfd, MIXER_READ(SOUND_MIXER_OGAIN),   &volume) == -1) {
		perror("Getting volume");
	}
	return volume & 0x000000ff; /* Extract left channel volume */
}
コード例 #3
0
ファイル: oplay.c プロジェクト: ghthor/hxtools
static void mixer_proc_ctl(int mixer_fd, const char *ctl, const char *vol)
{
    int arg, i, devmask;
    if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0) {
        perror("SOUND_MIXER_READ_DEVMASK");
        exit(EXIT_FAILURE);
    }

    for (i = 0; i < SOUND_MIXER_NRDEVICES &&
            strcmp(mixer_ctlname[i], ctl) != 0; ++i)
        ;

    if (i >= SOUND_MIXER_NRDEVICES) {
        fprintf(stderr, "Invalid recording source: %s\n", ctl);
        exit(EXIT_FAILURE);
    }

    if (vol == NULL) {
        if (ioctl(mixer_fd, MIXER_READ(i), &arg) < 0) {
            if (errno == EINVAL)
                fprintf(stderr, "Invalid mixer control: %s\n",
                        mixer_ctlname[i]);
            else
                perror("MIXER_READ");
            exit(EXIT_FAILURE);
        }
        printf("%s: L=%d%% R=%d%%\n", mixer_ctlname[i],
               arg & 0xFF, (arg >> 8) & 0xFF);
    } else if (*vol == '+' || *vol == '-') {
コード例 #4
0
int
oss_audio_get_igain(audio_desc_t ad)
{
	int volume;
	int which_port;

	if (devices[ad].is_ac97) {
		which_port = SOUND_MIXER_IGAIN;
	} else if (devices[ad].is_latemodel_opensound) {
	    which_port = SOUND_MIXER_RECLEV;
	} else {
		switch (iport) {
		case AUDIO_MICROPHONE:
			which_port = SOUND_MIXER_MIC;
			break;
		case AUDIO_LINE_IN:
			which_port = SOUND_MIXER_LINE;
			break;
		case AUDIO_CD:
			which_port = SOUND_MIXER_CD;
			break;
		default:
			printf("ERROR: Unknown iport in audio_set_igain!\n");
			abort();
	    	}
	}

        UNUSED(ad); assert(devices[ad].mixer_rfd > 0); assert(ad < OSS_MAX_DEVICES);

	if (ioctl(devices[ad].mixer_rfd, MIXER_READ(which_port), &volume) == -1) {
		perror("Getting gain");
	}
	debug_msg("getting igain; port=%d is_ac97=%d is_latemodel_opensound=%d vol=%d %d\n", which_port, devices[ad].is_ac97, devices[ad].is_latemodel_opensound, volume, volume & 0xff);
	return volume & 0xff;
}
コード例 #5
0
void EzxVolumeService::adjustVolume(int leftChannel, int rightChannel, AdjustType adjust)
{
    int mixerFd = open("/dev/mixer", O_RDWR);
    if (mixerFd >= 0) {
        int leftright, left, right;

        if (adjust == Relative) {
            ioctl(mixerFd, MIXER_READ(SOUND_MIXER_OGAIN), &leftright);

            left = leftright; 
            right = leftright; 

            left = qBound(0, left + leftChannel, 100);
            right = qBound(0, right + rightChannel, 100);

        } else {
            left = leftChannel;
            right = rightChannel;
        }

        leftright = (left + right) >> 1;
        int input = leftright;
        m_d->currVolume = leftright;
        ioctl(mixerFd, MIXER_WRITE(SOUND_MIXER_OGAIN), &leftright);       
        ioctl(mixerFd, MIXER_WRITE(SOUND_MIXER_IGAIN), &input);
        close(mixerFd);
    }
コード例 #6
0
ファイル: volume-impl.c プロジェクト: andrejlamov/mylxpanel
static void
get_current_levels() 
{
	ioctl(mixer_fd, MIXER_READ(SOUND_MIXER_VOLUME), &tmpvol);
	orig.mainvol = tmpvol.left;
	gtk_adjustment_set_value(GTK_ADJUSTMENT(vol_adjustment), (double) tmpvol.left);
}
コード例 #7
0
ファイル: oss.c プロジェクト: LaughingAngus/linphone-vs2008
static int oss_get_level(MSSndCard *card, MSSndCardMixerElem e)
{
	OssData *d=(OssData*)card->data;
	int p=0,mix_fd;
	int osscmd;
	if (d->mixdev==NULL) return -1;
	switch(e){
		case MS_SND_CARD_MASTER:
			osscmd=SOUND_MIXER_VOLUME;
		break;
		case MS_SND_CARD_CAPTURE:
			osscmd=SOUND_MIXER_IGAIN;
		break;
		case MS_SND_CARD_PLAYBACK:
			osscmd=SOUND_MIXER_PCM;
		break;
		default:
			ms_warning("oss_card_get_level: unsupported command.");
			return -1;
	}
	mix_fd = open(d->mixdev, O_RDONLY);
	ioctl(mix_fd,MIXER_READ(osscmd), &p);
	close(mix_fd);
	return p>>8;
}
コード例 #8
0
ファイル: oplay.c プロジェクト: ghthor/hxtools
static int mixer_display_all(int mixer_fd)
{
    int arg, i, devmask;
    if (ioctl(mixer_fd, SOUND_MIXER_READ_DEVMASK, &devmask) < 0) {
        perror("SOUND_MIXER_READ_DEVMASK");
        exit(EXIT_FAILURE);
    }

    for (i = 0; i < SOUND_MIXER_NRDEVICES; ++i) {
        if (devmask & (1 << i)) {
            if (ioctl(mixer_fd, MIXER_READ(i), &arg) < 0) {
                if (errno == EINVAL) {
                    fprintf(stderr, "Invalid mixer control: %s\n",
                            mixer_ctlname[i]);
                } else {
                    perror("MIXER_READ");
                }
                exit(EXIT_FAILURE);
            }

            printf("%-8s   L=%3d%%   R=%3d%%\n", mixer_ctlname[i],
                   arg & 0xFF, (arg >> 8) & 0xFF);
        }
    }
    return devmask;
}
コード例 #9
0
ファイル: ao_oss.c プロジェクト: basinilya/mplayer
// to set/get/query special features/parameters
static int control(int cmd,void *arg){
    switch(cmd){
	case AOCONTROL_SET_DEVICE:
	    dsp=(char*)arg;
	    return CONTROL_OK;
	case AOCONTROL_GET_DEVICE:
	    *(char**)arg=dsp;
	    return CONTROL_OK;
#ifdef SNDCTL_DSP_GETFMTS
	case AOCONTROL_QUERY_FORMAT:
	{
	    int format;
	    if (!ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &format))
		if ((unsigned int)format & (unsigned long)arg)
	    	    return CONTROL_TRUE;
	    return CONTROL_FALSE;
	}
#endif
	case AOCONTROL_GET_VOLUME:
	case AOCONTROL_SET_VOLUME:
	{
	    ao_control_vol_t *vol = (ao_control_vol_t *)arg;
	    int fd, v, devs;

	    if(AF_FORMAT_IS_AC3(ao_data.format))
		return CONTROL_TRUE;

	    if ((fd = open(oss_mixer_device, O_RDONLY)) != -1)
	    {
		if (ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devs) == -1)
		    return CONTROL_ERROR;
		if (devs & (1 << oss_mixer_channel))
		{
		    if (cmd == AOCONTROL_GET_VOLUME)
		    {
		        if (ioctl(fd, MIXER_READ(oss_mixer_channel), &v) == -1)
			    return CONTROL_ERROR;
			vol->right = (v & 0xFF00) >> 8;
			vol->left = v & 0x00FF;
		    }
		    else
		    {
		        v = ((int)vol->right << 8) | (int)vol->left;
			if (ioctl(fd, MIXER_WRITE(oss_mixer_channel), &v) == -1)
			    return CONTROL_ERROR;
		    }
		}
		else
		{
		    close(fd);
		    return CONTROL_ERROR;
		}
		close(fd);
		return CONTROL_OK;
	    }
	}
コード例 #10
0
ファイル: VolumeControl.cpp プロジェクト: sumitbirla/carpc
int VolumeControl::get_volume()
{   
   if ( ioctl(mixer_fd, MIXER_READ(SOUND_MIXER_VOLUME), &volume) < 0 ) 
   {
      fprintf(stderr, "Can't obtain current volume settings \n");
      return 0;
   }
   
   return volume.left;
}
コード例 #11
0
ファイル: cdaudio.c プロジェクト: sedwards/xmms3
static void oss_get_volume(int *l, int *r, int mixer_line)
{
	int fd, v;

	fd = open(DEV_MIXER, O_RDONLY);
	if (fd != -1)
	{
		ioctl(fd, MIXER_READ(mixer_line), &v);
		*r = (v & 0xFF00) >> 8;
		*l = (v & 0x00FF);
		close(fd);
	}
コード例 #12
0
ファイル: main.c プロジェクト: engine12/ebindkeys-zipit
void onVolume(int dev, int bIncrease){
	
	int mixernum=open("/dev/mixer", O_RDWR);
	//first get the volume 
	int vol;
	ioctl(mixernum, MIXER_READ(dev), &vol);
	vol=vol & 0xff;
	bIncrease?vol++:vol--;
	
	int i = vol | vol << 8 ;
	ioctl(mixernum, MIXER_WRITE(dev), &i);
	
	close(mixernum);	
}
コード例 #13
0
ファイル: volume.c プロジェクト: AmatCoder/fbpanel2
static int
oss_get_volume(volume_priv *c)
{
    int volume;

    ENTER;
    if (ioctl(c->fd, MIXER_READ(c->chan), &volume)) {
        ERR("volume: can't get volume from /dev/mixer\n");
        RET(0);
    }
    volume &= 0xFF;
    DBG("volume=%d\n", volume);
    RET(volume);
}
コード例 #14
0
ファイル: Emix.c プロジェクト: Limsik/e17
int
read_volume(int channel)
{
   unsigned char       lrvl[4];

   if (ioctl(fd_mixer, MIXER_READ(channels[channel].id), lrvl) == -1)
     {
#ifdef debug
	fprintf(stderr, "Error reading volume for channel #%d\n", channel);
#endif
	return 0;
     }
   channels[channel].value = (100 - (lrvl[0] + lrvl[1]) / 2) / 5;
   return channels[channel].value;
}
コード例 #15
0
int V4LRadioControl::getVol()
{
    int fd = ::open( "/dev/mixer", O_RDWR, 0 );
    if ( fd >= 0 ) {
        int volume = 0;
        ::ioctl( fd, MIXER_READ(SOUND_MIXER_VOLUME), &volume );
        int left = ( volume & 0xFF );
        int right = ( ( volume >> 8 ) & 0xFF );
        if ( left > right )
            vol = left;
        else
            vol = right;
        ::close( fd );
        return vol;
    }
コード例 #16
0
ファイル: evolume.cpp プロジェクト: GustavoMOG/ede12
void get_device_info(int mixer_dev, Fl_Slider *sl, Fl_Slider *bal, 
		     Fl_Check_Button *ck, int device)
{
    unsigned int devmask, recmask, recsrc, stereo;
    volume real_volume;
    
    real_volume.left = real_volume.right = 0;
    devmask = recmask = recsrc = stereo = 0;
    
    if (ioctl(mixer_dev, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) 
	fprintf(stderr, "Read devmask failed.\n");
    if (devmask & (1 << (device))) 
	sl->activate();
    else 
	sl->deactivate();

    if (ioctl(mixer_dev, SOUND_MIXER_READ_STEREODEVS, &stereo) == -1) 
	fprintf(stderr, "Read recsrc failed.\n"); 
    if ( stereo & (1 << (device) ) ) bal->activate();		    
    else ck->deactivate();		    
		    
    if (ioctl(mixer_dev, SOUND_MIXER_READ_RECMASK, &recmask) == -1) 
	fprintf(stderr, "Read recmask failed.\n");
    if ( recmask & (1 << (device) ) ) ck->activate();		    
    else ck->deactivate();
    
    if (ioctl(mixer_dev, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) 
	fprintf(stderr, "Read recsrc failed.\n"); 
    if ( recsrc & (1 << (device) ) ) ck->set();		    
    else ck->clear();		    
    
    if ( ioctl(mixer_dev, MIXER_READ(device), &real_volume) < 0 ) {
        fprintf(stderr, "Can't obtain current volume settings.\n");  
    }

    float volume = real_volume.left + real_volume.right;

    float balance = 0; 
    balance = ( (1.0 * (unsigned char)real_volume.right ) / 
		(1.0 * ((unsigned char)real_volume.left + (unsigned char)real_volume.right)) );

    if (volume == 0)
	volume=1;
    if (balance < 0)
	balance=0.5;
    sl->value(volume);
    bal->value(balance);
}
コード例 #17
0
ファイル: mixer.c プロジェクト: bsdplus/fluxbsd
static int mixer_get(int i)
{
	static char rep = 0;
	int val = -1;

	if (ioctl(mixer_fd, MIXER_READ(i), &val) == -1) {
		if (!rep) {
			NORM_ERR("mixer ioctl: %s", strerror(errno));
		}
		rep = 1;
		return 0;
	}
	rep = 0;

	return val;
}
コード例 #18
0
ファイル: audlinux_oss.cpp プロジェクト: muromec/qtopia-ezx
//Device specific method to get/set the devices current volume.
UINT16 CAudioOutLinux::_GetVolume() const
{
    int nVolume      = 0;
    int nRetVolume   = 0;
    int nLeftVolume  = 0;
    int nRightVolume = 0;
    
    if (::ioctl( m_nMixerID, MIXER_READ(HX_VOLUME), &nVolume) < 0)
    {
        nRetVolume = 0;
    }
    nLeftVolume  = (nVolume & 0x000000ff); 
    nRightVolume = (nVolume & 0x0000ff00) >> 8;

    //Which one to use? Average them?
    nRetVolume = nLeftVolume ;

    return nRetVolume; 
}
コード例 #19
0
static PyObject *
oss_mixer_get(oss_mixer_t *self, PyObject *args)
{
    int channel, volume;

    /* Can't use _do_ioctl_1 because of encoded arg thingy. */
    if (!PyArg_ParseTuple(args, "i:get", &channel))
        return NULL;

    if (channel < 0 || channel > SOUND_MIXER_NRDEVICES) {
        PyErr_SetString(OSSAudioError, "Invalid mixer channel specified.");
        return NULL;
    }

    if (ioctl(self->fd, MIXER_READ(channel), &volume) == -1)
        return PyErr_SetFromErrno(PyExc_IOError);

    return Py_BuildValue("(ii)", volume & 0xff, (volume & 0xff00) >> 8);
}
コード例 #20
0
ファイル: volume.c プロジェクト: AreaScout/mupen64plus-odroid
/* volGet
 *  Returns volume of PCM channel as a percentage (0-100).
 *  Returns 0 on error.
 */
int volGet(void)
{
    int vol, ret;
    int mixerfd = open("/dev/mixer", O_RDONLY);

    if(mixerfd < 0)
    {
        perror("/dev/mixer");
        return 0;
    }

    ret = ioctl(mixerfd, MIXER_READ(SOUND_MIXER_PCM), &vol);
    if(ret < 0)
        perror("Reading PCM volume");

    close(mixerfd);

    return vol & 0xff; // just return the left channel
}
コード例 #21
0
ファイル: OSS.c プロジェクト: wosayttn/NuMaker_NuWicam_RDK
ERRCODE
OSS_PlayGetVolume(
	uint32_t 		*pu32Volume		// [out] Current volume
) {
	int32_t i32Volume;

	if (pu32Volume == NULL)
		return ERR_OSS_NULL_POINTER;

	FUN_MUTEX_LOCK(&s_sOSSFunMutex);

	if (s_i32DSPFD < 0) {
		FUN_MUTEX_UNLOCK(&s_sOSSFunMutex);
		return ERR_OSS_DEV;
	}

	ioctl(s_i32MixerFD, MIXER_READ(SOUND_MIXER_VOLUME), &i32Volume);
	i32Volume = (i32Volume & 0x3f);
	*pu32Volume = i32Volume;
	FUN_MUTEX_UNLOCK(&s_sOSSFunMutex);
	return ERR_OSS_NONE;
}
コード例 #22
0
ファイル: mix.c プロジェクト: csabahenk/shell-fm
signed adjust(signed deviation, int device) {
	signed fd = open("/dev/mixer", O_RDONLY | O_NONBLOCK), volume;

	if(fd == -1) {
		fprintf(stderr, "Can't open mixer device. %s.\n", strerror(errno));
		return -1;
	}
	else {
		/* Read volume. */
		ioctl(fd, MIXER_READ(device), & volume);

		volume += deviation;
		
		if(volume < 0)
			volume = 0;
		else if(volume > 0xFFFF)
			volume = 0xFFFF;

		/* Write volume. */
		ioctl(fd, MIXER_WRITE(device), & volume);

		return volume;
	}
}
コード例 #23
0
ファイル: muted.c プロジェクト: OPSF/uClinux
static int getvol(void)
{
	int vol;

	if (ioctl(mixfd, MIXER_READ(mixchan), &vol)) {
#else
static float getvol(void)
{
	float volumeL, volumeR, vol;
	OSStatus err;
	AudioDeviceID device;
	UInt32 size;
	UInt32 channels[2];

	size = sizeof(device);
	err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
	size = sizeof(channels);
	if (!err) 
		err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
	size = sizeof(vol);
	if (!err)
		err = AudioDeviceGetProperty(device, channels[0], false, kAudioDevicePropertyVolumeScalar, &size, &volumeL);
	if (!err)
		err = AudioDeviceGetProperty(device, channels[1], false, kAudioDevicePropertyVolumeScalar, &size, &volumeR);
	if (!err)
		vol = (volumeL < volumeR) ? volumeR : volumeL;
	else {
#endif
		fprintf(stderr, "Unable to read mixer volume: %s\n", strerror(errno));
		return -1;
	}
	return vol;
}

#ifndef __Darwin__
static int setvol(int vol)
#else
static int setvol(float vol)
#endif
{
#ifndef __Darwin__
	if (ioctl(mixfd, MIXER_WRITE(mixchan), &vol)) {
#else	
	float volumeL = vol;
	float volumeR = vol;
	OSStatus err;
	AudioDeviceID device;
	UInt32 size;
	UInt32 channels[2];

	size = sizeof(device);
	err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &device);
	size = sizeof(channels);
	err = AudioDeviceGetProperty(device, 0, false, kAudioDevicePropertyPreferredChannelsForStereo, &size, &channels);
	size = sizeof(vol);
	if (!err)
		err = AudioDeviceSetProperty(device, 0, channels[0], false, kAudioDevicePropertyVolumeScalar, size, &volumeL);
	if (!err)
		err = AudioDeviceSetProperty(device, 0, channels[1], false, kAudioDevicePropertyVolumeScalar, size, &volumeR); 
	if (err) {
#endif

		fprintf(stderr, "Unable to write mixer volume: %s\n", strerror(errno));
		return -1;

	}
	return 0;
}

#ifndef __Darwin__
static int oldvol = 0;
static int mutevol = 0;
#else
static float oldvol = 0;
static float mutevol = 0;
#endif

#ifndef __Darwin__
static int mutedlevel(int orig, int mutelevel)
{
	int l = orig >> 8;
	int r = orig & 0xff;
	l = (float)(mutelevel) * (float)(l) / 100.0;
	r = (float)(mutelevel) * (float)(r) / 100.0;

	return (l << 8) | r;
#else
static float mutedlevel(float orig, float mutelevel)
{
	float master = orig;
	master = mutelevel * master / 100.0;
	return master;
#endif
	
}

static void mute(void)
{
#ifndef __Darwin__
	int vol;
	int start;
	int x;
#else
	float vol;
	float start = 1.0;
	float x;
#endif
	vol = getvol();
	oldvol = vol;
	if (smoothfade)
#ifdef __Darwin__ 
		start = mutelevel;
#else
		start = 100;
	else
コード例 #24
0
ファイル: muted.c プロジェクト: cfhb/vlink-cti
static int getvol(void)
{
	int vol;

	if (ioctl(mixfd, MIXER_READ(mixchan), &vol)) {
#else
static float getvol(void)
{
	float volumeL, volumeR, vol;
	OSStatus err;
	AudioDeviceID device;
	UInt32 size;
	UInt32 channels[2];
	AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
	AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard };
	AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, };

	size = sizeof(device);
	err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device);
	size = sizeof(channels);
	if (!err) {
		err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels);
	}
	size = sizeof(vol);
	if (!err) {
		VolumeAddr.mElement = channels[0];
		err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeL);
	}
	if (!err) {
		VolumeAddr.mElement = channels[1];
		err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeR);
	}
	if (!err)
		vol = (volumeL < volumeR) ? volumeR : volumeL;
	else {
#endif
		fprintf(stderr, "Unable to read mixer volume: %s\n", strerror(errno));
		return -1;
	}
	return vol;
}

#ifndef __Darwin__
static int setvol(int vol)
#else
static int setvol(float vol)
#endif
{
#ifndef __Darwin__
	if (ioctl(mixfd, MIXER_WRITE(mixchan), &vol)) {
#else	
	float volumeL = vol;
	float volumeR = vol;
	OSStatus err;
	AudioDeviceID device;
	UInt32 size;
	UInt32 channels[2];
	AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
	AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard };
	AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, };

	size = sizeof(device);
	err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device);
	size = sizeof(channels);
	err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels);
	size = sizeof(vol);
	if (!err) {
		VolumeAddr.mElement = channels[0];
		err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeL);
	}
	if (!err) {
		VolumeAddr.mElement = channels[1];
		err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeR);
	}
	if (err) {
#endif

		fprintf(stderr, "Unable to write mixer volume: %s\n", strerror(errno));
		return -1;

	}
	return 0;
}

#ifndef __Darwin__
static int oldvol = 0;
static int mutevol = 0;
#else
static float oldvol = 0;
static float mutevol = 0;
#endif

#ifndef __Darwin__
static int mutedlevel(int orig, int level)
{
	int l = orig >> 8;
	int r = orig & 0xff;
	l = (float)(level) * (float)(l) / 100.0;
	r = (float)(level) * (float)(r) / 100.0;

	return (l << 8) | r;
#else
static float mutedlevel(float orig, float level)
{
	float master = orig;
	master = level * master / 100.0;
	return master;
#endif
	
}

static void mute(void)
{
#ifndef __Darwin__
	int vol;
	int start;
	int x;
#else
	float vol;
	float start = 1.0;
	float x;
#endif
	vol = getvol();
	oldvol = vol;
	if (smoothfade)
#ifdef __Darwin__ 
		start = mutelevel;
#else
		start = 100;
	else
コード例 #25
0
ファイル: mixer.c プロジェクト: DeforaOS/Mixer
/* mixer_get_control */
static int _mixer_get_control(Mixer * mixer, MixerControl2 * control)
{
#ifdef AUDIO_MIXER_DEVINFO
	mixer_ctrl_t p;
	struct mixer_devinfo md;
	int i;
	uint16_t u16;
# ifdef DEBUG
	size_t u;
	char * sep = "";
# endif

	md.index = control->index;
	if(ioctl(mixer->fd, AUDIO_MIXER_DEVINFO, &md) != 0)
	{
		if(errno == ENXIO)
			return -errno;
		return _mixer_error(mixer, "AUDIO_MIXER_DEVINFO", -errno);
	}
	p.dev = control->index;
	/* XXX this is necessary for some drivers and I don't like it */
	if((p.type = md.type) == AUDIO_MIXER_VALUE)
		p.un.value.num_channels = md.un.v.num_channels;
	if(ioctl(mixer->fd, AUDIO_MIXER_READ, &p) != 0)
		return -_mixer_error(mixer, "AUDIO_MIXER_READ", 1);
	control->type = p.type;
# ifdef DEBUG
	for(u = 0; u < mixer->classes_cnt; u++)
		if(mixer->classes[u].mixer_class == md.mixer_class)
			printf("%s", mixer->classes[u].label.name);
	printf(".%s=", md.label.name);
# endif
	switch(p.type)
	{
		case AUDIO_MIXER_ENUM:
			control->un.ord = p.un.ord;
# ifdef DEBUG
			for(i = 0; i < md.un.e.num_mem; i++)
			{
				if(md.un.e.member[i].ord != p.un.ord)
					continue;
				printf("%s%s", sep,
						md.un.e.member[i].label.name);
				break;
			}
# endif
			break;
		case AUDIO_MIXER_SET:
			control->un.mask = p.un.mask;
# ifdef DEBUG
			for(i = 0; i < md.un.s.num_mem; i++)
			{
				if((p.un.mask & (1 << i)) == 0)
					continue;
				printf("%s%s", sep,
						md.un.s.member[i].label.name);
				sep = ",";
			}
			printf("%s", "  {");
			for(i = 0; i < md.un.s.num_mem; i++)
				printf(" %s", md.un.s.member[i].label.name);
			printf("%s", " }");
# endif
			break;
		case AUDIO_MIXER_VALUE:
			u16 = md.un.v.delta;
			if((u16 = ceil((u16 * 100) / 255.0)) == 0)
				u16 = 1;
			control->un.level.delta = u16;
			control->un.level.channels_cnt
				= p.un.value.num_channels;
			for(i = 0; i < p.un.value.num_channels; i++)
			{
# ifdef DEBUG
				printf("%s%u", sep, p.un.value.level[i]);
				sep = ",";
# endif
				u16 = p.un.value.level[i];
				u16 = ceil((u16 * 100) / 255.0);
				control->un.level.channels[i] = u16;
			}
#ifdef DEBUG
			printf(" delta=%u", md.un.v.delta);
#endif
			break;
	}
# ifdef DEBUG
	putchar('\n');
# endif
#else
	int value;
	uint16_t u16;

	if(ioctl(mixer->fd, MIXER_READ(control->index), &value) != 0)
		return _mixer_error(NULL, "MIXER_READ", -errno);
	control->type = 0;
	control->un.level.delta = 1;
	control->un.level.channels_cnt = 2;
	u16 = value & 0xff;
	control->un.level.channels[0] = u16;
	u16 = (value & 0xff00) >> 8;
	control->un.level.channels[1] = u16;
# ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() % 3d % 3d\n", __func__,
			control->un.level.channels[0],
			control->un.level.channels[1]);
# endif
#endif
	return 0;
}
コード例 #26
0
ファイル: mixer.c プロジェクト: DeforaOS/Mixer
Mixer * mixer_new(GtkWidget * window, String const * device, MixerLayout layout)
{
	Mixer * mixer;
	GtkSizeGroup * hgroup;
	GtkSizeGroup * vgroup;
	GtkWidget * scrolled = NULL;
	GtkWidget * label;
	GtkWidget * widget;
	GtkWidget * hvbox = NULL;
	GtkWidget * hbox;
	MixerControl * control;
	MixerControl2 * q;
	int i;
#ifdef AUDIO_MIXER_DEVINFO
	mixer_devinfo_t md;
	mixer_devinfo_t md2;
	MixerClass * p;
	size_t u;
	GtkWidget * vbox2;
	char * name;
#else
	int value;
	char const * labels[] = SOUND_DEVICE_LABELS;
	char const * names[] = SOUND_DEVICE_NAMES;
#endif

	if((mixer = malloc(sizeof(*mixer))) == NULL)
		return NULL;
	if(device == NULL)
		device = MIXER_DEFAULT_DEVICE;
	mixer->device = string_new(device);
	mixer->fd = open(device, O_RDWR);
	mixer->window = window;
	mixer->properties = NULL;
	mixer->bold = NULL;
#ifdef AUDIO_MIXER_DEVINFO
	mixer->classes = NULL;
	mixer->classes_cnt = 0;
#endif
	mixer->controls = NULL;
	mixer->controls_cnt = 0;
	mixer->source = 0;
	if(mixer->device == NULL || mixer->fd < 0)
	{
		_mixer_error(NULL, device, 0);
		mixer_delete(mixer);
		return NULL;
	}
	hgroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
	vgroup = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL);
	/* widgets */
	mixer->bold = pango_font_description_new();
	pango_font_description_set_weight(mixer->bold, PANGO_WEIGHT_BOLD);
	/* classes */
	mixer->notebook = NULL;
	if(layout == ML_TABBED)
		mixer->notebook = gtk_notebook_new();
	else
	{
		scrolled = gtk_scrolled_window_new(NULL, NULL);
		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
				GTK_POLICY_AUTOMATIC, (layout == ML_VERTICAL)
				? GTK_POLICY_AUTOMATIC : GTK_POLICY_NEVER);
		hvbox = gtk_box_new((layout == ML_VERTICAL)
				? GTK_ORIENTATION_VERTICAL
				: GTK_ORIENTATION_HORIZONTAL, 4);
		gtk_container_set_border_width(GTK_CONTAINER(hvbox), 2);
		if(layout == ML_VERTICAL)
			gtk_box_set_homogeneous(GTK_BOX(hvbox), TRUE);
		_mixer_scrolled_window_add(scrolled, hvbox);
	}
	for(i = 0;; i++)
	{
#ifdef AUDIO_MIXER_DEVINFO
		md.index = i;
		if(ioctl(mixer->fd, AUDIO_MIXER_DEVINFO, &md) < 0)
			break;
		if(md.type != AUDIO_MIXER_CLASS)
			continue;
		if((p = realloc(mixer->classes, sizeof(*p)
						* (mixer->classes_cnt + 1)))
				== NULL)
		{
			_mixer_error(NULL, "realloc", 1);
			mixer_delete(mixer);
			return NULL;
		}
		mixer->classes = p;
		p = &mixer->classes[mixer->classes_cnt++];
		p->mixer_class = md.mixer_class;
		memcpy(&p->label, &md.label, sizeof(md.label));
		p->hbox = NULL;
		p->page = -1;
#else
		hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
		gtk_container_set_border_width(GTK_CONTAINER(hbox), 2);
		if(mixer->notebook != NULL)
		{
			label = _new_frame_label(NULL, _("All"), NULL);
			gtk_widget_show_all(label);
			scrolled = gtk_scrolled_window_new(NULL, NULL);
			gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
						scrolled),
					GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER);
			_mixer_scrolled_window_add(scrolled, hbox);
			gtk_notebook_append_page(GTK_NOTEBOOK(mixer->notebook),
					scrolled, label);
		}
		else
			gtk_box_pack_start(GTK_BOX(hvbox), hbox, FALSE, TRUE,
					0);
		break;
#endif
	}
	/* controls */
	for(i = 0;; i++)
	{
#ifdef AUDIO_MIXER_DEVINFO
		md.index = i;
		if(ioctl(mixer->fd, AUDIO_MIXER_DEVINFO, &md) < 0)
			break;
		if(md.type == AUDIO_MIXER_CLASS)
			continue;
		for(u = 0; u < mixer->classes_cnt; u++)
			if(mixer->classes[u].mixer_class == md.mixer_class)
				break;
		if(u == mixer->classes_cnt)
			continue;
		hbox = mixer->classes[u].hbox;
		control = NULL;
		switch(md.type)
		{
			case AUDIO_MIXER_ENUM:
				control = _new_enum(mixer, i, &md.un.e,
						md.label.name,
						_mixer_get_icon(md.label.name),
						md.label.name);
				break;
			case AUDIO_MIXER_SET:
				control = _new_set(mixer, i, &md.un.s,
						md.label.name,
						_mixer_get_icon(md.label.name),
						md.label.name);
				break;
			case AUDIO_MIXER_VALUE:
				control = _new_value(mixer, i, vgroup,
						md.label.name,
						_mixer_get_icon(md.label.name),
						md.label.name);
				break;
		}
		if(control == NULL)
			continue;
		if((q = realloc(mixer->controls, sizeof(*q)
						* (mixer->controls_cnt + 1)))
				== NULL)
		{
			mixercontrol_delete(control);
			/* FIXME report error */
			continue;
		}
		mixer->controls = q;
		q = &mixer->controls[mixer->controls_cnt++];
		q->index = md.index;
		q->type = md.type;
		q->control = control;
		widget = mixercontrol_get_widget(control);
		vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
		gtk_box_pack_start(GTK_BOX(vbox2), widget, TRUE, TRUE, 0);
		gtk_size_group_add_widget(hgroup, widget);
		if(hbox == NULL)
		{
			p = &mixer->classes[u];
			p->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
			hbox = p->hbox;
			gtk_container_set_border_width(GTK_CONTAINER(hbox), 2);
			if(mixer->notebook != NULL)
			{
				if((name = strdup(mixer->classes[u].label.name))
						!= NULL)
					name[0] = toupper(
							(unsigned char)name[0]);
				label = _new_frame_label(NULL,
						mixer->classes[u].label.name,
						name);
				free(name);
				gtk_widget_show_all(label);
				scrolled = gtk_scrolled_window_new(NULL, NULL);
				gtk_scrolled_window_set_policy(
						GTK_SCROLLED_WINDOW(scrolled),
						GTK_POLICY_AUTOMATIC,
						GTK_POLICY_NEVER);
				_mixer_scrolled_window_add(scrolled, p->hbox);
				p->page = gtk_notebook_append_page(
						GTK_NOTEBOOK(mixer->notebook),
						scrolled, label);
			}
			else if(hvbox != NULL)
				gtk_box_pack_start(GTK_BOX(hvbox), p->hbox,
						FALSE, TRUE, 0);
		}
		gtk_box_pack_start(GTK_BOX(hbox), vbox2, FALSE, TRUE, 0);
		/* add a mute button if relevant */
		if(md.type != AUDIO_MIXER_VALUE)
			continue;
		md2.index = md.index + 1;
		if(ioctl(mixer->fd, AUDIO_MIXER_DEVINFO, &md2) < 0)
			break;
		if(md2.type == AUDIO_MIXER_CLASS)
			continue;
		for(u = 0; u < mixer->classes_cnt; u++)
			if(mixer->classes[u].mixer_class == md2.mixer_class)
				break;
		if(u == mixer->classes_cnt)
			continue;
		u = strlen(md.label.name);
		if(md2.type != AUDIO_MIXER_ENUM || strncmp(md.label.name,
					md2.label.name, u) != 0
				|| (u = strlen(md2.label.name)) < 6
				|| strcmp(&md2.label.name[u - 5], ".mute") != 0)
			continue;
		/* XXX may fail */
		mixercontrol_set(control, "show-mute", TRUE, NULL);
		i++;
#else
		if(i == SOUND_MIXER_NONE)
			break;
		if(ioctl(mixer->fd, MIXER_READ(i), &value) != 0)
			continue;
		if((q = realloc(mixer->controls, sizeof(*q)
						* (mixer->controls_cnt + 1)))
				== NULL)
			/* FIXME report error */
			continue;
		mixer->controls = q;
		q = &mixer->controls[mixer->controls_cnt];
		if((control = _new_value(mixer, i, vgroup, names[i],
						_mixer_get_icon(names[i]),
						labels[i]))
				== NULL)
			continue;
		q->index = i;
		q->type = 0;
		q->control = control;
		mixer->controls_cnt++;
		widget = mixercontrol_get_widget(control);
		gtk_size_group_add_widget(hgroup, widget);
		gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
#endif
	}
	mixer->widget = (mixer->notebook != NULL) ? mixer->notebook : scrolled;
#ifdef AUDIO_MIXER_DEVINFO
	mixer_show_class(mixer, AudioCoutputs);
#endif
	gtk_widget_show_all(mixer->widget);
	mixer->source = g_timeout_add(500, _new_on_refresh, mixer);
	return mixer;
}
コード例 #27
0
static int
oss_probe_audio_device(int i, struct oss_device *device)
{
	/* Probe /dev/dspX, and fill in mixer related parts of the device. */
	/* If we are requested to probe /dev/dsp0, and that file doesn't   */
	/* exist, we probe /dev/dsp instead (if that is not a symlink).    */
	/* This is for compatibility with some old Linux distributions,    */
	/* which have a broken /dev.                                       */
	struct stat	s;
	int		speed[] = {8000, 11025, 16000, 22050, 32000, 44100, 48000};
        int 		stereo, speed_index, fd;

	sprintf(device->audio_rdev, "/dev/dsp%d", i);
	fd = open(device->audio_rdev, O_RDWR);
	if ((fd < 0) && (i == 0)) {
		if ((stat("/dev/dsp", &s) == 0) && !S_ISLNK(s.st_mode)) {
			sprintf(device->audio_rdev, "/dev/dsp");
			fd = open(device->audio_rdev, O_RDWR);
		}
	}
	if (fd < 0) {
		debug_msg("cannot open %s - %s\n", device->audio_rdev, strerror(errno));
		return FALSE;
	}
	strncpy(device->audio_wdev, device->audio_rdev, 16);

	/* Check if the device is full duplex. This MUST be the first test   */
	/* after the audio device is opened.                                 */
	if (ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0) == -1) {
		debug_msg("testing %s support for full duplex operation: no\n", device->audio_rdev);
		device->duplex = OSS_DUPLEX_HALF;
	} else {
		debug_msg("testing %s support for full duplex operation: yes\n", device->audio_rdev);
		device->duplex = OSS_DUPLEX_FULL;
	}

	/* Check which sampling modes are supported...                       */
	device->num_supported_formats = 0;
	for (speed_index = 0; speed_index < 7; speed_index++) {
                for (stereo = 0; stereo < 2; stereo++) {
			debug_msg("testing %s support for %5dHz %s\n", device->audio_rdev, speed[speed_index], stereo?"stereo":"mono");
                        if (oss_test_mode(fd, speed[speed_index], stereo)) {
				device->supported_formats[device->num_supported_formats].sample_rate = speed[speed_index];
				device->supported_formats[device->num_supported_formats].channels    = stereo + 1;
				device->num_supported_formats++;
			}
                }
        }
	/* Check for OSS version number */

	{
#ifdef OSS_GETVERSION
	    int version = -1;
	    if (ioctl(fd, OSS_GETVERSION, &version) < 0) {
		debug_msg("%s doesn't support OSS_GETVERSION\n",
			  device->audio_rdev);
	    } else {
		int level;
		debug_msg("OSS version is %x\n", version);

		/*
		 * Check to see if we can use the MIXER_RECLEV setting
		 * If we can, this might be an ES1371-based card that uses
		 * RECLEV to adjust input levels.
		 */

		if (ioctl(fd, MIXER_READ(SOUND_MIXER_RECLEV), &level) >= 0) {
		    debug_msg("Can use reclev. \n");
		
		    if (version >= 0x030903) {
			debug_msg("Enabling latemodel opensound\n");
			device->is_latemodel_opensound = 1;
		    }
		}
	    }
#endif
	}

	close(fd);
	device->audio_rfd = -1;
	device->audio_wfd = -1;
	return TRUE;
}
コード例 #28
0
ファイル: mixer.c プロジェクト: AhmadTux/freebsd
int
main(int argc, char *argv[])
{
	char	mixer[PATH_MAX] = "/dev/mixer";
	char	lstr[5], rstr[5];
	char	*name, *eptr;
	int	devmask = 0, recmask = 0, recsrc = 0, orecsrc;
	int	dusage = 0, drecsrc = 0, sflag = 0, Sflag = 0;
	int	l, r, lrel, rrel;
	int	ch, foo, bar, baz, dev, m, n, t;

	if ((name = strdup(basename(argv[0]))) == NULL)
		err(1, "strdup()");
	if (strncmp(name, "mixer", 5) == 0 && name[5] != '\0') {
		n = strtol(name + 5, &eptr, 10) - 1;
		if (n > 0 && *eptr == '\0')
			snprintf(mixer, PATH_MAX - 1, "/dev/mixer%d", n);
	}
	free(name);
	name = mixer;

	n = 1;
	for (;;) {
		if (n >= argc || *argv[n] != '-')
			break;
		if (strlen(argv[n]) != 2) {
			if (strcmp(argv[n] + 1, "rec") != 0)
				dusage = 1;
			break;
		}
		ch = *(argv[n] + 1);
		if (ch == 'f' && n < argc - 1) {
			name = argv[n + 1];
			n += 2;
		} else if (ch == 's') {
			sflag = 1;
			n++;
		} else if (ch == 'S') {
			Sflag = 1;
			n++;
		} else {
			dusage = 1;
			break;
		}
	}
	if (sflag && Sflag)
		dusage = 1;

	argc -= n - 1;
	argv += n - 1;

	if ((baz = open(name, O_RDWR)) < 0)
		err(1, "%s", name);
	if (ioctl(baz, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
		err(1, "SOUND_MIXER_READ_DEVMASK");
	if (ioctl(baz, SOUND_MIXER_READ_RECMASK, &recmask) == -1)
		err(1, "SOUND_MIXER_READ_RECMASK");
	if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1)
		err(1, "SOUND_MIXER_READ_RECSRC");
	orecsrc = recsrc;

	if (argc == 1 && dusage == 0) {
		for (foo = 0, n = 0; foo < SOUND_MIXER_NRDEVICES; foo++) {
			if (!((1 << foo) & devmask))
				continue;
			if (ioctl(baz, MIXER_READ(foo),&bar) == -1) {
			   	warn("MIXER_READ");
				continue;
			}
			if (Sflag || sflag) {
				printf("%s%s%c%d:%d", n ? " " : "",
				    names[foo], Sflag ? ':' : ' ',
				    bar & 0x7f, (bar >> 8) & 0x7f);
				n++;
			} else
				printf("Mixer %-8s is currently set to "
				    "%3d:%d\n", names[foo], bar & 0x7f,
				    (bar >> 8) & 0x7f);
		}
コード例 #29
0
ファイル: tvmixer.c プロジェクト: muromec/linux-ezxdev
static int tvmixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	struct video_audio va;
	int left,right,ret,val = 0;
        struct TVMIXER *mix = file->private_data;
	struct i2c_client *client = mix->dev;

	if (NULL == client)
		return -ENODEV;
	
        if (cmd == SOUND_MIXER_INFO) {
                mixer_info info;
                strncpy(info.id, "tv card", sizeof(info.id));
                strncpy(info.name, client->name, sizeof(info.name));
                info.modify_counter = 42 /* FIXME */;
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
        }
        if (cmd == SOUND_OLD_MIXER_INFO) {
                _old_mixer_info info;
                strncpy(info.id, "tv card", sizeof(info.id));
                strncpy(info.name, client->name, sizeof(info.name));
                if (copy_to_user((void *)arg, &info, sizeof(info)))
                        return -EFAULT;
                return 0;
        }
        if (cmd == OSS_GETVERSION)
                return put_user(SOUND_VERSION, (int *)arg);

	if (_SIOC_DIR(cmd) & _SIOC_WRITE)
		if (get_user(val, (int *)arg))
			return -EFAULT;

	/* read state */
	memset(&va,0,sizeof(va));
	client->driver->command(client,VIDIOCGAUDIO,&va);

	switch (cmd) {
	case MIXER_READ(SOUND_MIXER_RECMASK):
	case MIXER_READ(SOUND_MIXER_CAPS):
	case MIXER_READ(SOUND_MIXER_RECSRC):
	case MIXER_WRITE(SOUND_MIXER_RECSRC):
		ret = 0;
		break;

	case MIXER_READ(SOUND_MIXER_STEREODEVS):
		ret = SOUND_MASK_VOLUME;
		break;
	case MIXER_READ(SOUND_MIXER_DEVMASK):
		ret = SOUND_MASK_VOLUME;
		if (va.flags & VIDEO_AUDIO_BASS)
			ret |= SOUND_MASK_BASS;
		if (va.flags & VIDEO_AUDIO_TREBLE)
			ret |= SOUND_MASK_TREBLE;
		break;

	case MIXER_WRITE(SOUND_MIXER_VOLUME):
		left  = mix_to_v4l(val);
		right = mix_to_v4l(val >> 8);
		va.volume  = MAX(left,right);
		va.balance = (32768*MIN(left,right)) / (va.volume ? va.volume : 1);
		va.balance = (left<right) ? (65535-va.balance) : va.balance;
		client->driver->command(client,VIDIOCSAUDIO,&va);
		client->driver->command(client,VIDIOCGAUDIO,&va);
		/* fall throuth */
	case MIXER_READ(SOUND_MIXER_VOLUME):
		left  = (MIN(65536 - va.balance,32768) *
			 va.volume) / 32768;
		right = (MIN(va.balance,32768) *
			 va.volume) / 32768;
		ret = v4l_to_mix2(left,right);
		break;
		
	case MIXER_WRITE(SOUND_MIXER_BASS):
		va.bass = mix_to_v4l(val);
		client->driver->command(client,VIDIOCSAUDIO,&va);
		client->driver->command(client,VIDIOCGAUDIO,&va);
		/* fall throuth  */
	case MIXER_READ(SOUND_MIXER_BASS):
		ret = v4l_to_mix(va.bass);
		break;

	case MIXER_WRITE(SOUND_MIXER_TREBLE):
		va.treble = mix_to_v4l(val);
		client->driver->command(client,VIDIOCSAUDIO,&va);
		client->driver->command(client,VIDIOCGAUDIO,&va);
		/* fall throuth */
	case MIXER_READ(SOUND_MIXER_TREBLE):
		ret = v4l_to_mix(va.treble);
		break;

	default:
		return -EINVAL;
	}
	if (put_user(ret, (int *)arg))
		return -EFAULT;
	return 0;
}
コード例 #30
0
ファイル: sound.c プロジェクト: JackieXie168/movgrab
int OSSAlterVolumeType(char *device, int Type, int delta)
{
int left_val, right_val, val, mixfd=0;

mixfd=open(device, O_RDWR);
if (mixfd > -1)
{
switch (Type)
{
	case VOL_MASTER:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_VOLUME),&val);
	break;

	case VOL_PCM:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_PCM),&val);
	break;

	case VOL_CD:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_CD),&val);
	break;

	case VOL_MIC:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_MIC),&val);
	break;

	case VOL_VIDEO:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_VIDEO),&val);
	break;

	case VOL_PHONEIN:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_PHONEIN),&val);
	break;

	case VOL_PHONEOUT:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_PHONEOUT),&val);
	break;

	case VOL_LINE1:
	ioctl(mixfd,MIXER_READ(SOUND_MIXER_LINE1),&val);
	break;
}

left_val=val & 0xFF;
right_val=(val & 0xFF00) >> 8;

left_val+=delta;
if (left_val < 0) left_val=0;
if (left_val > 255) left_val=255;

right_val+=delta;
if (right_val < 0) right_val=0;
if (right_val > 255) right_val=255;

right_val=right_val << 8;
val=right_val + left_val;

switch (Type)
{
	case VOL_MASTER:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_VOLUME),&val);
	break;

	case VOL_PCM:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_PCM),&val);
	break;

	case VOL_CD:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_CD),&val);
	break;

	case VOL_MIC:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_MIC),&val);
	break;

	case VOL_VIDEO:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_VIDEO),&val);
	break;

	case VOL_PHONEIN:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_PHONEIN),&val);
	break;

	case VOL_PHONEOUT:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_PHONEOUT),&val);
	break;

	case VOL_LINE1:
	ioctl(mixfd,MIXER_WRITE(SOUND_MIXER_LINE1),&val);
	break;
}

close(mixfd);
}

return(left_val);
}