diff --git a/main.cpp b/main.cpp index 199c71e..86d6609 100755 --- a/main.cpp +++ b/main.cpp @@ -25,15 +25,20 @@ int current_instrument = 0; int current_volume = 2; int current_effect = 0; -toneGen tonegen(SOUND_NUM_SAMPLES); +toneGen channel[4]; SDL_AudioDeviceID sdlAudioDevice; +Sint16 auxBuffer[512]; void audioCallback(void* userdata, Uint8* stream, int len) { Sint16* buffer = (Sint16*)stream; - int numSamples = tonegen.getSamples(len >> 1, buffer); - if (numSamples*2 < len) { - int rest = len - numSamples*2; - SDL_memset(&stream[numSamples*2], 0, rest); + int numBytesGenerated = channel[0].getSamples(len >> 1, buffer) * 2; + for (int i=1; i<4; ++i) { + channel[i].getSamples(len >> 1, auxBuffer); + for (int j=0; jnote_length = note_length; +toneGen::toneGen() { this->current_pos = 0; this->note = 34; @@ -24,6 +23,10 @@ toneGen::toneGen(const int note_length) { this->f = -AUDIO_FORMAT_MAX_VALUE; } +void toneGen::setNoteLength(const int note_length) { + this->note_length = note_length; +} + void toneGen::setup(const uint8_t note, const uint8_t instrument, const uint8_t volume, const uint8_t effect) { this->current_pos = 0; diff --git a/tonegen.h b/tonegen.h index ddc3f44..e6c9878 100755 --- a/tonegen.h +++ b/tonegen.h @@ -16,7 +16,8 @@ class toneGen { public: - toneGen(const int note_length); + toneGen(); + void setNoteLength(const int note_length); void setup(const uint8_t note, const uint8_t instrument, const uint8_t volume, const uint8_t effect); void setup(const uint16_t tracker_note); const int getSamples(const int numSamples, Sint16 *buffer);