I wanted to experiment with making noise-static, so I wrote this little thing up in about 30 minutes. Perhaps someone might find a use for it.
Rem
Basic 8-bit mono noise.
-----------------------
Noise is basically a bunch of random values plugged into an audio sample.
The audio sample needs to have a large amount of data samples in order
for this to work.
Created by Makeii - 2/21/2014
EndRem
' Always work in superstrict (or strict) mode. This is good programming practice
' and helps you from slipping up.
SuperStrict
' Get a random seed. Otherwise the static will sound exactly the same
' Each time you run this.
SeedRnd(MilliSecs())
' Create a new audio sample (a sample of data samples). This audio sample
' holds 50,000 data samples and plays at 30,000 Hz (30,000 samples per second).
' The format is 8-bit monosound.
Global _sample :TAudioSample = CreateAudioSample(50000,30000,SF_MONO8)
For Local i:Short=0 To 49999
' random numbers can go to 255, but the differences in the data will generate
' a sound that is too loud. By setting it between 0-127, the static produced
' will be half the volume, making it unnecessary to change the channel volume.
_sample.samples[i] = Rand(0,127)
Next
' Create a new playable sound based on the audio sample created.
' The second parameter is True, which means it will loop when played.
Global _sound :TSound = LoadSound(_sample,True)
' Allocate a new channel for playing the sound and play the sound.
Global _channel :TChannel = PlaySound(_sound)
' Slow the rate of the noise to create a nifty retro explosion.
Global _rate :Float = 1.0
While (_rate > 0.003)
_rate :* 0.90
SetChannelRate(_channel,_rate)
Delay 50
Wend
' Stop the channel and end program.
StopChannel(_channel)
End
|