/gme/Sms_Apu.h

http://game-music-emu.googlecode.com/ · C++ Header · 75 lines · 40 code · 18 blank · 17 comment · 0 complexity · 200e36e3fff9aaf574f260ec632dd11d MD5 · raw file

  1. // Sega Master System SN76489 PSG sound chip emulator
  2. // Sms_Snd_Emu 0.1.4
  3. #ifndef SMS_APU_H
  4. #define SMS_APU_H
  5. #include "Sms_Oscs.h"
  6. class Sms_Apu {
  7. public:
  8. // Set overall volume of all oscillators, where 1.0 is full volume
  9. void volume( double );
  10. // Set treble equalization
  11. void treble_eq( const blip_eq_t& );
  12. // Outputs can be assigned to a single buffer for mono output, or to three
  13. // buffers for stereo output (using Stereo_Buffer to do the mixing).
  14. // Assign all oscillator outputs to specified buffer(s). If buffer
  15. // is NULL, silences all oscillators.
  16. void output( Blip_Buffer* mono );
  17. void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right );
  18. // Assign single oscillator output to buffer(s). Valid indicies are 0 to 3,
  19. // which refer to Square 1, Square 2, Square 3, and Noise. If buffer is NULL,
  20. // silences oscillator.
  21. enum { osc_count = 4 };
  22. void osc_output( int index, Blip_Buffer* mono );
  23. void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right );
  24. // Reset oscillators and internal state
  25. void reset( unsigned noise_feedback = 0, int noise_width = 0 );
  26. // Write GameGear left/right assignment byte
  27. void write_ggstereo( blip_time_t, int );
  28. // Write to data port
  29. void write_data( blip_time_t, int );
  30. // Run all oscillators up to specified time, end current frame, then
  31. // start a new frame at time 0.
  32. void end_frame( blip_time_t );
  33. public:
  34. Sms_Apu();
  35. ~Sms_Apu();
  36. private:
  37. // noncopyable
  38. Sms_Apu( const Sms_Apu& );
  39. Sms_Apu& operator = ( const Sms_Apu& );
  40. Sms_Osc* oscs [osc_count];
  41. Sms_Square squares [3];
  42. Sms_Square::Synth square_synth; // used by squares
  43. blip_time_t last_time;
  44. int latch;
  45. Sms_Noise noise;
  46. unsigned noise_feedback;
  47. unsigned looped_feedback;
  48. void run_until( blip_time_t );
  49. };
  50. struct sms_apu_state_t
  51. {
  52. unsigned char regs [8] [2];
  53. unsigned char latch;
  54. };
  55. inline void Sms_Apu::output( Blip_Buffer* b ) { output( b, b, b ); }
  56. inline void Sms_Apu::osc_output( int i, Blip_Buffer* b ) { osc_output( i, b, b, b ); }
  57. #endif