[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Setting samplerate on /dev/dsp



On Mon, Nov 01, 2004 at 07:55:15PM +0000, ognjen Bezanov wrote:
> Hi all, while not technically debian related it has something to do with
> linux.
> 
> I want to capture data from my /dev/dsp device but the devices defaults
> are 8bit mono sound, i want to know how to set the samplerate and
> mono/stereo from the command line, a google search showed me only how to
> do it in C++ (using ioctl). is it possible?
> 
> if not is there are program out there which would let me set the
> samplerate before capture?

Digging around in some of my old experimental stuff reveals this
little C program which seems to be for providing access to that ioctl
from the command line. Compile with gcc fmts.c -o fmts (or whatever
else you want to call it). You need to know the hex codes for the
format you want, which your google search probably told you; if it
didn't have a poke through the kernel source and /usr/include/linux.

Disclaimer: it's a long time since I was fiddling with this and I
can't remember whether it actually works or not. I think it did though
:-)

-- 
Pigeon

Be kind to pigeons
Get my GPG key here: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x21C61F7F
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>


int dsp_fd;
FILE *f;

int dsp_init(void)
{
  int i,value;

  f=fopen("/dev/dsp","w+");
  if(f==NULL){
    perror("File I/O");
    return 0;
  }
  dsp_fd=i=fileno(f);
  return 1;
}


int main(int argc, char *argv[]) {
	int x, y;
	
    if (dsp_init()==0) {
		fprintf(stderr,"Can't open dsp\n");
		exit(1);
	}
	
	x=0;
	y=ioctl(dsp_fd,SNDCTL_DSP_GETFMTS,&x);
	
	printf("ioctl returned %d, x is %08X\n",y,x);

	x=0;
	y=ioctl(dsp_fd,SNDCTL_DSP_SETFMT,&x);
	printf("ioctl returned %d, current format is %08X\n",y,x);
    
	if (argc==2) {
		if (sscanf(argv[1],"%08x",&x)==1) {
			printf("Attempting to set format %08X... ",x);
			y=ioctl(dsp_fd,SNDCTL_DSP_SETFMT,&x);
			printf("ioctl returned %d, new format is %08X\n",y,x);
		}
    }

	fclose(f);
    exit(0);
}

Attachment: signature.asc
Description: Digital signature


Reply to: