From e70407f16bfd11c7e30ca70959e0e9e05ca58785 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Tue, 16 Dec 2014 20:34:32 +0100 Subject: [PATCH 1/4] Added PureBasic --- lib/linguist/languages.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 86105d81..f3222610 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2306,6 +2306,17 @@ Pure Data: tm_scope: none ace_mode: text +PureBasic: + type: programming + color: "#5a6986" + extensions: + - .pb + - .pbi + - .pbf + - .pbp + tm_scope: none + ace_mode: text + PureScript: type: programming color: "#bcdc53" From 39f5d283481498a6d52ee005c592399a295d196a Mon Sep 17 00:00:00 2001 From: David Vogel Date: Tue, 16 Dec 2014 21:12:13 +0100 Subject: [PATCH 2/4] Added PureBasic example --- samples/PureBasic/Memory.pbi | 203 +++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 samples/PureBasic/Memory.pbi diff --git a/samples/PureBasic/Memory.pbi b/samples/PureBasic/Memory.pbi new file mode 100644 index 00000000..75cc95df --- /dev/null +++ b/samples/PureBasic/Memory.pbi @@ -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 From 70eb779ce50b090b8e6a47831a3bd50c2c0e7d71 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Tue, 16 Dec 2014 22:19:56 +0100 Subject: [PATCH 3/4] Reduced PureBasic to .pb and .pbi --- lib/linguist/languages.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index f3222610..a91bcc8e 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -2312,8 +2312,6 @@ PureBasic: extensions: - .pb - .pbi - - .pbf - - .pbp tm_scope: none ace_mode: text From 0a56f5282d1c2cc04c47059f6fd8431892061a74 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Wed, 17 Dec 2014 12:00:16 +0100 Subject: [PATCH 4/4] Create Example_Sine.pb --- samples/PureBasic/Example_Sine.pb | 137 ++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 samples/PureBasic/Example_Sine.pb diff --git a/samples/PureBasic/Example_Sine.pb b/samples/PureBasic/Example_Sine.pb new file mode 100644 index 00000000..4170ff6c --- /dev/null +++ b/samples/PureBasic/Example_Sine.pb @@ -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