'----------------------------------------
handle = WAVtoRAW("1.wav") ' write sound content as binary data to array OutputSound
AddEcho handle, 0, 1, echo() ' create new sound from old sound using echo in with time .1 seconds and 5 echoes
'REDIM Longer(0) AS Snd
'SNDARRCOPY echo(), 2, Longer() ' copy done sound effect as 2 sounds consecutively
'ERASE echo
sw = 1024
sh = 768
n = 65536
dim leftx
(n
- 1), rightx
(n
- 1) dim leftxx_r
(n
- 1), leftxx_i
(n
- 1) dim rightxx_r
(n
- 1), rightxx_i
(n
- 1)
leftx(i) = echo(i).Left
rightx(i) = echo(i).Right
line -(x
, sh
/6 - 100*leftx
(x
*n
/sw
))
line -(x
, 2*sh
/6 - 100*rightx
(x
*n
/sw
))
rfft leftxx_r(), leftxx_i(), leftx(), n
rfft rightxx_r(), rightxx_i(), rightx(), n
line -(x
, 4*sh
/6 - sqr(leftxx_r
(x
*n
/2/sw
)^2 + leftxx_i
(x
*n
/2/sw
)^2))
line -(x
, 5*sh
/6 - sqr(rightxx_r
(x
*n
/2/sw
)^2 + rightxx_i
(x
*n
/2/sw
)^2))
for i
=1 to 40*n
/sw
'to n/2 - 1 leftxx_r(i) = 0
leftxx_i(i) = 0
leftxx_r(n - i) = 0
leftxx_i(n - i) = 0
rightxx_r(i) = 0
rightxx_i(i) = 0
rightxx_r(n - i) = 0
rightxx_i(n - i) = 0
line -(x
, 4*sh
/6 - sqr(leftxx_r
(x
*n
/2/sw
)^2 + leftxx_i
(x
*n
/2/sw
)^2)),_rgb(0,255,0)
line -(x
, 5*sh
/6 - sqr(rightxx_r
(x
*n
/2/sw
)^2 + rightxx_i
(x
*n
/2/sw
)^2)),_rgb(0,255,0)
'line (100*
'inverse
leftxx_i(i) = -leftxx_i(i)
rightxx_i(i) = -rightxx_i(i)
fft leftx(), temp(), leftxx_r(), leftxx_i(), n
fft rightx(), temp(), rightxx_r(), rightxx_i(), n
leftx(i) = leftx(i)/n
rightx(i) = rightx(i)/n
echo(i).Left = leftx(i)
echo(i).Right = rightx(i)
SAVESOUND16S echo(), "high_freq.wav" ' save new sound as file New_echo.wav
locate 1,1:
? "high pass done" handle = WAVtoRAW("1.wav") ' write sound content as binary data to array OutputSound
AddEcho handle, 0, 1, echo() ' create new sound from old sound using echo in with time .1 seconds and 5 echoes
leftx(i) = echo(i).Left
rightx(i) = echo(i).Right
line -(x
, sh
/6 - 100*leftx
(x
*n
/sw
))
line -(x
, 2*sh
/6 - 100*rightx
(x
*n
/sw
))
rfft leftxx_r(), leftxx_i(), leftx(), n
rfft rightxx_r(), rightxx_i(), rightx(), n
line -(x
, 4*sh
/6 - sqr(leftxx_r
(x
*n
/2/sw
)^2 + leftxx_i
(x
*n
/2/sw
)^2))
line -(x
, 5*sh
/6 - sqr(rightxx_r
(x
*n
/2/sw
)^2 + rightxx_i
(x
*n
/2/sw
)^2))
leftxx_r(i) = 0
leftxx_i(i) = 0
leftxx_r(n - i) = 0
leftxx_i(n - i) = 0
rightxx_r(i) = 0
rightxx_i(i) = 0
rightxx_r(n - i) = 0
rightxx_i(n - i) = 0
line -(x
, 4*sh
/6 - sqr(leftxx_r
(x
*n
/2/sw
)^2 + leftxx_i
(x
*n
/2/sw
)^2)),_rgb(0,255,0)
line -(x
, 5*sh
/6 - sqr(rightxx_r
(x
*n
/2/sw
)^2 + rightxx_i
(x
*n
/2/sw
)^2)),_rgb(0,255,0)
'line (100*
'inverse
leftxx_i(i) = -leftxx_i(i)
rightxx_i(i) = -rightxx_i(i)
fft leftx(), temp(), leftxx_r(), leftxx_i(), n
fft rightx(), temp(), rightxx_r(), rightxx_i(), n
leftx(i) = leftx(i)/n
rightx(i) = rightx(i)/n
echo(i).Left = leftx(i)
echo(i).Right = rightx(i)
SAVESOUND16S echo(), "low_freq.wav" ' save new sound as file New_echo.wav
'_SNDPLAYFILE "new_echo.wav" 'play it
'ERASE longer
sub fft
(xx_r
(), xx_i
(), x_r
(), x_i
(), n
)
'bit rev copy
rev = 0
if i
and (2^j
) then rev
= rev
+ (2^(log2n
- 1 - j
))
xx_r(i) = x_r(rev)
xx_i(i) = x_i(rev)
m = 2^i
w_r = 1
w_i = 0
p = j + k
q = p + (m \ 2)
u_r = w_r*xx_r(q) - w_i*xx_i(q)
u_i = w_r*xx_i(q) + w_i*xx_r(q)
v_r = xx_r(p)
v_i = xx_i(p)
xx_r(p) = v_r + u_r
xx_i(p) = v_i + u_i
xx_r(q) = v_r - u_r
xx_i(q) = v_i - u_i
u_r = w_r
u_i = w_i
w_r = u_r*wm_r - u_i*wm_i
w_i = u_r*wm_i + u_i*wm_r
sub rfft
(xx_r
(), xx_i
(), x_r
(), n
)
rev = 0
if i
and (2^j
) then rev
= rev
+ (2^(log2n
- 1 - j
))
xx_r(i) = x_r(2*rev)
xx_i(i) = x_r(2*rev + 1)
m = 2^i
w_r = 1
w_i = 0
p = j + k
q = p + (m \ 2)
u_r = w_r*xx_r(q) - w_i*xx_i(q)
u_i = w_r*xx_i(q) + w_i*xx_r(q)
v_r = xx_r(p)
v_i = xx_i(p)
xx_r(p) = v_r + u_r
xx_i(p) = v_i + u_i
xx_r(q) = v_r - u_r
xx_i(q) = v_i - u_i
u_r = w_r
u_i = w_i
w_r = u_r*wm_r - u_i*wm_i
w_i = u_r*wm_i + u_i*wm_r
xx_r(n/2) = xx_r(0)
xx_i(n/2) = xx_i(0)
xx_r(n/2 + i) = xx_r(n/2 - i)
xx_i(n/2 + i) = xx_i(n/2 - i)
xpr = (xx_r(i) + xx_r(n/2 + i)) / 2
xpi = (xx_i(i) + xx_i(n/2 + i)) / 2
xmr = (xx_r(i) - xx_r(n/2 + i)) / 2
xmi = (xx_i(i) - xx_i(n/2 + i)) / 2
xx_r
(i
) = xpr
+ xpi
*cos(2*pi
*i
/n
) - xmr
*sin(2*pi
*i
/n
) xx_i
(i
) = xmi
- xpi
*sin(2*pi
*i
/n
) - xmr
*cos(2*pi
*i
/n
)
'symmetry, complex conj
xx_r(n/2 + i) = xx_r(n/2 - 1 - i)
xx_i(n/2 + i) =-xx_i(n/2 - 1 - i)
dest(i&) = source(d&)
i& = i& + 1
'delka echa v sekundach, pocet ozven
Re = RawSize(handle)
BLen& = 44100 * lenght
size = Re + (BLen& * echoes)
devol = 1 / echoes
vol = 1
FOR c
= OTP
(handle
).Offset_Start
TO OTP
(handle
).Offset_End
arr(i& + s).Left = OutputSound(c).Left * vol + arr(i& + s).Left
arr(i& + s).Right = OutputSound(c).Right * vol + arr(i& + s).Right
IF arr
(i&
).Left
> .9 THEN arr
(i&
).Left
= .9 IF arr
(i&
).Left
< -.9 THEN arr
(i&
).Left
= -.9 IF arr
(i&
).Right
> .9 THEN arr
(i&
).Right
= .9 IF arr
(i&
).Right
< -.9 THEN arr
(i&
).Right
= -.9 i& = i& + 1
s& = s& + BLen&
i& = s&
vol = vol - devol
RawSize = OTP(handle).Offset_End - OTP(handle).Offset_Start
FUNCTION WAVtoRAW
(file$
) ' Function load WAV file (this just 16bit, stereo format) and load it to array as RAW. subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS STRING * 2 ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM) channels
AS INTEGER ' 2 bytes (1 = mono, 2 = stereo) rate
AS LONG ' 4 bytes (sample rate, standard is 44100) ByteRate
AS LONG ' 4 bytes (= sample rate * number of channels * (bits per channel /8)) Block
AS INTEGER ' 2 bytes (block align = number of channels * bits per sample /8) Bits
AS INTEGER ' 2 bytes (bits per sample. 8 = 8, 16 = 16) subchunk2
AS STRING * 4 ' 4 bytes ("data") contains begin audio samples
block = H.Block
RATE = H.rate
chan = H.channels
bits = H.Bits
SEEK #ch
, Find_data_area
(file$
)
OTP
(OTP_Size
).Offset_Start
= UBOUND(outputsound
) + 1
lef = lefi / 65535
righ = righi / 65535
IF RATE
> 44100 THEN frekvence
= RATE
ELSE frekvence
= 44100
FOR plll
= 1 TO frekvence
/ RATE
OutputSound(oss + plll).Left = lef
OutputSound(oss + plll).Right = righ
OTP
(OTP_Size
).Offset_End
= UBOUND(outputsound
) WAVtoRAW = OTP_Size
Find_data_area
= INSTR(1, D$
, "data") + 8
size
AS LONG ' 4 bytes (file size) subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS INTEGER ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM) channels
AS INTEGER ' 2 bytes (1 = mono, 2 = stereo) rate
AS LONG ' 4 bytes (sample rate, standard is 44100) ByteRate
AS LONG ' 4 bytes (= sample rate * number of channels * (bits per channel /8)) Block
AS INTEGER ' 2 bytes (block align = number of channels * bits per sample /8) Bits
AS INTEGER ' 2 bytes (bits per sample. 8 = 8, 16 = 16) subchunk2
AS STRING * 4 ' 4 bytes ("data") contains begin audio samples lenght
AS LONG ' 4 bytes Data block size
H16.chunk = "RIFF"
H16.size
= 44 + UBOUND(arr
) * 4 'two channels, it create 16 bit, stereo wav file, one sample use 2 bytes to one channel
H16.fomat = "WAVE"
H16.sub1 = "fmt "
H16.subchunksize = 16
H16.format = 1
H16.channels = 2
H16.rate = 44100
H16.ByteRate = 44100 * 2 * 16 / 8
H16.Block = 4
H16.Bits = 16
H16.subchunk2 = "data"
LeftChannel = arr(audiodata).Left * 32768
RightChannel = arr(audiodata).Right * 32768