File: main.c

package info (click to toggle)
s3mod 1.09-10
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 248 kB
  • ctags: 354
  • sloc: ansic: 2,856; makefile: 153
file content (260 lines) | stat: -rw-r--r-- 5,381 bytes parent folder | download | duplicates (2)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/***************************************************************************
 *   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
 ***************************************************************************
 *
 * main.c - The main part of the s3mod program.
 *
 */

#include "config.h"

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

#include "mod.h"
#include "play.h"
#include "main.h"
#include "cmdline.h"
#include "dsp.h"
#ifdef GUS
#include "gus.h"
#endif /* GUS */

/*
 * Beginning of real code 
 */

struct option_struct options;
int gus_dev=-1;
int use_gus=1;
int stereo = 0;
int bit16 = 0;

void help(void)
{
  printf("\nS3MOD - S3M/MOD tracker (%s) for Linux/Sun/DEC/SGI\n",VERSION);
#ifdef LINUX
  printf("         Linux Support by Daniel Marks \n");
  printf("           GUS Support by David Jeske (jeske@uiuc.edu)\n");
#endif /* LINUX */
#if defined(__sgi)
  printf("           SGI Support by Mike Muuss (Mike@arl.mil)\n\n");
#endif /* __sgi */
#if defined(SUN) || defined(DEC)
  printf("    SUN/DEC AF Support by Ricky Beam (cramer@catt.ncsu.edu)\n\n");
#endif /* SUN || DEC */
  printf("(C) Copyright 1994 by Daniel L. Marks and David Jeske\n\n");
  printf("For information email (s3mod@uiuc.edu).\n");
  printf("s3mod [-sbfqnl] [sampling frequency] filename\n");
  printf("     -s stereo\n");
#ifdef LINUX
  printf("     -b 16 bit samples\n");
#endif /* ?LINUX */
  printf("     -f set frequency\n");
  printf("     -q quiet (don't print anything)\n");
  printf("     -n don't loop\n");
  printf("     -l loud mode (shift voices louder)\n");
#ifdef LINUX
  printf("     -g do NOT use GUS native mode\n");
#endif /* ?LINUX */
  printf("     -p PAL speed adjustment (145bpm start)\n");
  printf("s3mod -sbf 44100 foobar.mod\n");
  printf("   plays in stereo, 16 bits, 44.1 kHz\n\n");
  printf("This player plays Screamtracker 3 files, and\n");
  printf("4,6,or 8 track MODs.\n\n");
#ifdef DEC
  printf("NOTE: DEC AF support is in it's ALPHA stages\n\n");
#endif /* ?LINUX */
  exit(1);
}


void get_audio_device(void)
{
  int found_gus=0;

#ifdef GUS 
  if (use_gus)
    {
      found_gus = get_gus_device();
    }

 if (!found_gus)
   {gus_dev=-1;
    get_dsp_device();
   }
#else /* GUS */
  get_dsp_device();
#endif /* GUS */

}


void main(int argc, char **argv)
{
  uint32 j;
  char *filename;
  long int frequency;
  int quiet = 0;
  int loud = 0;
  int use_pal = 0;

  mixspeed = DSP_SPEED;

  if (argc < 2) 
    { help();
      exit(1);
    }
 
  parm_setup(argc,argv,"","SsBbQqNnLlGgPp","Ff");

  if (read_parm(NON_FLAGGED, &filename, NULL) != 1)
  {
    help();
    printf("No executable filename found!\n");
    exit(1);
  }

  if (read_parm('S',NULL,NULL))
    stereo=1;
  else
    stereo=0;
  if (read_parm('B',NULL,NULL))
    bit16=1;
  else
    bit16=0;
  if (read_parm('Q',NULL,NULL))
    quiet=1;
  else
    quiet=0;
  if (read_parm('N',NULL,NULL))
    loop_mod = 0;
  else
    loop_mod = 1;
  if (read_parm('L',NULL,NULL))
    loud = 1;
  else
    loud = 0;
#ifdef GUS
  if (read_parm('G',NULL,NULL))
    use_gus = 0;
  else
    use_gus = 1;
#endif /* GUS */
  if (read_parm('P',NULL,NULL))
    use_pal = 1;
  else
    use_pal = 0;


#ifdef SIXTEEN_BIT_PLAY_ONLY
bit16 = 1;
#endif /* SIXTEEN_BIT_PLAY_ONLY */

  if (read_parm('F',NULL,&frequency))
    {
      mixspeed = (frequency);
      if ((mixspeed < 8000) || (mixspeed > 44100))
	{ help();
	  printf("Invalid Frequency: %ld",frequency);
	  exit(1);
	}
    }
    
  if (use_pal)
    { options.def_tempo = DEF_TEMPO_PAL; 
      options.def_bpm   = DEF_BPM_PAL;
    }
  else
    { options.def_tempo = DEF_TEMPO_NTSC;
      options.def_bpm   = DEF_BPM_NTSC;
    }


  get_audio_device();

  if (load_s3m(filename,&mod,quiet))
    if (load_mod(filename,&mod,quiet))
    {
      printf("File is not a valid mod or s3m!\n");
      exit(1);
    }



  if (!quiet) 
  {

    if (gus_dev==-1)
      printf("Playing \"%s\"\nAt rate %d, %d bits, %s, blocksize %d\n",
	     filename,
	     mixspeed,
	     bit16 ? 16 : 8,
	     stereo ? "stereo" : "mono",
	     audio_buffer_size);
    
    else {
#ifdef GUS
      printf("GUS (ALPHA support) Playing \"%s\" \n",filename);
      printf("Using %d of %d bytes of GUS RAM\n",
	     (gus_total_mem - gus_mem_free(gus_dev)),
	     (gus_total_mem));
#else
      printf("GUS support not compiled in...\n");
      exit(1);
#endif /* GUS */
    }


  }


  if (gus_dev!=-1) {
#ifdef GUS    
    play_mod_gus(loud);
#else
    printf("GUS support not compiled in...\n");
    exit(1);
#endif
  } else {
    play_mod(loud);
  }
  
  close_dsp_device();
  free(audio_start_buffer);
}