CSC 790 Fall 2009 A good resource for Linux audio programming is provided in the "Open Sound System OSS 4.x Programmer's Guide" http://manuals.opensound.com/developer/ ========================================================================== Some #includes you will need #include // for ioctl #include // for open and O_WRONLY #include // for SNDCTL defines ========================================================================== The ioctl system calls you will need are given below. Note in most cases the function returns -1 if an error occurs. You must determine if this occurs in your program and handle it appropriately. Setting the format of the audio samples to DSP signed 16 bit little endian int format = AFMT_S16_LE; ioctl(fd_, SNDCTL_DSP_SETFMT, &format); Setting the format to stereo or mono, returns -1 if error int stereo = 0; // 0 = mono , 1 = stereo ioctl(fd_, SNDCTL_DSP_STEREO, &stereo); Setting the sampling rate of the device int speed = 8000; ioctl(fd_, SNDCTL_DSP_SPEED, &sampleRate); Finding the amount of buffer space of the device audio_buf_info bi; ioctl(fd_, SNDCTL_DSP_GETOSPACE, &bi); bufferSize_ = bi.bytes; Setting the volume of the device, note range is 0 to 100 (0 is the minimum) int level = (vol)|(vol<<8); ioctl(fd_, SOUND_MIXER_WRITE_VOLUME, &level); Finding the amount of empty space in the buffer audio_buf_info bi; ioctl(fd_, SNDCTL_DSP_GETOSPACE, &bi); cout << "number of bytes empty in buffer " << bi.bytes << '\n';