linux.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. static const char rcsid[] = "$Id: linux.c,v 1.3 1997/01/26 07:45:01 b1 Exp $";
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <fcntl.h>
  38. #include <unistd.h>
  39. #include <linux/soundcard.h>
  40. #include "soundsrv.h"
  41. int audio_fd;
  42. void
  43. myioctl
  44. ( int fd,
  45. int command,
  46. int* arg )
  47. {
  48. int rc;
  49. extern int errno;
  50. rc = ioctl(fd, command, arg);
  51. if (rc < 0)
  52. {
  53. fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
  54. fprintf(stderr, "errno=%d\n", errno);
  55. exit(-1);
  56. }
  57. }
  58. void I_InitMusic(void)
  59. {
  60. }
  61. void
  62. I_InitSound
  63. ( int samplerate,
  64. int samplesize )
  65. {
  66. int i;
  67. audio_fd = open("/dev/dsp", O_WRONLY);
  68. if (audio_fd<0)
  69. fprintf(stderr, "Could not open /dev/dsp\n");
  70. i = 11 | (2<<16);
  71. myioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i);
  72. myioctl(audio_fd, SNDCTL_DSP_RESET, 0);
  73. i=11025;
  74. myioctl(audio_fd, SNDCTL_DSP_SPEED, &i);
  75. i=1;
  76. myioctl(audio_fd, SNDCTL_DSP_STEREO, &i);
  77. myioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i);
  78. if (i&=AFMT_S16_LE)
  79. myioctl(audio_fd, SNDCTL_DSP_SETFMT, &i);
  80. else
  81. fprintf(stderr, "Could not play signed 16 data\n");
  82. }
  83. void
  84. I_SubmitOutputBuffer
  85. ( void* samples,
  86. int samplecount )
  87. {
  88. write(audio_fd, samples, samplecount*4);
  89. }
  90. void I_ShutdownSound(void)
  91. {
  92. close(audio_fd);
  93. }
  94. void I_ShutdownMusic(void)
  95. {
  96. }