1 /*************************************************************************** 2 Sound Chip 3 4 This is an abstract class, used by the Sega PCM and YM2151 chips. 5 It facilitates writing to a buffer of sound data. 6 7 Copyright Chris White. 8 See license.txt for more details. 9 ***************************************************************************/ 10 11 #pragma once 12 13 class SoundChip 14 { 15 public: 16 bool initalized; 17 18 // Sample Frequency in use 19 uint32_t sample_freq; 20 21 // How many channels to support (mono/stereo) 22 uint8_t channels; 23 24 // Size of the buffer (including channel info) 25 uint32_t buffer_size; 26 27 SoundChip(); 28 ~SoundChip(); 29 30 void init(uint8_t, int32_t, int32_t); 31 32 // Pure virtual function. Denotes virtual class. 33 virtual void stream_update() = 0; 34 35 int16_t* get_buffer(); 36 void set_volume(uint8_t); 37 38 protected: 39 const static uint8_t MONO = 1; 40 const static uint8_t STEREO = 2; 41 42 const static uint8_t LEFT = 0; 43 const static uint8_t RIGHT = 1; 44 45 // Buffer size for one frame (excluding channel info) 46 uint32_t frame_size; 47 48 // Volume of sound chip 49 float volume; 50 51 void clear_buffer(); 52 void write_buffer(const uint8_t, uint32_t, int16_t); 53 int16_t read_buffer(const uint8_t, uint32_t); 54 55 private: 56 // Sound buffer stream 57 int16_t* buffer; 58 59 // Frames per second 60 uint32_t fps; 61 };