[ale] Can someone tell me what I am doing wrong....?

Glenn C. Lasher Jr. critter at wizvax.net
Tue Jan 19 15:55:21 EST 1999


Having not found an audio recorder program that fits my needs, I am taking
a shot at writing my own.  Thus, I have come up with the following
experimental program whose code follows.  The problem is this:  When I
compile this, it compiles fine.  At run time, however, the message
returned is that it is unable to set the mode to S16LE (Signed, 16 bit,
Little Endian) because of a bad address.  The specific message appears as:

	Unable to set correct sample format:bad address

Obviously, the first part of this is from my perror() call.  What is it
talking about, "Bad addrss"?  

BTW, this code should be considered GPL.  If you like it (not likely), use
it.  When I get done with it, I'll release the whole thing to the public
under GPL.

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

#define BUF_SIZE    4096

main()
  {
    int len;
    int stereo;
    int speed;
    int audio_fd;                                                         
    unsigned char audio_buffer[BUF_SIZE];                          
   
    /*Attempt to open the audio device....*/ 
    if ((audio_fd = open ("/dev/dsp", O_RDONLY, 0)) == -1)
      {      
	perror ("Unable to open sound device");
	exit(-1);
      }

    /*Attempt to set the audio mode to signed, 16bit, Little Endian... */
    if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, AFMT_S16_LE) == -1)
      {
	perror ("Unable to set correct sample format");
	exit(-1);
      }

    /*Attempt to set the mode to stereo*/
    stereo=1;
    if (ioctl(audio_fd, SNDCTL_DSP_STEREO, &stereo) == -1)
      {
	perror ("Unable to set stereo mode");
	exit(-1);
      }

    /*Attempt to set the speed to 44100 Hz*/
    speed=44100;
    if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &speed) == -1)
      {
	perror("Unable to set sample speed");
	exit(-1);
      }

    /*Attempt to read one block of audio.*/
    if ((len = read(audio_fd, audio_buffer, BUF_SIZE)) == -1)
      {
	perror ("Unable to read from audio device");
	exit(-1);
      }
  }




--
Critter at Wizvax.Net
Stealing is illegal... the government hates competition.
PGP key available at http://www.wizvax.net/critter/pgpkey.html.






More information about the Ale mailing list