Recent topics Log in
Search Profile
Memberlist Usergroups
Log in to check your private messages
Register
linux commandline vol control
Post new topic   Reply to topic
SpaceTrace Forum Forum Index » Off topic » linux commandline vol control
View previous topic :: View next topic  
Author Message
plasmator
Commander
Commander


Joined: 07 Nov 2003
Posts: 94

 Post Posted: Mon Dec 22, 2003 8:40 pm    Post subject:
Reply with quote

/*
* mixer.c
* Example of a simple mixer program
*/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/soundcard.h>

/* names of available mixer devices */
const char *sound_device_names[] = SOUND_DEVICE_NAMES;

int fd; /* file descriptor for mixer device */
int devmask, stereodevs; /* bit masks of mixer information */
char *name; /* program name */

/* display command usage and exit with error status */
void usage()
{
int i;

fprintf(stderr, "usage: %s <device> <left-gain%%> <right-gain%%>n"
" %s <device> <gain%%>nn"
"Where <device> is one of:n", name, name);
for (i = 0 ; i < SOUND_MIXER_NRDEVICES ; i++)
if ((1 << i) & devmask) /* only display valid devices */
fprintf(stderr, "%s ", sound_device_names[i]);
fprintf(stderr, "n");
exit(1);
}

int main(int argc, char *argv[])
{
int left, right, level; /* gain settings */
int status; /* return value from system calls */
int device; /* which mixer device to set */
int i; /* general purpose loop counter */
char *dev; /* mixer device name */

/* save program name */
name = argv[0];

/* open mixer, read only */
fd = open("/dev/mixer", O_RDONLY);
if (fd == -1) {
perror("unable to open /dev/mixer");
exit(1);
}

/* get needed information about the mixer */
status = ioctl(fd, SOUND_MIXER_READ_DEVMASK, &devmask);
if (status == -1)
perror("SOUND_MIXER_READ_DEVMASK ioctl failed");
status = ioctl(fd, SOUND_MIXER_READ_STEREODEVS, &stereodevs);
if (status == -1)
perror("SOUND_MIXER_READ_STEREODEVS ioctl failed");

/* check that user passed two or three arguments on command line */
if (argc != 3 && argc != 4)
usage();

/* save mixer device name */
dev = argv[1];

/* figure out which device to use */
for (i = 0 ; i < SOUND_MIXER_NRDEVICES ; i++)
if (((1 << i) & devmask) && !strcmp(dev, sound_device_names[i]))
break;
if (i == SOUND_MIXER_NRDEVICES) { /* didn't find a match */
fprintf(stderr, "%s is not a valid mixer devicen", dev);
usage();
}

/* we have a valid mixer device */
device = i;

/* get gain values */
if (argc == 4) {
/* both left and right values given */
left = atoi(argv[2]);
right = atoi(argv[3]);
} else {
/* left and right are the same */
left = atoi(argv[2]);
right = atoi(argv[2]);
}

/* display warning if left and right gains given for non-stereo device */
if ((left != right) && !((1 << i) & stereodevs)) {
fprintf(stderr, "warning: %s is not a stereo devicen", dev);
}

/* encode both channels into one value */
level = (right << 8 ) + left;

/* set gain */
status = ioctl(fd, MIXER_WRITE(device), &level);
if (status == -1) {
perror("MIXER_WRITE ioctl failed");
exit(1);
}

/* unpack left and right levels returned by sound driver */
left = level & 0xff;
right = (level & 0xff00) >> 8;

/* display actual gain setting */
fprintf(stderr, "%s gain set to %d%% / %d%%n", dev, left, right);

/* close mixer device and exit */
close(fd);
return 0;
}



[ This Message was edited by: plasmator on 2003-12-22 20:43 ]
 Back to top »
View user's profile Send private message
plasmator
Commander
Commander


Joined: 07 Nov 2003
Posts: 94

 Post Posted: Mon Dec 22, 2003 8:43 pm    Post subject:
Reply with quote

mmmh it made a out of some source code...(i corrected it ) 8 ) not

just save this as mixer.c

then

gcc mixer.c
cp a.out mixer



[ This Message was edited by: plasmator on 2003-12-22 20:45 ]
 Back to top »
View user's profile Send private message
JaM
Admiral
Admiral


Joined: 23 Mar 2003
Posts: 1300

 Post Posted: Mon Dec 22, 2003 10:41 pm    Post subject:

There is something like
Code:

#include <iostream>

int main ()
{
   cout << "Hello SpaceTrace World" << endl;
   return 0;
}
tags
But I don't use linux
 Back to top »
View user's profile Send private message Send e-mail
Display posts from previous:   
SpaceTrace Forum Forum Index » Off topic » linux commandline vol control
Post new topic   Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Solaris phpBB theme/template by Jakob Persson
Copyright © Jakob Persson 2003



Powered by phpBB © 2001, 2002 phpBB Group

Impressum