mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
@@ -2313,6 +2313,15 @@ Pure Data:
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
PureBasic:
|
||||
type: programming
|
||||
color: "#5a6986"
|
||||
extensions:
|
||||
- .pb
|
||||
- .pbi
|
||||
tm_scope: none
|
||||
ace_mode: text
|
||||
|
||||
PureScript:
|
||||
type: programming
|
||||
color: "#bcdc53"
|
||||
|
||||
137
samples/PureBasic/Example_Sine.pb
Normal file
137
samples/PureBasic/Example_Sine.pb
Normal file
@@ -0,0 +1,137 @@
|
||||
EnableExplicit
|
||||
|
||||
; ##################################################### Includes ####################################################
|
||||
|
||||
XIncludeFile "Includes/AudioOut.pbi"
|
||||
|
||||
; ##################################################### Prototypes ##################################################
|
||||
|
||||
; ##################################################### Structures ##################################################
|
||||
|
||||
; ##################################################### Constants ###################################################
|
||||
|
||||
#Samplerate = 44100
|
||||
|
||||
; ##################################################### Structures ##################################################
|
||||
|
||||
Structure Main
|
||||
*AudioOut
|
||||
|
||||
Quit.i
|
||||
EndStructure
|
||||
Global Main.Main
|
||||
|
||||
Structure Main_Window
|
||||
ID.i
|
||||
|
||||
TrackBar.i [10]
|
||||
EndStructure
|
||||
Global Main_Window.Main_Window
|
||||
|
||||
; ##################################################### Variables ###################################################
|
||||
|
||||
Global Frequency.d = 1000
|
||||
Global Amplitude.d = 0.25
|
||||
|
||||
; ##################################################### Procedures ##################################################
|
||||
|
||||
Procedure Main_Window_Open()
|
||||
Main_Window\ID = OpenWindow(#PB_Any, 0, 0, 800, 100, "AudioOut Example", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
|
||||
|
||||
If Main_Window\ID
|
||||
|
||||
Main_Window\TrackBar[0] = TrackBarGadget(#PB_Any, 10, 10, 780, 30, 0, 20000)
|
||||
SetGadgetState(Main_Window\TrackBar[0], Frequency)
|
||||
|
||||
Main_Window\TrackBar[1] = TrackBarGadget(#PB_Any, 10, 40, 780, 30, 0, 1000)
|
||||
SetGadgetState(Main_Window\TrackBar[1], Amplitude*1000)
|
||||
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure Notifier_CallBack(*AudioOut)
|
||||
Protected *Temp, Temp_Size.i
|
||||
Static Rotation.d
|
||||
|
||||
While AudioOut::GetQueuedBlocks(*AudioOut) <= 3
|
||||
|
||||
Temp_Size = AudioOut::GetBufferBlocksize(*AudioOut)
|
||||
If Temp_Size > 0
|
||||
*Temp = AllocateMemory(Temp_Size)
|
||||
|
||||
Define Left.d, Right.d, i
|
||||
For i = 0 To Temp_Size / 4 - 1
|
||||
Left = Sin(Rotation) * Amplitude
|
||||
Right = Sin(Rotation) * Amplitude
|
||||
|
||||
PokeW(*Temp + i*4 , Left*32767)
|
||||
PokeW(*Temp + i*4 + 2, Right*32767)
|
||||
|
||||
Rotation + 2.0*#PI / #Samplerate * Frequency
|
||||
Next
|
||||
|
||||
AudioOut::Write_Data(Main\AudioOut, *Temp, Temp_Size)
|
||||
|
||||
FreeMemory(*Temp)
|
||||
EndIf
|
||||
|
||||
Wend
|
||||
EndProcedure
|
||||
|
||||
; ##################################################### Initialisation ##############################################
|
||||
|
||||
Main_Window_Open()
|
||||
|
||||
AudioOut::GetDevices()
|
||||
|
||||
ForEach AudioOut::Device()
|
||||
Debug PeekS(AudioOut::@Device()\szPname)
|
||||
Next
|
||||
|
||||
Main\AudioOut = AudioOut::Initialize(#WAVE_MAPPER, #Samplerate, 2, 16, @Notifier_CallBack())
|
||||
|
||||
If Not Main\AudioOut
|
||||
Debug AudioOut::GetError()
|
||||
End
|
||||
EndIf
|
||||
|
||||
Notifier_CallBack(Main\AudioOut)
|
||||
|
||||
; ##################################################### Main ########################################################
|
||||
|
||||
Repeat
|
||||
|
||||
Repeat
|
||||
Select WaitWindowEvent(100)
|
||||
Case #PB_Event_Gadget
|
||||
Select EventGadget()
|
||||
Case Main_Window\TrackBar[0]
|
||||
Frequency = GetGadgetState(Main_Window\TrackBar[0])
|
||||
Debug Frequency
|
||||
|
||||
Case Main_Window\TrackBar[1]
|
||||
Amplitude = GetGadgetState(Main_Window\TrackBar[1]) / 1000
|
||||
|
||||
EndSelect
|
||||
|
||||
Case #PB_Event_CloseWindow
|
||||
Main\Quit = #True
|
||||
|
||||
Case 0
|
||||
Break
|
||||
EndSelect
|
||||
ForEver
|
||||
|
||||
Until Main\Quit
|
||||
|
||||
; ##################################################### End #########################################################
|
||||
|
||||
AudioOut::Deinitialize(Main\AudioOut)
|
||||
|
||||
; IDE Options = PureBasic 5.30 Beta 2 (Windows - x64)
|
||||
; CursorPosition = 109
|
||||
; FirstLine = 79
|
||||
; Folding = -
|
||||
; EnableUnicode
|
||||
; EnableThread
|
||||
; EnableXP
|
||||
203
samples/PureBasic/Memory.pbi
Normal file
203
samples/PureBasic/Memory.pbi
Normal file
@@ -0,0 +1,203 @@
|
||||
|
||||
Structure Memory_Operation
|
||||
Src_Offset.q
|
||||
Src_Size.q
|
||||
|
||||
Dst_Offset.q
|
||||
Dst_Size.q
|
||||
|
||||
Copy_Size.q
|
||||
EndStructure
|
||||
|
||||
; #### Cuts the Offset's / Sizes of the memory operation to prevent memory violations
|
||||
Procedure Memory_Operation_Check(*Memory_Operation.Memory_Operation)
|
||||
Protected Temp.q
|
||||
|
||||
If *Memory_Operation\Src_Offset < 0
|
||||
*Memory_Operation\Copy_Size + *Memory_Operation\Src_Offset
|
||||
*Memory_Operation\Dst_Offset - *Memory_Operation\Src_Offset
|
||||
*Memory_Operation\Src_Offset - *Memory_Operation\Src_Offset
|
||||
EndIf
|
||||
|
||||
If *Memory_Operation\Dst_Offset < 0
|
||||
*Memory_Operation\Copy_Size + *Memory_Operation\Dst_Offset
|
||||
*Memory_Operation\Src_Offset - *Memory_Operation\Dst_Offset
|
||||
*Memory_Operation\Dst_Offset - *Memory_Operation\Dst_Offset
|
||||
EndIf
|
||||
|
||||
Temp = *Memory_Operation\Src_Size - *Memory_Operation\Src_Offset
|
||||
If *Memory_Operation\Copy_Size > Temp
|
||||
*Memory_Operation\Copy_Size = Temp
|
||||
EndIf
|
||||
|
||||
Temp = *Memory_Operation\Dst_Size - *Memory_Operation\Dst_Offset
|
||||
If *Memory_Operation\Copy_Size > Temp
|
||||
*Memory_Operation\Copy_Size = Temp
|
||||
EndIf
|
||||
|
||||
If *Memory_Operation\Copy_Size < 0
|
||||
*Memory_Operation\Copy_Size = 0
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
; #### Fills a *Destination with a specified amount of data.
|
||||
; #### It cuts everything, to prevent memory violations
|
||||
Procedure Memory_Range_Fill(Ascii.a, Fill_Size.q, *Dst, Dst_Offset.q, Dst_Size.q=-1)
|
||||
Protected Temp.q
|
||||
|
||||
If Not *Dst
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Dst_Size = -1
|
||||
Dst_Size.q = MemorySize(*Dst)
|
||||
EndIf
|
||||
|
||||
If Dst_Offset < 0
|
||||
Fill_Size + Dst_Offset
|
||||
Dst_Offset - Dst_Offset
|
||||
EndIf
|
||||
|
||||
Temp = Dst_Size - Dst_Offset
|
||||
If Fill_Size > Temp
|
||||
Fill_Size = Temp
|
||||
EndIf
|
||||
|
||||
If Fill_Size > 0
|
||||
FillMemory(*Dst+Dst_Offset, Fill_Size, Ascii)
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
; #### Copies a specified amount of data (Copy_Size) from the source to the destination.
|
||||
; #### It cuts everything, to prevent memory violations
|
||||
Procedure Memory_Range_Copy(*Src, Src_Offset.q, *Dst, Dst_Offset.q, Copy_Size.q, Src_Size.q=-1, Dst_Size.q=-1)
|
||||
Protected Temp.q
|
||||
If Not *Src
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not *Dst
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Src_Size = -1
|
||||
Src_Size.q = MemorySize(*Src)
|
||||
EndIf
|
||||
If Dst_Size = -1
|
||||
Dst_Size.q = MemorySize(*Dst)
|
||||
EndIf
|
||||
|
||||
If Src_Offset < 0
|
||||
Copy_Size + Src_Offset
|
||||
Dst_Offset - Src_Offset
|
||||
Src_Offset - Src_Offset
|
||||
EndIf
|
||||
|
||||
If Dst_Offset < 0
|
||||
Copy_Size + Dst_Offset
|
||||
Src_Offset - Dst_Offset
|
||||
Dst_Offset - Dst_Offset
|
||||
EndIf
|
||||
|
||||
Temp = Src_Size - Src_Offset
|
||||
If Copy_Size > Temp
|
||||
Copy_Size = Temp
|
||||
EndIf
|
||||
|
||||
Temp = Dst_Size - Dst_Offset
|
||||
If Copy_Size > Temp
|
||||
Copy_Size = Temp
|
||||
EndIf
|
||||
|
||||
If Copy_Size > 0
|
||||
CopyMemory(*Src+Src_Offset, *Dst+Dst_Offset, Copy_Size)
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
; #### Copies (MoveMemory) a specified amount of data (Copy_Size) from the source to the destination.
|
||||
; #### It cuts everything, to prevent memory violations
|
||||
Procedure Memory_Range_Move(*Src, Src_Offset.q, *Dst, Dst_Offset.q, Copy_Size.q, Src_Size.q=-1, Dst_Size.q=-1)
|
||||
Protected Temp.q
|
||||
If Not *Src
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not *Dst
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Src_Size = -1
|
||||
Src_Size.q = MemorySize(*Src)
|
||||
EndIf
|
||||
If Dst_Size = -1
|
||||
Dst_Size.q = MemorySize(*Dst)
|
||||
EndIf
|
||||
|
||||
If Src_Offset < 0
|
||||
Copy_Size + Src_Offset
|
||||
Dst_Offset - Src_Offset
|
||||
Src_Offset - Src_Offset
|
||||
EndIf
|
||||
|
||||
If Dst_Offset < 0
|
||||
Copy_Size + Dst_Offset
|
||||
Src_Offset - Dst_Offset
|
||||
Dst_Offset - Dst_Offset
|
||||
EndIf
|
||||
|
||||
Temp = Src_Size - Src_Offset
|
||||
If Copy_Size > Temp
|
||||
Copy_Size = Temp
|
||||
EndIf
|
||||
|
||||
Temp = Dst_Size - Dst_Offset
|
||||
If Copy_Size > Temp
|
||||
Copy_Size = Temp
|
||||
EndIf
|
||||
|
||||
If Copy_Size > 0
|
||||
MoveMemory(*Src+Src_Offset, *Dst+Dst_Offset, Copy_Size)
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
; #### Mirrors the memory, usable for little/big endian switching
|
||||
Procedure Memory_Mirror(*Memory, Memory_Size)
|
||||
Protected Elements, i
|
||||
Protected Temp.a, *A.Ascii, *B.Ascii
|
||||
|
||||
If Not *Memory
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Memory_Size < 1
|
||||
ProcedureReturn #True
|
||||
EndIf
|
||||
|
||||
Elements = Memory_Size/2
|
||||
*A = *Memory
|
||||
*B = *Memory + Memory_Size - 1
|
||||
|
||||
For i = 0 To Elements - 1
|
||||
Temp = *A\a
|
||||
*A\a = *B\a
|
||||
*B\a = Temp
|
||||
*A + 1
|
||||
*B - 1
|
||||
Next
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
; IDE Options = PureBasic 5.31 (Windows - x64)
|
||||
; CursorPosition = 190
|
||||
; FirstLine = 177
|
||||
; Folding = -
|
||||
; EnableXP
|
||||
; DisableDebugger
|
||||
Reference in New Issue
Block a user