Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 35
» Latest member: coronaman
» Forum threads: 137
» Forum posts: 1,163

Full Statistics

Online Users
There are currently 101 online users.
» 0 Member(s) | 99 Guest(s)
Applebot, Bing

Latest Threads
Manual
Forum: Everything else
Last Post: 1micha.elok
2 hours ago
» Replies: 1
» Views: 25
Xmas New Year
Forum: Suggestions
Last Post: Marcus
11-22-2024, 03:36 PM
» Replies: 17
» Views: 3,041
Santa by Marcus
Forum: NaaLaa 6 Code
Last Post: johnno56
11-18-2024, 05:41 PM
» Replies: 7
» Views: 157
How to code efficiently
Forum: NaaLaa 7 Questions
Last Post: 1micha.elok
11-17-2024, 09:31 AM
» Replies: 4
» Views: 171
How to make a race track ...
Forum: NaaLaa 7 Questions
Last Post: kevin
11-10-2024, 04:02 PM
» Replies: 8
» Views: 431
Start of a silly Galaga s...
Forum: NaaLaa 7 Code
Last Post: johnno56
11-08-2024, 08:22 AM
» Replies: 3
» Views: 201
Theme Editor
Forum: Everything else
Last Post: johnno56
11-05-2024, 06:45 PM
» Replies: 2
» Views: 156
Scrolling Text
Forum: Everything else
Last Post: kevin
11-04-2024, 02:17 PM
» Replies: 10
» Views: 487
Naalaa origins
Forum: Everything else
Last Post: johnno56
10-25-2024, 07:21 AM
» Replies: 2
» Views: 296
Maze generation
Forum: NaaLaa 7 Code
Last Post: johnno56
10-23-2024, 09:05 AM
» Replies: 17
» Views: 1,687

 
  Sleepy tunnel
Posted by: Marcus - 02-29-2024, 03:44 PM - Forum: NaaLaa 7 Code - Replies (8)

A 3d tunnel effect.

Code:
' sleepy_tunnel.n7
' ----------------

#win32
constant WIN_W = 640, WIN_H = 480
set window "Sleepy Tunnel", WIN_W, WIN_H
set redraw off
aa = 0
while not keydown(KEY_ESCAPE, true)
    aa = aa + 0.05
    zoffset = (zoffset + 0.001)%0.01
    set color 0, 0, 0
    cls
    set color 255, 255, 255
    maxz = 0.1 + 150*0.01
    for i = 150 to 0
        z = 0.1 + i*0.01 - zoffset
        s = 50/z
        x = cos(z*5 + aa)*(z - 0.1)*50
        y = sin(z*5 + aa)*(z - 0.1)*25
        intens = 255 - 255*z*1.5/maxz
        set color intens*0.5, intens, intens*0.75
        draw pixel WIN_W/2 + x/z + cos(rad(0))*s, WIN_H/2 + y/z + sin(rad(0))*s
        a = 15
        while a <= 360
            draw line to WIN_W/2 + x/z + cos(rad(a))*s, WIN_H/2 + y/z + sin(rad(a))*s
            a = a + 15
        wend
    next
    redraw
    fwait 60
wend



Attached Files
.n7   sleepy_tunnel.n7 (Size: 868 bytes / Downloads: 3)
Print this item

  Simple Scaling and Rotating
Posted by: 1micha.elok - 02-28-2024, 11:57 AM - Forum: NaaLaa 7 Code - Replies (7)

Just a simple scaling and rotating  Cool

Possible use in games, such as
- Space Invaders, Gargoyle Attack
- Tetris

Code:
'==========================================
'       SIMPLE SCALING AND ROTATING
'
'Possible use in games, such as
'- Space Invaders, Gargoyle Attack
'- Tetris
'
'Limitation
'Rotate : only multiplication of 90 degree
'==========================================


'----------------
' INITIALIZATION
'----------------
set window "Pixel Art", 150, 150, false,4
set redraw off

'Color definition
visible cBlack  = [0,0,0]
visible cGreen  = [0,255,0]

'Sprite class definition
Sprite =
[
    '--- Properties ---
    data: [
    [0,0,0,0,0,0,0,0],
    [0,0,1,0,0,1,0,0],
    [0,1,1,1,1,1,1,0],
    [0,1,1,0,0,1,1,0],
    [0,0,1,1,1,1,0,0],
    [0,1,1,1,1,1,1,0],
    [0,1,0,0,0,0,1,0],
    [0,0,0,0,0,0,0,0]
    ],
   
    img: 0, x:0, y:0,    
   
    '--- Methods ---
    Transform_Scale : function(s)
                        this.img = Scale(this.data,s)
                        this.x   = (width(primary)-8*s)/2
                        this.y   = (height(primary)-8*s)/2
                       endfunc, 
    Transform_Rotate : function(s,r)
                        this.img = Rotate(this.data,s,r)
                        this.x   = (width(primary)-8*s)/2
                        this.y   = (height(primary)-8*s)/2
                       endfunc
]

'--------------
' MAIN PROGRAM
'--------------
TitleScreen()
scale   = 1
rotate  = 0
do
    'Prepare screen
    set color cBlack; cls
    set color cGreen

    'Draw Sprite
    'Sprite.Transform_Scale(scale)
    Sprite.Transform_Rotate(scale,rotate)
    draw image Sprite.img,Sprite.x,Sprite.y

    'Pause and wait until SPACE BAR is pressed, ESCAPE to quit
    set caret width(primary)/2, height(primary)-20
    center "SPACE BAR"; redraw
    do;wait 1;if keydown(KEY_ESCAPE,true) end;until keydown(KEY_SPACE,true)
    if scale < 10 then
        scale = scale + 1
    else
        scale = 1
    endif
    if rotate < 3 then
        rotate = rotate + 1
    else
        rotate = 0
    endif  

    free image Sprite.img 'free image from memory
loop

'-----------
' FUNCTIONS
'-----------
function Scale(data,s)
    img = createimage(8*s,8*s); set image img
    for y = 0 to 7
        for x = 0 to 7
            if data[y][x] then
                set color cGreen
            else 
                set color cBlack
            endif
            draw rect x*s,y*s,s,s,1
        next
    next
    set image primary; return img
endfunc

function Rotate(data,s,r)
    img = createimage(8*s,8*s); set image img
    for y = 0 to 6
        for x = 0 to 6
            if data[y][x] then
                set color cGreen
            else 
                set color cBlack
            endif
                       
            '(a,b)  = center point of rotation
            '(x,y)  is rotated into (m,n)
            'd      = angle of rotation in radian
            'm      = cos(d)*(x-a)-sin(d)*(y-b)+a
            'n      = sin(d)*(x-a)+cos(d)*(y-b)+b
            a = 3
            b = 3
            d = r*90*(22/7)/180
            m = (round((cos(d)*(x-a))-(sin(d)*(y-b))+a))
            n = (round((sin(d)*(x-a))+(cos(d)*(y-b))+b))
                     
            draw rect m*s,n*s,s,s,1
        next
    next
    set image primary; return img
endfunc

function TitleScreen()
    set caret width(primary)/2,5
    center "Scaling and"
    center "Rotating"
    set caret width(primary)/2, height(primary)-20
    center "Press ENTER"
    redraw
    do;wait 1;until keydown(KEY_RETURN,true)
endfunc

Print this item

  A game of pool...
Posted by: kevin - 02-22-2024, 02:16 PM - Forum: NaaLaa 7 Code - Replies (14)

Here's a pool game that I have been working on. You can play against another player, or the computer.

I've tried to include playing hints that show up as you play - there's no time pressure, so you can take the time to read these as they appear in the lower part of the screen.

The main control is the mouse or trackpad. When it is your turn to play, press AND HOLD DOWN the left mouse button to lift the pool cue. You can then position the cue by using the mouse, while keeping the mouse button pressed down. The further away from the white ball the mouse goes, the more powerful the shot will be. When you are happy with the mouse position, release the mouse button to take the shot.

There's no image files needed, so you can just run the n7 file from the zip, or use the executable.

   


.zip   pool.zip (Size: 842.52 KB / Downloads: 12)

Print this item

  Mouse
Posted by: johnno56 - 02-21-2024, 08:34 PM - Forum: NaaLaa 7 Questions - Replies (6)

Quick question...

Are there any commands to 'hide' the mouse and to 'read' the mouse wheel?

Just curious. If not, it might be a good idea to add them... purely selfish reasons... lol

J

Print this item

  SFX
Posted by: johnno56 - 02-19-2024, 07:02 PM - Forum: NaaLaa 7 Questions - Replies (8)

Marcus,

I am curious as to "how" your SFX program actually generates tones. For instance: Most Music Notation software relies on a "soundfont" (database of stored samples) to play various instruments but usually require the use of a midi compatible sound card...  Are you using a 'secret' method (similar to KFC's herbs and spices) to access the midi port?... Perhaps a little magic or 'slight of hand'? Just curious...

J

Print this item

  Space Side Scroller
Posted by: johnno56 - 02-19-2024, 10:50 AM - Forum: NaaLaa 7 Code - Replies (9)

This is a simple side scroller. Collect as many "stars" as you can. It stars off slow, but as your score increases, so does your speed. But, if you miss a star, you will lose a life....

Mouse controlled (vertical only) - Note: The sounds were created by Marcus's SFX library....

For those who are patient enough... post your final scores.... lol


.zip   scroller.zip (Size: 757.53 KB / Downloads: 6)

J

Print this item

  N7 version 24.02.16 released
Posted by: Marcus - 02-17-2024, 06:49 PM - Forum: Announcements - Replies (12)

Here comes a new release with the online high-score library (ohs), updated since I posted it in a thread a while ago, and the sfx library. 

2024-02-16

  • The compiler and the generated programs are from now and on 64 bit. libgcc_s_dw2-1.dll is no longer required for the programs to run. ibwinpthread-1.dll and libportaudio.dll are still required but have been replaced with 64 bit versions
  • Added the sfx library for creating sound effects with two examples in examples/sfx_library
  • Added the ohs library for online high-score lists with two examples in examples/ohs_library
  • Added some programs by members of the naalaa forum to examples/other
  • Fixed an issue with 'draw pixel'

https://naalaa.com/n7/N7_240216.zip

Print this item

  horizontal scroll bar
Posted by: aliensoldier - 02-17-2024, 04:05 PM - Forum: Suggestions - Replies (4)

I think a horizontal bar is necessary so that when the code is very wide it can be moved horizontally comfortably.

I mention this because when creating the scenarios in the platform game that I am making, the scenario is a list and I have not been able to make it very long because I had to move with the keyboard arrows from left to right and when I reached the end I returned to the beginning.

And it was very tiresome to have to move around with the keys again.

Print this item

  SFX library
Posted by: Marcus - 02-16-2024, 04:13 PM - Forum: NaaLaa 7 Code - Replies (3)

Here comes a library for creating sound effects. It's an improvement of the thing I made for that Defender-clone. You now have more advanced control over the frequency and volume of the sounds you create. You can also add echo effects and save your masterpieces as wav files.

sfx_library_example.n7

Code:
' sfx_library_example
' -------------------

#win32

' Include the sfx library.
include "sfx.n7"

' Create a window and print instructions.
set window "SFX", 640, 480
wln "1 - Play a square wave sound effect"
wln "2 - Play a sine wave sound effect"
wln "3 - Play a noise sound effect"
wln
wln "Esc - Quit"

' Create an sfx instance.
sfx = SFX()

' You can use 'SetSampleRate(value)' to change the sample rate that is used when creating sounds.
' It defaults to 16000 (so the call below is just for show). There's no point setting a higher value
' than 22050, since that is the output frequency of all audio in n7.
sfx.SetSampleRate(16000)

' Use 'SetEcho(count, delay, dropOff, panning)' to enable an echo effect for all sound effects
' created. Set the 'count' parameter to 0 to disable echo. Echo is disabled by default. 'count' is
' the number of echos and 'delay' is the delay in seconds between them. 'dropOff' decides how much
' the volume will decrase for each echo. If 'dropOff' is 0.5, the first echo will have that volume,
' the second one 0.5*0.5 = 0.26 and so on. 'panning', [-1..1] can be used to make the echo bounce
' between the left and right speakers. The 'panning' value is inverted after each echo. Set
' 'panning' to 0 to disable panning.
sfx.SetEcho(2, 0.4, 0.1, 0)

' Use 'SquareWave(duration, freq, vol)' to create a square wave sound. 'duration' is the duration in
' seconds (excluding any echo effect). 'freq' is the frequency. It can be either a number or an
' array of numbers. In the case of an array, it is evaluated as a one dimensional bezier curve. It's
' not as complicated as it may sound. To make a sound start with a frequencey of 500 and end with
' 1000, simply set the 'freq' parameter to [500, 1000]. 'vol' is the volume, and just like 'freq' it
' can be a number or an array. The 'vol' value(s) should be in the range [0..1].
crispSound = sfx.SquareWave(0.5, [50, 100, -500, 1000], [0.5, 1, 0])
' You can also use 'SaveSquareWave(filename, duration, freq, vol)' to save a sound to a wav file.
'sfx.SaveSquareWave("crisp_sound.wav", 0.5, [50, 100, -500, 1000], [0.5, 1, 0])

' Change the echo effect and use 'SineWave(duration, freq, vol)' to create a sine wave sound. The
' parameters work just as they do for 'SquareWave'.
sfx.SetEcho(2, 0.15, 0.2, 0)
blubSound = sfx.SineWave(0.2, [0, 500, 25, 500], [0, 1, 0])
' You can also use 'SaveSine'Wave(filename, duration, freq, vol)' to save a sound to a wav file.
'sfx.SaveSineWave("blub_sound.wav", 0.2, [0, 500, 25, 500], [0, 1, 0])

' This time, use panning for the echo effect. 'Noise(duration, freq, vol)' creates a noise sound,
' and the parameters work just the same way as they do for 'SquareWave' and 'SineWave'.
sfx.SetEcho(2, 0.4, 0.2, -0.5)
boomSound = sfx.Noise(0.6, [5000, 100], [1, 0, 1, 0])
' You can also use 'SaveNoise(filename, duration, freq, vol)' to save a sound to a wav file.
'sfx.SaveNoise("boom_sound.wav", 0.6, [5000, 100], [1, 0, 1, 0])

' Let the user play the sound effects.
while not keydown(KEY_ESCAPE)
    if keydown(KEY_1, true)  play sound crispSound
    if keydown(KEY_2, true)  play sound blubSound
    if keydown(KEY_3, true)  play sound boomSound
    fwait 60
wend

sfx.n7
Code:
' SFX
' ---
' A library for creating simple sound effects.
'
' By Marcus.


' SFX
' ---
function SFX()
    sfx = [sr: 16000, ech: 0, echDel: 0, echDO: 0]
   
    ' GetSampleRate
    ' -------------
    ' Return number of samples per second.
    sfx.GetSampleRate = function()
        return this.sr
    endfunc
   
    ' SetSampleRate
    ' -------------
    ' Set number of samples per second.
    sfx.SetSampleRate = function(sampleRate)
        assert sampleRate >= 8000 and sampleRate <= 22050, "SFX.SetSampleRate: Invalid sample rate"
        this.sr = sampleRate
    endfunc
   
    ' SetEcho
    ' -------
    ' Add 'count' number of echos with a delay of 'delay' seconds. Set 'count' to 0 to disable echo.
    ' The volume is multiplied by 'dropOff' for each echo. 'pan', [-1..1], can be used to make the
    ' sound bounce between the left and right speaker. A value of -1 means that the first echo will
    ' be played only on the left side, and 1 means it will be played on the right side. After each
    ' echo the pan value is inverted. Set 'pan' to 0 to disable panning.
    sfx.SetEcho = function(count, delay, dropOff, pan)
        assert count >= 0, "SFX.SetEcho: Invalid count"
        assert delay >= 0, "SFX.SetEcho: Invalid delay"
        this.ech = count
        this.echDel = delay
        this.echDO = dropOff
        this.echPan = pan
    endfunc

    ' SineWaveData
    ' ------------
    ' Return sine wave data lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be in
    ' the range [0..1].
    sfx.SineWaveData = function(duration, freq, vol)
        assert duration > 0, "SFX.SineWaveData: Invalid duration"
        if typeof(freq) <> TYPE_TABLE  freq = [freq]
        if typeof(vol) <> TYPE_TABLE  vol = [vol]
        freqDegree = sizeof(freq) - 1
        freqBc = BinomialCoefficients(freqDegree)
        volDegree = sizeof(vol) - 1
        volBc = BinomialCoefficients(volDegree)
        data = []
        a = 0
        p = 0
        dp = 1/(duration*this.sr)
        for i = 0 to duration*this.sr - 1
            data[i] = sin(a)*EvaluateCurve(vol, volBc, p)
            a = a + 2*PI*EvaluateCurve(freq, freqBc, p)/this.sr
            p = p + dp
        next
        if this.ech
            return ApplyEcho(data, this.ech, int(this.echDel*this.sr), this.echDO, this.echPan)
        else
            return [data, data]
        endif
    endfunc
       
    ' SineWave
    ' --------
    ' Return a sine wave sound lasting for 'duration' seconds. 'freq' is the frequency and can be
    ' a number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be
    ' a number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.SineWave = function(duration, freq, vol)
        data = this.SineWaveData(duration, freq, vol)
        return createsound(data[0], data[1], this.sr)
    endfunc
   
    ' SaveSineWave
    ' ------------
    ' Save sine wave sound lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be in
    ' the range [0..1].
    sfx.SaveSineWave = function(filename, duration, freq, vol)
        data = this.SineWaveData(duration, freq, vol)
        return SaveWav(filename, data[0], data[1], this.sr)
    endfunc

    ' SquareWaveData
    ' --------------
    ' Return square wave data lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.SquareWaveData = function(duration, freq, vol)
        assert duration > 0, "SFX.SquareWave: Invalid duration"   
        if typeof(freq) <> TYPE_TABLE  freq = [freq]
        if typeof(vol) <> TYPE_TABLE  vol = [vol]
        freqDegree = sizeof(freq) - 1
        freqBc = BinomialCoefficients(freqDegree)
        volDegree = sizeof(vol) - 1
        volBc = BinomialCoefficients(volDegree)
        data = []
        a = 0
        p = 0
        dp = 1/(duration*this.sr)
        for i = 0 to duration*this.sr - 1
            sa = sin(a)
            if sa < 0  sa = -1
            elseif sa > 0  sa = 1
            data[i] = sa*EvaluateCurve(vol, volBc, p)
            a = a + 2*PI*EvaluateCurve(freq, freqBc, p)/this.sr
            p = p + dp
        next
        if this.ech
            return ApplyEcho(data, this.ech, int(this.echDel*this.sr), this.echDO, this.echPan)
        else
            return [data, data]
        endif
    endfunc

    ' SquareWave
    ' ----------
    ' Return a square wave sound lasting for 'duration' seconds. 'freq' is the frequency and can be
    ' a number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be
    ' a number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.SquareWave = function(duration, freq, vol)
        data = this.SquareWaveData(duration, freq, vol)
        return createsound(data[0], data[1], this.sr)
    endfunc

    ' SaveSquareWave
    ' --------------
    ' Save a square wave sound lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.SaveSquareWave = function(filename, duration, freq, vol)
        data = this.SquareWaveData(duration, freq, vol)
        return SaveWav(filename, data[0], data[1], this.sr)
    endfunc

    ' NoiseData
    ' ---------
    ' Return noise data lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.NoiseData = function(duration, freq, vol)
        assert duration > 0, "SFX.Noise: Invalid duration"   
        if typeof(freq) <> TYPE_TABLE  freq = [freq]
        if typeof(vol) <> TYPE_TABLE  vol = [vol]
        freqDegree = sizeof(freq) - 1
        freqBc = BinomialCoefficients(freqDegree)
        volDegree = sizeof(vol) - 1
        volBc = BinomialCoefficients(volDegree)
        data = []
        tick = 0
        value = 0
        deta = 0
        p = 0
        dp = 1/(duration*this.sr)
        for i = 0 to duration*this.sr - 1
            tick = tick - 1
            if tick <= 0
                tick = this.sr/EvaluateCurve(freq, freqBc, p)
                delta = ((rnd()*2 - 1) - value)/tick
            endif
            value = value + delta
            data[i] = value*EvaluateCurve(vol, volBc, p)
            p = p + dp
        next
        if this.ech
            return ApplyEcho(data, this.ech, int(this.echDel*this.sr), this.echDO, this.echPan)
        else
            return [data, data]
        endif
    endfunc

    ' Noise
    ' -----
    ' Return a noise sound lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.Noise = function(duration, freq, vol)
        data = this.NoiseData(duration, freq, vol)
        return createsound(data[0], data[1], this.sr)
    endfunc

    ' SaveNoise
    ' ---------
    ' Save a noise sound lasting for 'duration' seconds. 'freq' is the frequency and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. 'vol' is the volume and can be a
    ' number or an array of numbers, treated as a 1D bezier curve. The 'vol' value(s) should be
    ' in the range [0..1].
    sfx.SaveNoise = function(filename, duration, freq, vol)
        data = this.NoiseData(duration, freq, vol)
        return SaveWav(filename, data[0], data[1], this.sr)
    endfunc
           
    return sfx
   
    ' BinomialCoefficients
    ' --------------------
    function BinomialCoefficients(n)
        function bc(n, k)
            if n = k  return 1
            v = 1
            i = 1
            while i <= k
                v = v*int((n + 1 - i)/i)
                i = i + 1
            wend
            return v
        endfunc
        c = []
        for i = 0 to n  c[i] = bc(n, i)
        return c
    endfunc
   
    ' EvaluateCurve
    ' -------------
    function EvaluateCurve(points, bcs, param)
        n = sizeof(points) - 1
        v = 0
        for i = 0 to n  v = v + bcs[i]*(1 - param)^(n - i)*param^i*points[i]
        return v
    endfunc
   
    ' ApplyEcho
    ' ---------
    function ApplyEcho(data, count, offset, dropOff, pan)
        pan = max(min(pan, 1), -1)
        ldata = fill(0, count*offset + sizeof(data))
        rdata = fill(0, count*offset + sizeof(data))
        for i = 0 to sizeof(data) - 1
            ldata[i] = data[i]
            rdata[i] = data[i]
        next
        for i = 1 to count
            offs = i*offset
            vol = dropOff^i
            lvol = vol*cos((pan + 1)*0.5*PI*0.5)
            rvol = vol*sin((pan + 1)*0.5*PI*0.5)
            for j = 0 to sizeof(data) - 1
                ldata[offs + j] = ldata[offs + j] + data[j]*lvol
                rdata[offs + j] = rdata[offs + j] + data[j]*rvol
            next
            pan = -pan
        next
        return [ldata, rdata]
    endfunc

    ' SaveWav
    ' -------   
    function SaveWav(filename, ldata, rdata, sampleRate)
        function WriteBinChars(f, txt)
            for i = 0 to len(txt) - 1  write file f, asc(mid(txt, i)), 8
        endfunc
       
        f = createfile(filename, true)
        if typeof(f)
            if ldata = rdata  channels = 1
            else  channels = 2
            for i = 0 to sizeof(ldata) - 1  ldata[i] = max(min(ldata[i], 1), -1)
            if channels = 2  for i = 0 to sizeof(rdata) - 1  rdata[i] = max(min(rdata[i], 1), -1)
            WriteBinChars(f, "RIFF")
            frameCount = sizeof(ldata)
            bits = 16
            mul = 32767
            length = int(frameCount*channels*bits/8)
            write file f, length + 44 - 8, 32, false
            WriteBinChars(f, "WAVE")
            WriteBinChars(f, "fmt ")
            write file f, 16, 32, false
            write file f, 1, 16, false
            write file f, channels, 16, false
            write file f, sampleRate, 32, false
            write file f, int(sampleRate*bits*channels/8), 32, false
            write file f, int(channels*bits/8), 16, false
            write file f, bits, 16, false
            WriteBinChars(f, "data")
            write file f, length, 32, false
            if channels = 1
                for i = 0 to sizeof(ldata) - 1  write file f, ldata[i]*mul, 16, true
            else
                for i = 0 to sizeof(ldata) - 1
                    write file f, ldata[i]*mul, 16, true
                    write file f, rdata[i]*mul, 16, true
                next
            endif
            free file f
            return true
        else
            return false
        endif
    endfunc
endfunc



Attached Files
.zip   sfx.zip (Size: 3.59 KB / Downloads: 10)
Print this item

  min TEST 1
Posted by: aurel - 02-16-2024, 02:13 PM - Forum: Programming - Replies (8)

min TEST 1 src loaded

be  careful ,this is trick question !

what is this ?

   

Print this item