home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / src_cpp / include / sndfile.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-14  |  2.4 KB  |  104 lines

  1. // Copyright 1993, Mark T. Pflaging
  2. // Interface for class SB_SoundFile.
  3. // See also comments in "SndFile.cpp".
  4. #ifndef __SNDFILE_HPP
  5. #define __SNDFILE_HPP
  6.  
  7. #include <malloc.h>
  8. #include "standard.hpp"
  9. #include "emm.hpp"
  10.  
  11. class SB_SoundFile;
  12.  
  13. class strSnd {
  14. public:
  15.     char * name;
  16.     SB_SoundFile * sound;
  17. };
  18.  
  19. #define MAXSOUNDS    100
  20.  
  21. struct wav_header {
  22.     char id1[4];        // "RIFF"
  23.     unsigned long junk1;    // Don't really need this length
  24.     char id2[8];        // "WAVEfmt "
  25.     unsigned long blklen;
  26.     unsigned int indicator;
  27.     unsigned int stereoval;
  28.     unsigned long sr;        // sample rate.
  29.     unsigned long blkpersec;
  30.     unsigned int blkspersamp;
  31.     unsigned int bits_per_sample;
  32.     char id3[4];            // "data"
  33.     unsigned long sample_len;    // sample length on disk
  34. };
  35.  
  36. class SB_SoundFile
  37. #ifndef OLD_WAY
  38.  : LIMEMS
  39. #endif
  40. {
  41.     static log_to_phys_map quadphys[4];    // 4 physical-to-logical mappings
  42.     static SB_SoundFile * current_file;
  43.  
  44. #ifdef OLD_WAY
  45.     signed char far * aligned;
  46.     signed char far *raw;
  47. #else
  48.     int pages, first_page, last_page;
  49.     static int current_page, pages_left, is_not_maptime;
  50.     static unsigned long bytes_left;
  51.     static SoundBlaster * device;
  52. #endif
  53.  
  54.     unsigned long sr;        // sample rate.
  55.     unsigned sl;        // sample length in memory
  56.     unsigned long sample_len;    // sample length on disk
  57.     Boolean stereo;
  58.  
  59.     static strSnd sndRefs[MAXSOUNDS];
  60.     static int currentSnds;
  61.  
  62.     void InitRef(char * refname) {
  63.         sndRefs[currentSnds].name = refname;
  64.         sndRefs[currentSnds].sound = this;
  65.         ++currentSnds;
  66.     }
  67.     Boolean ReadHeader(int fd);
  68.  
  69.     void guess(istream & where, char * addr);
  70.  
  71. public:
  72.     SB_SoundFile(char * refname, char * filenm) : sr(11000), stereo(False) {
  73.         Init(refname, filenm);
  74.     }
  75.     ~SB_SoundFile() {
  76.         // I'm assuming that all the SB_SoundFiles get deleted
  77.         // at the same time.  This is easier to handle consider
  78.         // the stupidity of the EMM.
  79. #ifdef OLD_WAY
  80.         farfree(raw);
  81. #endif
  82.     }
  83.  
  84.     static void KillAllSounds();    // Deletes every SB_SoundFile
  85.  
  86.     unsigned long getSampleRate() { return sr; }
  87.     void setStereo(Boolean arg) { stereo = arg; }
  88.  
  89.     void Init(char * refname, char * filenm);
  90.     void MapInSound(int first, int howmany);
  91.  
  92.     void OutVoice_DMA(SoundBlaster & device);
  93.     void Play(SoundBlaster & device) {
  94.         OutVoice_DMA(device);
  95.     }
  96.     static SB_SoundFile * Find(char * ref);
  97.     static Boolean nextDMAtransfer() {
  98.         return current_file->NextDMASegment();
  99.     }
  100.     Boolean NextDMASegment();
  101. };
  102.  
  103. #endif
  104.