home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / maplay-1.2 / obuffer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-04  |  4.3 KB  |  167 lines

  1. /*
  2.  *  @(#) obuffer.h 1.8, last edit: 6/15/94 16:51:56
  3.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  4.  *  @(#) Berlin University of Technology
  5.  *
  6.  *  Idea and first implementation for u-law output with fast downsampling by
  7.  *  Jim Boucher (jboucher@flash.bu.edu)
  8.  *
  9.  *  LinuxObuffer class written by
  10.  *  Louis P. Kruger (lpkruger@phoenix.princeton.edu)
  11.  *
  12.  *  This program is free software; you can redistribute it and/or modify
  13.  *  it under the terms of the GNU General Public License as published by
  14.  *  the Free Software Foundation; either version 2 of the License, or
  15.  *  (at your option) any later version.
  16.  *
  17.  *  This program is distributed in the hope that it will be useful,
  18.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  *  GNU General Public License for more details.
  21.  *
  22.  *  You should have received a copy of the GNU General Public License
  23.  *  along with this program; if not, write to the Free Software
  24.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #ifndef OBUFFER_H
  28. #define OBUFFER_H
  29.  
  30. #include <iostream.h>
  31. #include <unistd.h>
  32. #include <stdlib.h>
  33. #include "all.h"
  34. #include "header.h"
  35. extern "C" {
  36. #include "audio_includes.h"
  37. }
  38.  
  39.  
  40. static const uint32 OBUFFERSIZE = 2 * 1152;    // max. 2 * 1152 samples per frame
  41. static const uint32 MAXCHANNELS = 2;        // max. number of channels
  42.  
  43.  
  44. // Abstract base class for audio output classes:
  45. class Obuffer
  46. {
  47. public:
  48.   virtual     ~Obuffer (void) {}        // dummy
  49.   virtual void append (uint32 channel, int16 value) = 0;
  50.            // this function takes a 16 Bit PCM sample
  51.   virtual void write_buffer (int fd) = 0;
  52.            // this function should write the samples to the filedescriptor
  53.            // or directly to the audio hardware
  54. };
  55.  
  56.  
  57. // An audio output class for raw pcm output
  58. // or if ULAW is defined:
  59. // An audio output class for 8-bit ulaw output at 8 kHz:
  60. class FileObuffer : public Obuffer
  61. {
  62. private:
  63. #ifdef ULAW
  64.   ulawsample buffer[OBUFFERSIZE];
  65.   ulawsample *bufferp[MAXCHANNELS];
  66. #else
  67.   int16 buffer[OBUFFERSIZE];
  68.   int16 *bufferp[MAXCHANNELS];
  69. #endif
  70.   uint32 channels;
  71.  
  72. public:
  73.     FileObuffer (uint32 number_of_channels);
  74.        ~FileObuffer (void) {}
  75.   void    append (uint32 channel, int16 value);
  76.   void    write_buffer (int fd);
  77. };
  78.  
  79.  
  80. #ifdef Indigo
  81. // a class for direct sound output on SGI machines:
  82. class IndigoObuffer : public Obuffer
  83. {
  84. private:
  85.   int16 buffer[OBUFFERSIZE];
  86.   int16 *bufferp[MAXCHANNELS];
  87.   uint32 channels;
  88.   ALport port;
  89.  
  90. public:
  91.     IndigoObuffer (uint32 number_of_channels, Header *);
  92.        ~IndigoObuffer (void);
  93.   void    append (uint32 channel, int16 value);
  94.   void    write_buffer (int dummy);
  95. };
  96. #endif    // Indigo
  97.  
  98.  
  99. #ifdef SPARC
  100. // a class for direct sound output on SPARC 10 machines (dbri device)
  101. // or if ULAW is defined:
  102. // a class for direct sound output on SPARCs using a 8 kHz
  103. // 8-bit u-law audio device: (audioamd)
  104. class SparcObuffer : public Obuffer
  105. {
  106. private:
  107. #ifdef ULAW
  108.   ulawsample buffer[OBUFFERSIZE >> 1];        // mono only
  109.   ulawsample *bufferp;
  110. #else
  111.   int16 buffer[OBUFFERSIZE];
  112.   int16 *bufferp[MAXCHANNELS];
  113.   uint32 channels;
  114. #endif
  115.   static int audio_fd;
  116.  
  117.   static int open_audio_device (void);
  118. #ifdef Solaris
  119.   static void get_device_type (int fd, audio_device *);
  120. #else
  121.   static int get_device_type (int fd);
  122. #endif
  123.  
  124. public:
  125. #ifdef ULAW
  126.     SparcObuffer (Header *, bool use_speaker, bool use_headphone, bool use_line_out);
  127. #else
  128.     SparcObuffer (uint32 number_of_channels, Header *,
  129.                bool use_speaker, bool use_headphone, bool use_line_out);
  130. #endif
  131.        ~SparcObuffer (void);
  132.   void    append (uint32 channel, int16 value);
  133.   void    write_buffer (int dummy);
  134.  
  135. #ifdef ULAW
  136.   static bool class_suitable (uint32 number_of_channels, bool force_amd);
  137.     // returnvalue == False: no u-law output possible (class unsuitable)
  138. #else
  139.   static bool class_suitable (void);
  140.     // returnvalue == False: no 16-bit output possible (class unsuitable)
  141. #endif
  142. };
  143. #endif    // SPARC
  144.  
  145.  
  146. #ifdef LINUX
  147. class LinuxObuffer : public Obuffer
  148. {
  149.   int16  buffer[OBUFFERSIZE];
  150.   int16 *bufferp[MAXCHANNELS];
  151.   uint32 channels;
  152.   static int audio_fd;
  153.  
  154.   static int open_audio_device (void);
  155.  
  156. public:
  157.     LinuxObuffer (uint32 number_of_channels, Header *);
  158.        ~LinuxObuffer (void);
  159.   void    append (uint32 channel, int16 value);
  160.   void    write_buffer (int dummy);
  161.  
  162.   static bool class_suitable (uint32 number_of_channels);
  163. };
  164. #endif    // LINUX
  165.  
  166. #endif
  167.