~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/emucore/TIASnd.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
5
//  SS     tttttt  eeee   ll   ll   aaaa 
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-2005 by Bradford W. Mott
 
12
//
 
13
// See the file "license" for information on usage and redistribution of
 
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
15
//
 
16
// $Id: TIASnd.hxx,v 1.4 2006/01/06 00:31:56 stephena Exp $
 
17
//============================================================================
 
18
 
 
19
#ifndef TIASOUND_HXX
 
20
#define TIASOUND_HXX
 
21
 
 
22
#include "bspf.hxx"
 
23
 
 
24
/**
 
25
  This class implements a fairly accurate emulation of the TIA sound
 
26
  hardware.
 
27
 
 
28
  @author  Bradford W. Mott
 
29
  @version $Id: TIASnd.hxx,v 1.4 2006/01/06 00:31:56 stephena Exp $
 
30
*/
 
31
class TIASound
 
32
{
 
33
  public:
 
34
    /**
 
35
      Create a new TIA Sound object using the specified output frequency
 
36
    */
 
37
    TIASound(Int32 outputFrequency = 31400, Int32 tiaFrequency = 31400,
 
38
             uInt32 channels = 1);
 
39
 
 
40
    /**
 
41
      Destructor
 
42
    */
 
43
    virtual ~TIASound();
 
44
 
 
45
  public:
 
46
    /**
 
47
      Reset the sound emulation to its power-on state
 
48
    */
 
49
    void reset();
 
50
 
 
51
    /**
 
52
      Set the frequency output samples should be generated at
 
53
    */
 
54
    void outputFrequency(Int32 freq);
 
55
 
 
56
    /**
 
57
      Set the frequency the of the TIA device
 
58
    */
 
59
    void tiaFrequency(Int32 freq);
 
60
 
 
61
    /**
 
62
      Selects the number of audio channels per sample (1 = mono, 2 = stereo)
 
63
    */
 
64
    void channels(uInt32 number);
 
65
 
 
66
    /**
 
67
      Set volume clipping (decrease volume range by half to eliminate popping)
 
68
    */
 
69
    void clipVolume(bool clip);
 
70
 
 
71
  public:
 
72
    /**
 
73
      Sets the specified sound register to the given value
 
74
 
 
75
      @param address Register address
 
76
      @param value Value to store in the register
 
77
    */
 
78
    void set(uInt16 address, uInt8 value);
 
79
 
 
80
    /**
 
81
      Gets the specified sound register's value
 
82
 
 
83
      @param address Register address
 
84
    */
 
85
    uInt8 get(uInt16 address);
 
86
 
 
87
    /**
 
88
      Create sound samples based on the current sound register settings
 
89
      in the specified buffer. NOTE: If channels is set to stereo then
 
90
      the buffer will need to be twice as long as the number of samples.
 
91
 
 
92
      @param buffer The location to store generated samples
 
93
      @param samples The number of samples to generate
 
94
    */
 
95
    void process(uInt8* buffer, uInt32 samples);
 
96
 
 
97
    /**
 
98
      Set the volume of the samples created (0-100)
 
99
    */
 
100
    void volume(uInt32 percent);
 
101
 
 
102
  private:
 
103
    /**
 
104
      Frequency divider class which outputs 1 after "divide-by" clocks. This
 
105
      is used to divide the main frequency by the values 1 to 32.
 
106
    */
 
107
    class FreqDiv
 
108
    {
 
109
      public:
 
110
        FreqDiv()
 
111
        {
 
112
          myDivideByValue = myCounter = 0;
 
113
        }
 
114
 
 
115
        void set(uInt32 divideBy)
 
116
        {
 
117
          myDivideByValue = divideBy;
 
118
        }
 
119
 
 
120
        bool clock()
 
121
        {
 
122
          if(++myCounter > myDivideByValue)
 
123
          {
 
124
            myCounter = 0;
 
125
            return true;
 
126
          }
 
127
          return false;
 
128
        }
 
129
 
 
130
      private:
 
131
        uInt32 myDivideByValue;
 
132
        uInt32 myCounter;
 
133
    };
 
134
 
 
135
  private:
 
136
    uInt8 myAUDC[2];
 
137
    uInt8 myAUDF[2];
 
138
    uInt8 myAUDV[2];
 
139
 
 
140
    FreqDiv myFreqDiv[2];    // Frequency dividers
 
141
    uInt8 myP4[2];           // 4-bit register LFSR (lower 4 bits used)
 
142
    uInt8 myP5[2];           // 5-bit register LFSR (lower 5 bits used)
 
143
 
 
144
    Int32  myOutputFrequency;
 
145
    Int32  myTIAFrequency;
 
146
    uInt32 myChannels;
 
147
    Int32  myOutputCounter;
 
148
    uInt32 myVolumePercentage;
 
149
    uInt8  myVolumeClip;
 
150
};
 
151
 
 
152
#endif