home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / sndserv / src / linux.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  2.8 KB  |  121 lines

  1. /*  Emacs style mode select   -*- C++ -*-  */
  2. /* ----------------------------------------------------------------------------- */
  3. /*  */
  4. /*  $Id: linux.c,v 1.3 1997/01/26 07:45:01 b1 Exp $ */
  5. /*  */
  6. /*  Copyright (C) 1993-1996 by id Software, Inc. */
  7. /*  */
  8. /*  This source is available for distribution and/or modification */
  9. /*  only under the terms of the DOOM Source Code License as */
  10. /*  published by id Software. All rights reserved. */
  11. /*  */
  12. /*  The source is distributed in the hope that it will be useful, */
  13. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of */
  14. /*  FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License */
  15. /*  for more details. */
  16. /*  */
  17. /*  */
  18. /*  $Log: linux.c,v $ */
  19. /*  Revision 1.3  1997/01/26 07:45:01  b1 */
  20. /*  2nd formatting run, fixed a few warnings as well. */
  21. /*  */
  22. /*  Revision 1.2  1997/01/21 19:00:01  b1 */
  23. /*  First formatting run: */
  24. /*   using Emacs cc-mode.el indentation for C++ now. */
  25. /*  */
  26. /*  Revision 1.1  1997/01/19 17:22:45  b1 */
  27. /*  Initial check in DOOM sources as of Jan. 10th, 1997 */
  28. /*  */
  29. /*  */
  30. /*  DESCRIPTION: */
  31. /*     UNIX, soundserver for Linux i386. */
  32. /*  */
  33. /* ----------------------------------------------------------------------------- */
  34.  
  35. static const char rcsid[] = "$Id: linux.c,v 1.3 1997/01/26 07:45:01 b1 Exp $";
  36.  
  37.  
  38. #include <stdlib.h>
  39. #include <stdio.h>
  40. #include <fcntl.h>
  41. #include <unistd.h>
  42.  
  43. #include <sys/ioctl.h>
  44.  
  45. #include <linux/soundcard.h>
  46.  
  47. #include "soundsrv.h"
  48.  
  49. int    audio_fd;
  50.  
  51. void
  52. myioctl
  53. ( int    fd,
  54.   int    command,
  55.   int*    arg )
  56. {   
  57.     int        rc;
  58.     extern int    errno;
  59.     
  60.     rc = ioctl(fd, command, arg);  
  61.     if (rc < 0)
  62.     {
  63.     fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
  64.     fprintf(stderr, "errno=%d\n", errno);
  65.     exit(-1);
  66.     }
  67. }
  68.  
  69. void I_InitMusic(void)
  70. {
  71. }
  72.  
  73. void
  74. I_InitSound
  75. ( int    samplerate,
  76.   int    samplesize )
  77. {
  78.  
  79.     int i;
  80.                 
  81.     audio_fd = open("/dev/dsp", O_WRONLY);
  82.     if (audio_fd<0)
  83.         fprintf(stderr, "Could not open /dev/dsp\n");
  84.          
  85.                      
  86.     i = 11 | (2<<16);                                           
  87.     myioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i);
  88.                     
  89.     myioctl(audio_fd, SNDCTL_DSP_RESET, 0);
  90.     i=11025;
  91.     myioctl(audio_fd, SNDCTL_DSP_SPEED, &i);
  92.     i=1;    
  93.     myioctl(audio_fd, SNDCTL_DSP_STEREO, &i);
  94.             
  95.     myioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i);
  96.     if (i&=AFMT_S16_LE)    
  97.         myioctl(audio_fd, SNDCTL_DSP_SETFMT, &i);
  98.     else
  99.         fprintf(stderr, "Could not play signed 16 data\n");
  100.  
  101. }
  102.  
  103. void
  104. I_SubmitOutputBuffer
  105. ( void*    samples,
  106.   int    samplecount )
  107. {
  108.     write(audio_fd, samples, samplecount*4);
  109. }
  110.  
  111. void I_ShutdownSound(void)
  112. {
  113.  
  114.     close(audio_fd);
  115.  
  116. }
  117.  
  118. void I_ShutdownMusic(void)
  119. {
  120. }
  121.