1
2// NES non-linear audio output handling.
3
4// Nes_Snd_Emu 0.1.7. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
5
6#ifndef NONLINEAR_BUFFER_H
7#define NONLINEAR_BUFFER_H
8
9#include "Multi_Buffer.h"
10class Nes_Apu;
11
12// Use to make samples non-linear in Blip_Buffer used for triangle, noise, and DMC only
13class Nes_Nonlinearizer {
14public:
15 Nes_Nonlinearizer();
16
17 // Must be called when buffer is cleared
18 void clear() { accum = 0x8000; }
19
20 // Enable/disable non-linear output
21 void enable( Nes_Apu&, bool = true );
22
23 // Make at most 'count' samples in buffer non-linear and return number
24 // of samples modified. This many samples must then be read out of the buffer.
25 long make_nonlinear( Blip_Buffer&, long count );
26
27private:
28 enum { shift = 5 };
29 enum { half = 0x8000 >> shift };
30 enum { entry_mask = half * 2 - 1 };
31 BOOST::uint16_t table [half * 2];
32 long accum;
33 bool nonlinear;
34};
35
36class Nonlinear_Buffer : public Multi_Buffer {
37public:
38 Nonlinear_Buffer();
39 ~Nonlinear_Buffer();
40
41 // Enable/disable non-linear output
42 void enable_nonlinearity( Nes_Apu&, bool = true );
43
44 // Blip_Buffer to output other sound chips to
45 Blip_Buffer* buffer() { return &buf; }
46
47 // See Multi_Buffer.h
48 blargg_err_t sample_rate( long rate, int msec = blip_default_length );
49 using Multi_Buffer::sample_rate;
50 void clock_rate( long );
51 void bass_freq( int );
52 void clear();
53 channel_t channel( int );
54 void end_frame( blip_time_t, bool unused = true );
55 long samples_avail() const;
56 long read_samples( blip_sample_t*, long );
57
58private:
59 Blip_Buffer buf;
60 Blip_Buffer tnd;
61 Nes_Nonlinearizer nonlinearizer;
62};
63
64#endif
65
66