mute implementat
This commit is contained in:
17
main.cpp
17
main.cpp
@@ -160,6 +160,7 @@ int main(int argc, char* argv[]) {
|
|||||||
for (int i=0; i<4; ++i) {
|
for (int i=0; i<4; ++i) {
|
||||||
if ((sdlEvent.button.x >= 12+i*35) && (sdlEvent.button.x <= 45+i*35) && (sdlEvent.button.y >= 2) && (sdlEvent.button.y <= 13) ) {
|
if ((sdlEvent.button.x >= 12+i*35) && (sdlEvent.button.x <= 45+i*35) && (sdlEvent.button.y >= 2) && (sdlEvent.button.y <= 13) ) {
|
||||||
muted[i] = not muted[i];
|
muted[i] = not muted[i];
|
||||||
|
channel[i].setMute(muted[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,18 +209,18 @@ int main(int argc, char* argv[]) {
|
|||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
}
|
}
|
||||||
if (key == SDL_SCANCODE_F4) {
|
if (key == SDL_SCANCODE_F4) {
|
||||||
channel[0].setup(song.GetCurrentNote(0, selected_row));
|
for (int i=0;i<4;++i) {
|
||||||
channel[1].setup(song.GetCurrentNote(1, selected_row));
|
channel[i].setup(song.GetCurrentNote(i, selected_row));
|
||||||
channel[2].setup(song.GetCurrentNote(2, selected_row));
|
channel[i].setMute(muted[i]);
|
||||||
channel[3].setup(song.GetCurrentNote(3, selected_row));
|
}
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
}
|
}
|
||||||
if (key == SDL_SCANCODE_F5) {
|
if (key == SDL_SCANCODE_F5) {
|
||||||
song.Play();
|
song.Play();
|
||||||
channel[0].setup(song.GetCurrentNote(0));
|
for (int i=0;i<4;++i) {
|
||||||
channel[1].setup(song.GetCurrentNote(1));
|
channel[i].setup(song.GetCurrentNote(i));
|
||||||
channel[2].setup(song.GetCurrentNote(2));
|
channel[i].setMute(muted[i]);
|
||||||
channel[3].setup(song.GetCurrentNote(3));
|
}
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
}
|
}
|
||||||
if (key == SDL_SCANCODE_F8) {
|
if (key == SDL_SCANCODE_F8) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ toneGen::toneGen() {
|
|||||||
this->instrument = CHIPTUNE_INSTRUMENT_NOISE;
|
this->instrument = CHIPTUNE_INSTRUMENT_NOISE;
|
||||||
this->volume = 0;
|
this->volume = 0;
|
||||||
this->effect = CHIPTUNE_EFFECT_FADEOUT;
|
this->effect = CHIPTUNE_EFFECT_FADEOUT;
|
||||||
|
this->muted = false;
|
||||||
|
|
||||||
this->current_volume = this->nominal_volume = 1.0f;
|
this->current_volume = this->nominal_volume = 1.0f;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ void toneGen::setup(const uint8_t note, const uint8_t instrument, const uint8_t
|
|||||||
this->instrument = instrument;
|
this->instrument = instrument;
|
||||||
this->volume = volume;
|
this->volume = volume;
|
||||||
this->effect = effect;
|
this->effect = effect;
|
||||||
|
this->muted = false;
|
||||||
|
|
||||||
this->nominal_volume = float(volume) / 15.0f;
|
this->nominal_volume = float(volume) / 15.0f;
|
||||||
this->current_volume = this->effect == CHIPTUNE_EFFECT_FADEIN ? 0.0f : this->nominal_volume;
|
this->current_volume = this->effect == CHIPTUNE_EFFECT_FADEIN ? 0.0f : this->nominal_volume;
|
||||||
@@ -92,9 +94,13 @@ const int toneGen::getSamples(const int numSamples, Sint16 *buffer) {
|
|||||||
buffer[i] = (rand()*2)-AUDIO_FORMAT_MAX_VALUE;
|
buffer[i] = (rand()*2)-AUDIO_FORMAT_MAX_VALUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buffer[i] *= this->current_volume;
|
buffer[i] *= (muted ? 0 : this->current_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->current_pos += actual_samples_generated;
|
this->current_pos += actual_samples_generated;
|
||||||
return actual_samples_generated;
|
return actual_samples_generated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void toneGen::setMute(const bool value) {
|
||||||
|
muted = value;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class toneGen {
|
|||||||
void setup(const uint8_t note, const uint8_t instrument, const uint8_t volume, const uint8_t effect);
|
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);
|
void setup(const uint16_t tracker_note);
|
||||||
const int getSamples(const int numSamples, Sint16 *buffer);
|
const int getSamples(const int numSamples, Sint16 *buffer);
|
||||||
|
void setMute(const bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t note, instrument, volume, effect;
|
uint8_t note, instrument, volume, effect;
|
||||||
@@ -29,4 +30,5 @@ class toneGen {
|
|||||||
int note_length;
|
int note_length;
|
||||||
int current_pos;
|
int current_pos;
|
||||||
float vibrato_counter;
|
float vibrato_counter;
|
||||||
|
bool muted;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user