Main Menu

"Pythagorean sound device"

Started by stef, November 21, 2005, 03:37:16 PM

Previous topic - Next topic

stef

Hi!

Some "sphere sound"!

I assume you have the file "ding.wav"
If it doesn't work you must change the loading parameters at the begin of the prog.


You can also choose an other soundfile by changing the line

soundfile$= "ding.wav"

some file gives an interesting sound-result.


read text at begin of codetext!


Greetings
stef



; PROJECT : pythagorean sound
; AUTHOR  : stef
; CREATED : 13.11.2005
; EDITED  : 21.11.2005
; ---------------------------------------------------------------------
RemStart


pythagorean sound device generates a playable scale (of tones/sounds) from a loaded
soundfile.


play with mouse or key 1-8

you can change parameters (volume,freq,mode)
by leftclicking into textfield
input new value
push "return"

freq is frequency parameter of "playsound" not acoustical frequency!!!!!

scale (by pythagoras):
1 freq (as shown in textfield) is always the base
2 freq * 9/8
3 freq * 5/4
4 freq * 4/3
5 freq * 3/2
6 freq * 5/3
7 freq * 15/8
8 freq * 2

from 1 (freq) to 8 (freq *2) is a whole octave

mode:
s means singlehit (mouseclick) (with "flushmouse")
r means repeat hits

This prog isn't really optimized!
low freq gives strange result!

RemEnd

soundfile$= "ding.wav"

Path$ = CurrentDir$()

windir$= WindowsDir$ ()

CD windir$+"media"

If FileExist(soundfile$)=True
LoadSound soundfile$,1
Else
CD Path$
If FileExist(soundfile$)=True
   LoadSound soundfile$,1
Else
 Print "Can't load soundfile!"
 Sync
 Repeat
  Wait 5
 Until ScanCode() Or MouseButton()
  End
 EndIf
EndIf

CD Path$


 LoadFont "times new roman",2,36,0
 MakeShadowBitmapFont 2,RGB(180,180,180),1,1,RGB(50,50,50)

 LoadFont "times new roman",3,24,0
 MakeShadowBitmapFont 3,RGB(180,180,180),1,1,RGB(8,8,8)
 
SetFont 3




Global volume$ ="200"

Global freq$ ="7500"
freq# = Val(freq$)

factor2#=9.0/8.0
factor3#=5.0/4.0
factor4#=4.0/3.0
factor5#=3.0/2.0
factor6#=5.0/3.0
factor7#=15.0/8.0
factor8#=2.0

mode$="R"

Gosub frontside

;--------------------------------------loopstart
Do

RenderToScreen
Cls 100
DrawImage front,0,0,1

Text 84,251,volume$
Text 324,251,freq$
Text 564,251,mode$



If MouseInBox(80,250,160,286) And LeftMouseButton()=True
Gosub volumesettings
EndIf
volume=Val(volume$)
SoundMasterVolume volume

If MouseInBox(320,250,400,286) And LeftMouseButton()=True
Gosub freqsettings
EndIf
freq=Val(freq$)

If MouseInBox(560,250,640,286) And LeftMouseButton()=True
Gosub modesettings
EndIf


If ScanCode() > 1
If ScanCode() <10
 keyplace = ScanCode()-1

 Gosub play
EndIf
EndIf

For keyplace = 1 To 8
mousestat =0
If MouseInBox(4+keyplace*80, 404, 82+keyplace*80,478)
  If LeftMouseButton() = True
   Gosub play
  EndIf
EndIf


Next
If mode$= "S" Then FlushMouse


Sync
Loop
;----------------------------------------------loopend
volumesettings:

volume1$=volume$
volume$=""

DrawImage textbox2,80,250,1


Sync
Repeat
  Wait 5
Until ScanCode() Or MouseButton()
Repeat

vol$= Inkey$()
If ScanCode()<2 Or ScanCode()>11
vol$=""

EndIf

volume$=volume$+vol$
volume=Val(volume$)
If Val(volume$)<0 Or Val(volume$) >255
volume$=volume1$
Exit
EndIf
DrawImage textbox2,80,250,1

Text 84,250,volume$
Sync

Until EnterKey()

Return

freqsettings:

freq1$=freq$
freq$=""

DrawImage textbox2,320,250,1

Sync
Repeat
  Wait 5
Until ScanCode() Or MouseButton()
Repeat

fre$= Inkey$()
If ScanCode()<2 Or ScanCode()>11
fre$=""

EndIf

freq$=freq$+fre$
freq#=Val(freq$)

If Val(freq$)<0
freq$ ="0"
Return
EndIf
If Val(freq$)>44000
freq$ ="44000"
Return
endif

DrawImage textbox2,320,250,1

Text 324,250,freq$
Sync

Until EnterKey()

Return
modesettings:
mode1$=mode$

DrawImage textbox2,560,250,1
Sync
Repeat
  Wait 5
Until ScanCode() Or MouseButton()
Select ScanCode()
Case 31
 mode$="S"
 Return
Case 19
 mode$="R"
 Return
Default
 mode$=mode1$
 Return
endselect  
return

play:

Wait 10
fr#=0
Select keyplace
Case 1
 fr# = freq#
Case 2
 fr# = freq# * factor2#
Case 3
 fr# = freq# * factor3#
Case 4
 fr# = freq# * factor4#
Case 5
 fr# = freq# * factor5#
Case 6
 fr# = freq# * factor6#
Case 7
 fr# = freq# * factor7#
Case 8
 fr# = freq# * factor8#
EndSelect


  PlayDynamicSound 1, 0, 255, fr#
 
BoxC 4+keyplace*80, 404, 82+keyplace*80, 478,1, RGB(250,250,150)

Wait 100
 


Return


frontside:

Gosub wood
Gosub soundfile
Gosub info
Gosub keydraw

front = GetFreeImage()
CreateImage front,800,600
RenderToImage front

TileImage books,0,0,1
BoxC 20,20,780,580,0,RGB(180,180,180)

SetFont 2
CenterText 400,60,"PYTHAGOREAN SOUND DEVICE"
DrawImage textbox1,280,170,1
DrawImage textbox2,80,250,1
DrawImage textbox2,320,250,1
DrawImage textbox2,560,250,1
SetFont 3
Text 280, 146,"SOUNDFILE"

Text 80,225,"VOLUME"
Text 80,280,"0-255"

Text 320,225,"FREQ"
Text 320,280,"0-44000"

Text 560,225,"MODE"
Text 560,280,"S or R"

DrawImage key, 80,400,1
For x = 1 To 8
Text 40+ 80*x, 490, x
Next

Return

wood:
books= GetFreeImage()
CreateImage books,100,100
RenderToImage books

BoxC 0,0,100,100,1,RGB(225,110,35)

For maser1 = 1 To 80
xstart= RndRange(-20,100)
ystart= RndRange(0,100)
BoxC xstart,ystart, xstart+RndRange( 2,18),ystart+2,1,RGB(215,100,30)
Next

For maser2 = 1 To 200
xstart= RndRange(-20,100)
ystart= RndRange(0,100)
LineC xstart,ystart, xstart+RndRange( 2,8),ystart,RGB(210,90,20)
Next

BlurImage books, 10
soundfile:
textbox1= GetFreeImage()
CreateImage textbox1,200,28
RenderToImage textbox1

BoxC 0,0,200,28,1,RGB(180,180,180)
BoxC 2,2,198,26,1,RGB(10,10,10)
Text 10,1,soundfile$

info:
textbox2=GetFreeImage()
CreateImage textbox2,80,26
RenderToImage textbox2

BoxC 0,0,80,26,1,RGB(180,180,180)
BoxC 2,2,78,24,1,RGB(10,10,10)


Return

keydraw:
key =GetFreeImage()
CreateImage key, 646,82
RenderToImage key
BoxC 0,0,646,82,1,RGB(180,180,180)
BoxC 2,2,644,80,1,RGB(10,10,10)

For keyplace = 0 To 7

ShadeBox 4+keyplace*80, 4, 82+keyplace*80, 78, RGB(180,180,180),RGB(120,120,120),RGB(60,60,60),RGB(120,120,120)

Next

Return





Mick Berg

That's another excellent demo! As Kevin says, where do you get your ideas?

kevin

Yes indeed, that's another excellent and very creative demo !