Difference for arch/dos/digimm.c from version 1.1 to 1.2


version 1.1 version 1.2
Line 7
 
Line 7
 #include "mm_drv.h"  #include "mm_drv.h"
 #include "timer.h"  #include "timer.h"
   
 //#include "SDL.h"  
 //#include "SDL_audio.h"  
   
 #include "error.h"  #include "error.h"
 #include "mono.h"  #include "mono.h"
 #include "fix.h"  #include "fix.h"
Line 23
 
Line 20
 #include "kconfig.h"  #include "kconfig.h"
 #include "midiallg.h"  #include "midiallg.h"
   
   #include "altsound.h"
   
 int digi_driver_board                                   = 0;  int digi_driver_board                                   = 0;
 int digi_driver_port = 0;  int digi_driver_port = 0;
 int digi_driver_irq = 0;  int digi_driver_irq = 0;
 int digi_driver_dma = 0;  int digi_driver_dma = 0;
 //int digi_midi_type                                    = 0;                    // Midi driver type  
 //int digi_midi_port                                    = 0;                    // Midi driver port  
 int digi_timer_rate = 9943; // rate for the timer to go off to handle the driver system (120 Hz)  int digi_timer_rate = 9943; // rate for the timer to go off to handle the driver system (120 Hz)
   
 #ifndef ALLG_MIDI  #ifndef ALLG_MIDI
Line 182
 
Line 179
  unsigned int position; // Position we are at at the moment.   unsigned int position; // Position we are at at the moment.
 } SoundSlots[MAX_SOUND_SLOTS];  } SoundSlots[MAX_SOUND_SLOTS];
   
 //static SDL_AudioSpec WaveSpec;  
 static int digi_sounds_initialized = 0;  static int digi_sounds_initialized = 0;
   
 //added on 980905 by adb to add rotating/volume based sound kill system  //added on 980905 by adb to add rotating/volume based sound kill system
Line 201
 
Line 197
  unsigned char *streamend;   unsigned char *streamend;
  struct sound_slot *sl;   struct sound_slot *sl;
   
 //    if (grd_curscreen)  
 //   grd_curscreen->sc_canvas.cv_bitmap.bm_data[8]++;  
  len &= ~1; /* stereo -> always write 2 byte pairs */   len &= ~1; /* stereo -> always write 2 byte pairs */
  streamend = stream + len;   streamend = stream + len;
   
 #if 0  
 {  
  static int n = 0;  
  while(stream < streamend) {  
     *(stream++) = (n & 256) ? 256 - (n & 255) : (n & 255);  
     n++;  
  }  
  return len;  
 }  
 #endif  
   
  memset(stream, 0x80, len);   memset(stream, 0x80, len);
   
  for (sl = SoundSlots; sl < SoundSlots + MAX_SOUND_SLOTS; sl++)   for (sl = SoundSlots; sl < SoundSlots + MAX_SOUND_SLOTS; sl++)
Line 276
 
Line 259
   
 void mm_timer() {  void mm_timer() {
     drv->Update();      drv->Update();
 //    if (grd_curscreen)  
 //   (*grd_curscreen->sc_canvas.cv_bitmap.bm_data)++;  
 }  }
   
 /* Initialise audio devices. */  /* Initialise audio devices. */
Line 287
 
Line 268
  memset(SampleHandles, 255, sizeof(SampleHandles));   memset(SampleHandles, 255, sizeof(SampleHandles));
  //end edit by adb   //end edit by adb
   
  #if 0  
  WaveSpec.freq = 11025;  
  WaveSpec.format = AUDIO_U8 | AUDIO_STEREO;  
  WaveSpec.samples = SOUND_BUFFER_SIZE;  
  WaveSpec.callback = audio_mixcallback;  
   
  if ( SDL_OpenAudio(&WaveSpec, NULL) < 0 ) {  
   printf("Couldn't open audio: %s\n", SDL_GetError());  
   exit(2);  
  }  
  SDL_PauseAudio(0);  
 #endif  
  if (!drv->Init()) {   if (!drv->Init()) {
  printf("Couldn't open audio: %s", myerr);   printf("Couldn't open audio: %s", myerr);
  return -1;   return -1;
Line 348
 
Line 317
  #endif   #endif
 }  }
   
 /* Find the sound which actually equates to a sound number */  
 int digi_xlat_sound(int soundno)  
 {  
  if ( soundno < 0 ) return -1;  
   
  if ( digi_lomem ) {  
  soundno = AltSounds[soundno];  
  if ( soundno == 255 ) return -1;  
  }  
  return Sounds[soundno];  
 }  
   
 static int get_free_slot()  static int get_free_slot()
 {  {
  int i;   int i;
Line 375
 
Line 332
  int ntries;   int ntries;
  int slot;   int slot;
   
  if (!digi_initialised) return -1;     if (!digi_initialised)
       return -1;
   
  //added on 980905 by adb from original source to add sound kill system   //added on 980905 by adb from original source to add sound kill system
  // play at most digi_max_channel samples, if possible kill sample with low volume   // play at most digi_max_channel samples, if possible kill sample with low volume
Line 386
 
Line 344
  {   {
   if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) )    if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) )
   {    {
    //mprintf(( 0, "Not stopping loud sound %d.\n", next_handle ));  
    next_handle++;     next_handle++;
    if ( next_handle >= digi_max_channels )     if ( next_handle >= digi_max_channels )
     next_handle = 0;      next_handle = 0;
    ntries++;     ntries++;
    goto TryNextChannel;     goto TryNextChannel;
   }    }
   //mprintf(( 0, "[SS:%d]", next_handle ));  
   SoundSlots[SampleHandles[next_handle]].playing = 0;    SoundSlots[SampleHandles[next_handle]].playing = 0;
   SampleHandles[next_handle] = -1;    SampleHandles[next_handle] = -1;
  }   }
  //end edit by adb   //end edit by adb
   
  slot = get_free_slot();   slot = get_free_slot();
  if (slot<0) return -1;     if (slot<0)
       return -1;
   
  if (volume > F2_0)   if (volume > F2_0)
   volume = F2_0;    volume = F2_0;
   
  SoundSlots[slot].soundno = soundnum;   SoundSlots[slot].soundno = soundnum;
  SoundSlots[slot].samples = GameSounds[soundnum].data;    SoundSlots[slot].samples = Sounddat(soundnum)->data;
  SoundSlots[slot].length = GameSounds[soundnum].length;    SoundSlots[slot].length = Sounddat(soundnum)->length;
  SoundSlots[slot].volume = fixmul(digi_volume, volume);   SoundSlots[slot].volume = fixmul(digi_volume, volume);
  SoundSlots[slot].pan = pan;   SoundSlots[slot].pan = pan;
  SoundSlots[slot].position = 0;   SoundSlots[slot].position = 0;
Line 439
 
Line 397
 {  {
  int slot;   int slot;
   
  if (!digi_initialised) return -1;     if (!digi_initialised)
       return -1;
   
  slot = get_free_slot();   slot = get_free_slot();
   
  if (slot<0) return -1;     if (slot<0)
       return -1;
   
   
  SoundSlots[slot].soundno = SoundObjects[obj].soundnum;   SoundSlots[slot].soundno = SoundObjects[obj].soundnum;
  SoundSlots[slot].samples = GameSounds[SoundObjects[obj].soundnum].data;    SoundSlots[slot].samples = Sounddat(SoundObjects[obj].soundnum)->data;
  SoundSlots[slot].length = GameSounds[SoundObjects[obj].soundnum].length;    SoundSlots[slot].length = Sounddat(SoundObjects[obj].soundnum)->length;
  SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume);   SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume);
  SoundSlots[slot].pan = SoundObjects[obj].pan;   SoundSlots[slot].pan = SoundObjects[obj].pan;
  SoundSlots[slot].position = 0;   SoundSlots[slot].position = 0;
Line 474
 
Line 435
  if ( Newdemo_state == ND_STATE_RECORDING )   if ( Newdemo_state == ND_STATE_RECORDING )
  newdemo_record_sound( soundno );   newdemo_record_sound( soundno );
 #endif  #endif
  soundno = digi_xlat_sound(soundno);     if (!digi_initialised)
       return;
   
  if (!digi_initialised) return;     if (digi_xlat_sound(soundno) < 0 )
       return;
  if (soundno < 0 ) return;  
   
  digi_start_sound(soundno, max_volume, F0_5);   digi_start_sound(soundno, max_volume, F0_5);
 }  }
Line 493
 
Line 454
  if ( Newdemo_state == ND_STATE_RECORDING )   if ( Newdemo_state == ND_STATE_RECORDING )
  newdemo_record_sound( soundno );   newdemo_record_sound( soundno );
 #endif  #endif
  soundno = digi_xlat_sound(soundno);     if (!digi_initialised)
       return;
  if (!digi_initialised) return;  
   
  if (soundno < 0 ) return;     if (digi_xlat_sound(soundno) < 0 )
       return;
   
         for (i=0; i < MAX_SOUND_SLOTS; i++)          for (i=0; i < MAX_SOUND_SLOTS; i++)
           if (SoundSlots[i].soundno == soundno)            if (SoundSlots[i].soundno == soundno)
             SoundSlots[i].playing = 0;              SoundSlots[i].playing = 0;
  digi_start_sound(soundno, max_volume, F0_5);  
   
     digi_start_sound(soundno, max_volume, F0_5);
 }  }
   
 void digi_play_sample_3d( int soundno, int angle, int volume, int no_dups ) // Volume from 0-0x7fff  void digi_play_sample_3d( int soundno, int angle, int volume, int no_dups ) // Volume from 0-0x7fff
Line 511
 
Line 472
  no_dups = 1;   no_dups = 1;
   
 #ifdef NEWDEMO  #ifdef NEWDEMO
  if ( Newdemo_state == ND_STATE_RECORDING ) {     if ( Newdemo_state == ND_STATE_RECORDING )
       {
  if ( no_dups )   if ( no_dups )
  newdemo_record_sound_3d_once( soundno, angle, volume );   newdemo_record_sound_3d_once( soundno, angle, volume );
  else   else
  newdemo_record_sound_3d( soundno, angle, volume );   newdemo_record_sound_3d( soundno, angle, volume );
  }   }
 #endif  #endif
  soundno = digi_xlat_sound(soundno);  
   
  if (!digi_initialised) return;     if (!digi_initialised)
  if (soundno < 0 ) return;      return;
      if (digi_xlat_sound(soundno) < 0 )
       return;
   
      if (volume < MIN_VOLUME )
       return;
   
  if (volume < MIN_VOLUME ) return;  
  digi_start_sound(soundno, volume, angle);   digi_start_sound(soundno, volume, angle);
 }  }
   
Line 563
 
Line 528
  }      }  
 }  }
   
 int digi_link_sound_to_object2( int org_soundnum, short objnum, int forever, fix max_volume, fix  max_distance )  int digi_link_sound_to_object2( int soundnum, short objnum, int forever, fix max_volume, fix  max_distance )
 {  {
  int i,volume,pan;   int i,volume,pan;
  object * objp;   object * objp;
  int soundnum;  
   
  soundnum = digi_xlat_sound(org_soundnum);  
   
  if ( max_volume < 0 ) return -1;     if ( max_volume < 0 )
 // if ( max_volume > F1_0 ) max_volume = F1_0;      return -1;
       if (!digi_initialised)
       return -1;
      if (digi_xlat_sound(soundnum) < 0 )
       return -1;
   
  if (!digi_initialised) return -1;     if (Sounddat(soundnum)->data==NULL)
  if (soundnum < 0 ) return -1;      {
  if (GameSounds[soundnum].data==NULL) {  
  Int3();   Int3();
  return -1;   return -1;
  }   }
   
  if ((objnum<0)||(objnum>Highest_object_index))   if ((objnum<0)||(objnum>Highest_object_index))
  return -1;   return -1;
   
  if ( !forever ) {     if ( !forever )
       {
  // Hack to keep sounds from building up...   // Hack to keep sounds from building up...
  digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance );   digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance );
  digi_play_sample_3d( org_soundnum, pan, volume, 0 );        digi_play_sample_3d( soundnum, pan, volume, 0 );
  return -1;   return -1;
  }   }
   
Line 594
 
Line 561
         if (SoundObjects[i].flags==0)          if (SoundObjects[i].flags==0)
             break;              break;
   
  if (i==MAX_SOUND_OBJECTS) {     if (i==MAX_SOUND_OBJECTS)
       {
  mprintf((1, "Too many sound objects!\n" ));   mprintf((1, "Too many sound objects!\n" ));
  return -1;   return -1;
  }   }
   
  SoundObjects[i].signature=next_signature++;   SoundObjects[i].signature=next_signature++;
  SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_OBJ;   SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_OBJ;
   
  if ( forever )   if ( forever )
  SoundObjects[i].flags |= SOF_PLAY_FOREVER;   SoundObjects[i].flags |= SOF_PLAY_FOREVER;
  SoundObjects[i].lo_objnum = objnum;   SoundObjects[i].lo_objnum = objnum;
Line 623
 
Line 592
 }  }
   
 int digi_link_sound_to_object( int soundnum, short objnum, int forever, fix max_volume )  int digi_link_sound_to_object( int soundnum, short objnum, int forever, fix max_volume )
 { return digi_link_sound_to_object2( soundnum, objnum, forever, max_volume, 256*F1_0); }  {
     return digi_link_sound_to_object2( soundnum, objnum, forever, max_volume, 256*F1_0);
   }
   
 int digi_link_sound_to_pos2( int org_soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance )  int digi_link_sound_to_pos2( int soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance )
 {  {
  int i, volume, pan;   int i, volume, pan;
  int soundnum;  
   
  soundnum = digi_xlat_sound(org_soundnum);  
   
  if ( max_volume < 0 ) return -1;     if ( max_volume < 0 )
 // if ( max_volume > F1_0 ) max_volume = F1_0;      return -1;
      if (!digi_initialised)
  if (!digi_initialised) return -1;      return -1;
  if (soundnum < 0 ) return -1;     if (digi_xlat_sound(soundnum) < 0 )
  if (GameSounds[soundnum].data==NULL) {      return -1;
      if (Sounddat(soundnum)->data==NULL)
       {
  Int3();   Int3();
  return -1;   return -1;
  }   }
   
  if ((segnum<0)||(segnum>Highest_segment_index))   if ((segnum<0)||(segnum>Highest_segment_index))
  return -1;   return -1;
   
  if ( !forever ) {     if ( !forever )
       {
  // Hack to keep sounds from building up...   // Hack to keep sounds from building up...
  digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance );   digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance );
  digi_play_sample_3d( org_soundnum, pan, volume, 0 );        digi_play_sample_3d( soundnum, pan, volume, 0 );
  return -1;   return -1;
  }   }
   
Line 656
 
Line 626
  if (SoundObjects[i].flags==0)   if (SoundObjects[i].flags==0)
  break;   break;
    
  if (i==MAX_SOUND_OBJECTS) {     if (i==MAX_SOUND_OBJECTS)
       {
  mprintf((1, "Too many sound objects!\n" ));   mprintf((1, "Too many sound objects!\n" ));
  return -1;   return -1;
  }   }
   
   
  SoundObjects[i].signature=next_signature++;  
  SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_POS;  
  if ( forever )   if ( forever )
  SoundObjects[i].flags |= SOF_PLAY_FOREVER;   SoundObjects[i].flags |= SOF_PLAY_FOREVER;
     SoundObjects[i].signature=next_signature++;
     SoundObjects[i].flags = SOF_USED | SOF_LINK_TO_POS;
  SoundObjects[i].lp_segnum = segnum;   SoundObjects[i].lp_segnum = segnum;
  SoundObjects[i].lp_sidenum = sidenum;   SoundObjects[i].lp_sidenum = sidenum;
  SoundObjects[i].lp_position = *pos;   SoundObjects[i].lp_position = *pos;
Line 694
 
Line 664
 {  {
  int i,killed;   int i,killed;
   
  soundnum = digi_xlat_sound(soundnum);     if (!digi_initialised)
       return;
  if (!digi_initialised) return;  
   
  killed = 0;   killed = 0;
   
  for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {     for (i=0; i<MAX_SOUND_OBJECTS; i++ )
  if ( (SoundObjects[i].flags & SOF_USED) && (SoundObjects[i].flags & SOF_LINK_TO_POS) ) {      if ( (SoundObjects[i].flags & SOF_USED) &&
  if ((SoundObjects[i].lp_segnum == segnum) && (SoundObjects[i].soundnum==soundnum ) && (SoundObjects[i].lp_sidenum==sidenum) ) {           (SoundObjects[i].flags & SOF_LINK_TO_POS) &&
  if ( SoundObjects[i].flags & SOF_PLAYING ) {           (SoundObjects[i].lp_segnum == segnum) &&
            (SoundObjects[i].soundnum==soundnum) &&
            (SoundObjects[i].lp_sidenum==sidenum) )
        {
           if ( SoundObjects[i].flags & SOF_PLAYING )
          SoundSlots[SoundObjects[i].handle].playing = 0;           SoundSlots[SoundObjects[i].handle].playing = 0;
  }  
  SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound   SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
  killed++;   killed++;
  }   }
  }  
  }  
  // If this assert happens, it means that there were 2 sounds   // If this assert happens, it means that there were 2 sounds
  // that got deleted. Weird, get John.   // that got deleted. Weird, get John.
  if ( killed > 1 ) {     if ( killed > 1 )
  mprintf( (1, "ERROR: More than 1 sounds were deleted from seg %d\n", segnum ));   mprintf( (1, "ERROR: More than 1 sounds were deleted from seg %d\n", segnum ));
  }   }
 }  
   
 void digi_kill_sound_linked_to_object( int objnum )  void digi_kill_sound_linked_to_object( int objnum )
 {  {
Line 830
 
Line 800
   
 void digi_init_sounds()  void digi_init_sounds()
 {  {
 //        int i;     if (!digi_initialised)
       return;
  if (!digi_initialised) return;  
   
         digi_reset_digi_sounds();          digi_reset_digi_sounds();
   
 //        for (i=0; i<MAX_SOUND_OBJECTS; i++ )    {  
 //                if (digi_sounds_initialized) {  
 //                        if ( SoundObjects[i].flags & SOF_PLAYING )      {  
 //                                SoundSlots[SoundObjects[i].handle].playing=0;  
 //                        }  
 //                }  
 //                SoundObjects[i].flags = 0;      // Mark as dead, so some other sound can use this sound  
 //        }  
         digi_stop_soundobjects();          digi_stop_soundobjects();
   
         digi_sounds_initialized = 1;          digi_sounds_initialized = 1;
 }  }
   
Line 878
 
Line 837
 {  {
  int i;   int i;
   
  soundno = digi_xlat_sound(soundno);  
   
  for (i = 0; i < MAX_SOUND_SLOTS; i++)   for (i = 0; i < MAX_SOUND_SLOTS; i++)
    //changed on 980905 by adb: added SoundSlots[i].playing &&     //changed on 980905 by adb: added SoundSlots[i].playing &&
    if (SoundSlots[i].playing && SoundSlots[i].soundno == soundno)     if (SoundSlots[i].playing && SoundSlots[i].soundno == soundno)
Line 888
 
Line 845
  return 0;   return 0;
 }  }
   
   
 //void digi_pause_all() { }  
 //void digi_resume_all() { }  
 //void digi_stop_all() { }  
   
  //added on 980905 by adb to make sound channel setting work   //added on 980905 by adb to make sound channel setting work
 void digi_set_max_channels(int n) {   void digi_set_max_channels(int n) {
  digi_max_channels = n;   digi_max_channels = n;

Legend:
line(s) removed in v.1.1 
line(s) changed
 line(s) added in v.1.2