File: mtm.C

package info (click to toggle)
gmod 3.1-2
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 1,348 kB
  • ctags: 808
  • sloc: cpp: 7,755; makefile: 82
file content (62 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
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
// -*-C++-*-
// This file is part of the gmod package
// Copyright (C) 1997 by Andrew J. Robinson

#include <string.h>

#include "mtm.h"
#include "Sequencer.h"

void removeNoprint(char *);

int
MTM_sample::load (Sequencer &seq, FILE * modFd, int sampleNo, int cutFactor,
		  void *header, void *)
{
#define MTM_ATTRIBUTE_16BIT 1
  int bytesRead;
  unsigned char *buf = (unsigned char *)header;

  sampleNum_ = sampleNo;
  mode_ = WAVE_UNSIGNED;
  ok_ = 0;
  memcpy(name_, buf, 22);
  name_[22] = '\0';
  removeNoprint(name_);

  length_ = INTEL_LONG(buf + 22);
  loopStart = INTEL_LONG(buf + 26);
  loopEnd = INTEL_LONG(buf + 30);
  finetune_ = *(buf + 34) & 0x0f;

  if (finetune_ <= 7)
    finetune_ *= 12.5;
  else
    finetune_ = (short)(12.5 * (finetune_ - 16));

  volume_ = *(buf + 35);

  if (volume_ > 0)
    volume_ = volume_ * 4 - 1;

  if (*(buf + 36) & MTM_ATTRIBUTE_16BIT)
    mode_ |= WAVE_16_BITS;

  /* found a mod with lots of samples with loopEnds of 2.  played fine
       * without them.  should I check that here?
       */
  if (loopEnd > 2)
    mode_ |= WAVE_LOOPING;
#if 0
  else
    loopEnd = loopStart = 0;
#endif

  baseNote_ = C2FREQ;	/* was 261630 - Middle C */
  baseFreq_ = NTSC_RATE;

  if (length_ > 0)
    ok_ = !seq.patchLoad(modFd, sampleNo, *this, bytesRead, cutFactor);

  return bytesRead;
}