Skip to content

Commit

Permalink
Using white noise data
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Robson committed Aug 12, 2024
1 parent ea67231 commit fd3da18
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
TODO List

- Implement new white noise
- Check SFX.
- Adjust documentation


Expand Down
2 changes: 1 addition & 1 deletion basic/test.bsc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
noise 0,100,100
noise 0,300,100
end

proc snd(ch,fq,ms,sl,ty,v)
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/include/interface/whitenoise.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define NOISE_SIZE (1024)

static const uint8_t noisepattern[NOISE_SIZE] = {
static const uint8_t noisePattern[NOISE_SIZE] = {
7, 30, 30, 28, 28, 62, 60, 56,120,248,124, 30, 31,143, 7, 7,193,192,224,
241,224,240,227,225,192,224,120,126, 60, 56,224,225,195,195,135,199, 7, 30,
28, 31, 14, 14, 30, 14, 15, 15,195,195,241,225,227,193,227,195,195,252, 60,
Expand Down
15 changes: 4 additions & 11 deletions firmware/common/sources/interface/sndcreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct _ChannelStatus {
int state;
int soundType;
int volume;
bool modulate;
int samplePos;
} audio[CHANNEL_COUNT];

// ***************************************************************************************
Expand Down Expand Up @@ -70,11 +70,8 @@ int16_t SNDGetNextSample(void) {
cs->state ^= 0xFF;
switch (cs->soundType) {
case SOUNDTYPE_NOISE:
if (cs->modulate) {
level += cs->state ? rand() % cs->volume : -(rand() % cs->volume);
} else {
level += rand() % (cs->volume * 2) - cs->volume;
}
level += ((noisePattern[cs->samplePos] - 0x80) * cs->volume / 128);
if (++cs->samplePos == NOISE_SIZE) cs->samplePos = 0;
break;
default: // Square wave
level += cs->state ? cs->volume : -cs->volume;break;
Expand All @@ -101,11 +98,7 @@ void SNDUpdateSoundChannel(uint8_t channel,SOUND_CHANNEL *c) {
audio[channel].adder = SNDGetSampleFrequency() / c->currentFrequency / 2;
audio[channel].soundType = c->currentType;
audio[channel].volume = c->currentVolume;
audio[channel].modulate = true;
if (c->currentFrequency <= 100) {
audio[channel].modulate = false;
audio[channel].adder = SNDGetSampleFrequency() / 440 / 2;
}
audio[channel].samplePos = 0;
} else {
audio[channel].volume = 0;
}
Expand Down

0 comments on commit fd3da18

Please sign in to comment.