Subversion Repositories Kolibri OS

Rev

Rev 342 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 342 Rev 374
Line 47... Line 47...
47
#include "w_wad.h"
47
#include "w_wad.h"
Line 48... Line 48...
48
 
48
 
Line 49... Line 49...
49
#include "doomdef.h"
49
#include "doomdef.h"
-
 
50
 
Line 50... Line 51...
50
 
51
#include "kolibri.h"
51
#include "kolibri.h"
52
#include "sound.h"
52
 
53
 
53
// The number of internal mixing channels,
54
// The number of internal mixing channels,
Line 54... Line 55...
54
//  the samples calculated for each mixing step,
55
//  the samples calculated for each mixing step,
55
//  the size of the 16bit, 2 hardware channel (stereo)
56
//  the size of the 16bit, 2 hardware channel (stereo)
56
//  mixing buffer, and the samplerate of the raw data.
57
//  mixing buffer, and the samplerate of the raw data.
57
 
58
 
58
 
59
 
59
// Needed for calling the actual sound output.
60
// Needed for calling the actual sound output.
Line 60... Line 61...
60
#define SAMPLECOUNT     8192
61
#define SAMPLECOUNT     1024
61
#define NUM_CHANNELS    16
62
#define NUM_CHANNELS    16
Line 62... Line 63...
62
// It is 2 for 16bit, and 2 for two channels.
63
// It is 2 for 16bit, and 2 for two channels.
Line 74... Line 75...
74
 
75
 
75
// The global mixing buffer.
76
// The global mixing buffer.
76
// Basically, samples from all active internal channels
77
// Basically, samples from all active internal channels
77
//  are modifed and added, and stored in the buffer
78
//  are modifed and added, and stored in the buffer
78
//  that is submitted to the audio device.
79
//  that is submitted to the audio device.
79
signed short    mixbuffer[MIXBUFFERSIZE];
-
 
Line 80... Line 80...
80
 
80
signed short    *mixbuffer;
81
 
81
 
82
// The channel step amount...
82
// The channel step amount...
83
unsigned int    channelstep[NUM_CHANNELS];
83
unsigned int    channelstep[NUM_CHANNELS];
Line 289... Line 289...
289
    rightvol =
289
    rightvol =
290
        volume - ((volume*seperation*seperation) >> 16);        
290
        volume - ((volume*seperation*seperation) >> 16);        
Line 291... Line 291...
291
 
291
 
292
    // Sanity check, clamp volume.
292
    // Sanity check, clamp volume.
-
 
293
    if (rightvol < 0 || rightvol > 127)
293
    if (rightvol < 0 || rightvol > 127)
294
    {
-
 
295
        printf("rightvol out of bounds\n\r");
-
 
296
        rightvol = 0;
-
 
297
 
Line 294... Line 298...
294
        I_Error("rightvol out of bounds");
298
    }
-
 
299
    
295
    
300
    if (leftvol < 0 || leftvol > 127)
-
 
301
    {
-
 
302
        printf("leftvol out of bounds\n\r");
Line 296... Line 303...
296
    if (leftvol < 0 || leftvol > 127)
303
        leftvol=0;
297
        I_Error("leftvol out of bounds");
304
    }
298
    
305
    
299
    // Get the proper lookup table piece
306
    // Get the proper lookup table piece
Line 424... Line 431...
424
//  hardware channels (left and right, that is).
431
//  hardware channels (left and right, that is).
425
//
432
//
426
// This function currently supports only 16bit.
433
// This function currently supports only 16bit.
427
//
434
//
Line 428... Line 435...
428
 
435
 
-
 
436
extern SNDBUF hMixBuff;
429
extern DWORD hMixBuff[4];
437
extern unsigned int mix_offset;
Line 430... Line 438...
430
extern int mix_ptr;
438
extern int mix_size;
431
 
439
 
Line 432... Line 440...
432
void I_UpdateSound( void )
440
void I_UpdateSound( void )
Line 439... Line 447...
439
  register int          dr;
447
  register int          dr;
Line 440... Line 448...
440
  
448
  
441
  // Pointers in global mixbuffer, left, right, end.
449
  // Pointers in global mixbuffer, left, right, end.
442
  signed short*         leftout;
450
  signed short*         leftout;
443
  signed short*         rightout;
451
  signed short*         rightout;
444
  signed short*         leftend;
452
//  signed short*         leftend;
445
  // Step in mixbuffer, left and right, thus two.
453
  // Step in mixbuffer, left and right, thus two.
Line 446... Line 454...
446
  int                           step;
454
  int                           step;
447
 
455
 
448
  // Mixing channel index.
456
  // Mixing channel index.
449
  int                           chan;
457
  int                           chan;
450
  int i;
458
  int i;
Line 451... Line 459...
451
  int flags;
459
  int flags;
452
  flags = 0;
460
  int size = 0;
453
    
461
    
454
    // Left and right channel
462
    // Left and right channel
455
    //  are in global mixbuffer, alternating.
463
    //  are in global mixbuffer, alternating.
Line 456... Line 464...
456
    leftout = mixbuffer;
464
    leftout = mixbuffer;
457
    rightout = mixbuffer+1;
465
    rightout = mixbuffer+1;
458
    step = 2;
466
    step = 2;
Line 459... Line 467...
459
 
467
 
460
    // Determine end, for left channel only
468
    // Determine end, for left channel only
461
    //  (right channel is implicit).
469
    //  (right channel is implicit).
462
    leftend = mixbuffer + SAMPLECOUNT*step;
470
  //  leftend = mixbuffer + SAMPLECOUNT*step;
463
 
471
 
464
    // Mix sounds into the mixing buffer.
472
    // Mix sounds into the mixing buffer.
465
    // Loop over step*SAMPLECOUNT,
473
    // Loop over step*SAMPLECOUNT,
466
    //  that is 512 values for two channels.
474
    //  that is 512 values for two channels.
Line 467... Line 475...
467
    for (i=0; i < 8192; i++)
475
    for (i=0; i < mix_size/4; i++)
468
    {
476
    {
469
        // Reset left/right value. 
477
        // Reset left/right value. 
-
 
478
        dl = 0;
-
 
479
        dr = 0;
470
        dl = 0;
480
 
471
        dr = 0;
481
        // Love thy L2 chache - made this a loop.
472
 
482
        // Now more channels could be set at compile time
473
        // Love thy L2 chache - made this a loop.
483
        //  as well. Thus loop those  channels.
474
        // Now more channels could be set at compile time
484
  //      flags=0;
475
        //  as well. Thus loop those  channels.
485
        
Line 476... Line 486...
476
        for ( chan = 0; chan < NUM_CHANNELS; chan++ )
486
        for ( chan = 0; chan < NUM_CHANNELS; chan++ )
477
        {
487
        {
478
            // Check channel, if active.
488
            // Check channel, if active.
479
            if (channels[ chan ])
489
            if (channels[ chan ])
Line 523... Line 533...
523
            *rightout = dr;
533
            *rightout = dr;
Line 524... Line 534...
524
 
534
 
525
        // Increment current pointers in mixbuffer.
535
        // Increment current pointers in mixbuffer.
526
        leftout += step;
536
        leftout += step;
-
 
537
        rightout += step;
-
 
538
//        if (flags)
527
        rightout += step;
539
//          size+=4;
-
 
540
    }
-
 
541
 
-
 
542
    SetBuffer(hMixBuff,mixbuffer,mix_offset,mix_size);
-
 
543
 
-
 
544
 
-
 
545
 //   WaveOut(hMixBuff,(char*)&mixbuffer[0],4096);
528
    }
546
    
-
 
547
//    if(size)
529
    if(flags)
548
//    {
530
    { WaveOut(hMixBuff[mix_ptr],(char*)&mixbuffer[0],32768);
549
//       WaveOut(hMixBuff,(char*)&mixbuffer[0],size);
-
 
550
//       SetBufferPos(hMixBuff, 0);         
-
 
551
//        SetBuffer(hMixBuff,(char*)&mixbuffer[0],mix_offset,4096);
531
      mix_ptr= (mix_ptr+1)&3;
552
//       PlayBuffer(hMixBuff, PCM_SYNC); 
532
    };  
553
//    };  
Line 533... Line 554...
533
}
554
}
534
 
555
 
Line 557... Line 578...
557
 
578
 
558
  // UNUSED.
579
  // UNUSED.
559
  handle = vol = sep = pitch = 0;
580
  handle = vol = sep = pitch = 0;
Line 560... Line -...
560
}
-
 
561
 
-
 
562
void I_ShutdownSound(void)
581
}
563
{    
-
 
564
  // Wait till all pending sounds are finished.
-
 
Line 565... Line -...
565
  int done = 0;
-
 
566
  int i;
582
 
567
  
-
 
568
  // FIXME (below).
-
 
569
  printf( "I_ShutdownSound: NOT finishing pending sounds\n");
583
extern volatile int sound_state;
570
  
-
 
571
  while ( !done )
-
 
572
  {
-
 
573
    for( i=0 ; i<8 && !channels[i] ; i++);
-
 
574
    
584
 
575
    // FIXME. No proper channel output.
-
 
576
    //if (i==8)
585
void I_ShutdownSound(void)
577
    done=1;
586
{    
Line 578... Line 587...
578
  }
587
  sound_state=0;
579
  return;
588
  return;
Line 601... Line 610...
601
  }
610
  }
Line 602... Line 611...
602
 
611
 
Line 603... Line 612...
603
  printf( " pre-cached all sound data\n");
612
  printf( " pre-cached all sound data\n");
604
  
613
  
605
  // Now initialize mixbuffer with zero.
614
  // Now initialize mixbuffer with zero.
Line 606... Line 615...
606
  for ( i = 0; i< MIXBUFFERSIZE; i++ )
615
//  for ( i = 0; i< MIXBUFFERSIZE; i++ )
607
    mixbuffer[i] = 0;
616
 //   mixbuffer[i] = 0;
Line 608... Line 617...
608
  
617