File: play.c

package info (click to toggle)
s3mod 1.09-14
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 256 kB
  • ctags: 354
  • sloc: ansic: 2,919; makefile: 153; sh: 8
file content (185 lines) | stat: -rw-r--r-- 4,307 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/***************************************************************************
 *   S3m/Mod player by Daniel Marks (dmarks@ais.net)
 *   GUS support by David Jeske (jeske@uiuc.edu)
 *
 * (C) 1994,1995 By Daniel Marks and David Jeske
 *
 * While we retain the copyright to this code, this source code is FREE.
 * You may use it in any way you wish, in any product you wish. You may 
 * NOT steal the copyright for this code from us.
 *
 * We respectfully ask that you email one of us, if possible, if you
 * produce something significant with this code, or if you have any bug 
 * fixes to contribute.  We also request that you give credit where
 * credit is due if you include part of this code in a program of your own.
 *                                                 
 * Email: s3mod@uiuc.edu
 *        jeske@uiuc.edu
 *
 * See the associated README file for Thanks
 ***************************************************************************
 *
 * play.c - the player itself
 *
 */

#include "config.h"

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

#include "main.h"
#include "mod.h"
#include "play.h"
#include "dsp.h"

#ifdef GUS
#include <linux/ultrasound.h>
#include "gus.h"
#endif /* GUS */


union
{
  uint8                   rot_buf[ROT_BUF_SIZE];
  uint16                  rot_buf16[ROT_BUF_SIZE];
} buf;

void updatetracks(void)
{
  track_info_ptr track;
  int16 count;

  tempo_wait = tempo;
  if (row >= 64)
  {
    if (order_pos >= mod.song_length_patterns)
    {
      order_pos = mod.song_repeat_patterns;
      if (order_pos >= mod.song_length_patterns)
      {
        order_pos = 0;
        mod_done = 1;
      }
    }
    row = break_row;
    break_row = 0;
    if (mod.positions[order_pos] == 0xFF)
    {
      mod_done = 1;
      return;
    }
    if (mod.s3m)
      note = mod.patterns[mod.positions[order_pos]];
      else
      note = mod.patterns[mod.positions[order_pos]] + 
             (((uint16)row) * sizeof(uint8) * 4 * mod.tracks);
    order_pos++;
  }
  row++;
  if (mod.s3m)
    get_track_s3m(&note);
    else
    {
      track = tracks;
      for (count=0;count<mod.tracks;count++)
        get_track(track++,&note);
     
    }
  track = tracks;
  for (count=0;count<mod.tracks;count++)
  {
    track->playing_period = track->period;
    track->playing_volume = track->volume;
    track++;
  }

#ifdef DEBUG
  printf("00-01-02-03-04-05-06-07-pattern %d row %d\n",order_pos,row);
#endif
  return;
}


void play_mod(int loud)
{
  register uint8 *c;
  register uint16 *d;
  int16 i;
  track_info_ptr track;
  int16 count;

  startplaying(loud);
  mod_done = 0;
  while (!mod_done)
  {
    if (--tempo_wait)
      {
	track = tracks;
	for (count=0;count<mod.tracks;count++)
	  beattrack(track++);
      }
    else
      updatetracks();

    track = tracks;
    if (bit16)
    {
      if (stereo)
         for (d=&buf.rot_buf16[bpm_samples << 1];d > buf.rot_buf16;*(--d) = 0x8000);
         else
         for (d=&buf.rot_buf16[bpm_samples];d > buf.rot_buf16;*(--d) = 0x8000);
    } else
    {
      if (stereo)
         for (c=&buf.rot_buf[bpm_samples << 1];c > buf.rot_buf;*(--c) = 0x80);
         else
         for (c=&buf.rot_buf[bpm_samples];c > buf.rot_buf;*(--c) = 0x80);
    }
    for (i=0;i<mod.tracks;i++)
    {

      if (bit16)
      {
        if (stereo)
          mixtrack_16_stereo(track,buf.rot_buf16,bpm_samples,
                             i & 0x01);
          else
          mixtrack_16_mono(track,buf.rot_buf16,bpm_samples);
      } else
      {
        if (stereo)
          mixtrack_8_stereo(track,buf.rot_buf,bpm_samples,
                             i & 0x01);
          else
          mixtrack_8_mono(track,buf.rot_buf,bpm_samples);
      }
      track++;
    }
    c = (uint8 *) buf.rot_buf;
    if (stereo)
    {
      if (bit16)
        d = (uint16 *) &c[bpm_samples << 2];
        else
        d = (uint16 *) &c[bpm_samples << 1];
    } else
    {
      if (bit16)
        d = (uint16 *) &c[bpm_samples << 1];
        else
        d = (uint16 *) &c[bpm_samples];
    }
    while (c < ((uint8 *)d))
    {
      if (audio_curptr >= audio_end_buffer)
      {
      	write_dsp_device(audio_start_buffer,audio_buffer_size);
        audio_curptr = audio_start_buffer;
      }
      *audio_curptr++ = *c++;
    }
  } 
}