Skip to content

Commit

Permalink
add: audio/samples for lazarus
Browse files Browse the repository at this point in the history
  • Loading branch information
turborium committed Dec 23, 2022
1 parent 7dae9f3 commit be6b68b
Show file tree
Hide file tree
Showing 26 changed files with 1,243 additions and 607 deletions.
166 changes: 4 additions & 162 deletions examples/audio/audio_module_playing/audio_module_playing.dpr
Original file line number Diff line number Diff line change
@@ -1,172 +1,15 @@
(*******************************************************************************************
*
* raylib [audio] example - Module playing (streaming)
*
* Example originally created with raylib 1.5, last time updated with raylib 3.5
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2022 Ramon Santamaria (@raysan5)
*
********************************************************************************************)
program audio_module_playing;

{$IFDEF FPC}{$MODE DELPHIUNICODE}{$ENDIF}
{$APPTYPE CONSOLE}

{$R *.res}

uses
SysUtils,
raylib in '..\..\..\raylib\raylib.pas';

const
MAX_CIRCLES = 64;

type TCircleWave = record
Position: TVector2;
Radius: Single;
Alpha: Single;
Speed: Single;
Color: TColor;
end;


//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
procedure Main();
const
ScreenWidth = 800;
ScreenHeight = 450;
var
Colors: array of TColor;
Circles: array [0..MAX_CIRCLES-1] of TCircleWave;
I: Integer;

Music: TMusic;
Pitch, TimePlayed: Single;
Pause: Boolean;
begin
// Initialization
//---------------------------------------------------------------------------------------------
SetConfigFlags(FLAG_MSAA_4X_HINT or FLAG_WINDOW_HIGHDPI);
InitWindow(ScreenWidth, ScreenHeight, UTF8String('raylib [audio] example - module playing (streaming)'));

InitAudioDevice(); // Initialize audio device

Colors := [ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE];

// Creates some circles for visual effect
for I := High(Circles) downto 0 do
begin
Circles[I].Alpha := 0.0;
Circles[I].Radius := GetRandomValue(10, 40);
Circles[I].Position.X := GetRandomValue(Trunc(Circles[I].Radius), Trunc(ScreenWidth - Circles[I].Radius));
Circles[I].Position.Y := GetRandomValue(Trunc(Circles[I].Radius), Trunc(ScreenHeight - Circles[I].Radius));
Circles[I].Speed := GetRandomValue(1, 100) / 2000.0;
Circles[I].Color := colors[GetRandomValue(0, 13)];
end;

Music := LoadMusicStream(UTF8String('resources/audio/mini1111.xm'));
Music.Looping := False;
Pitch := 1.0;

PlayMusicStream(Music);

Pause := False;

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//---------------------------------------------------------------------------------------------

// Main game loop
while not WindowShouldClose() do // Detect window close button or ESC key
begin
// Update
//-------------------------------------------------------------------------------------------
UpdateMusicStream(Music); // Update music buffer with new stream data

// Restart music playing (stop and play)
if IsKeyPressed(KEY_SPACE) then
begin
StopMusicStream(Music);
PlayMusicStream(Music);
end;

// Pause/Resume music playing
if IsKeyPressed(KEY_P) then
begin
Pause := not Pause;

if Pause then
PauseMusicStream(Music)
else
ResumeMusicStream(Music);
end;

if IsKeyDown(KEY_DOWN) then
Pitch := Pitch - 0.01
else if IsKeyDown(KEY_UP) then
Pitch := Pitch + 0.01;

SetMusicPitch(Music, Pitch);

// Get timePlayed scaled to bar dimensions
TimePlayed := GetMusicTimePlayed(Music) / GetMusicTimeLength(Music) * (ScreenWidth - 40);

// Color circles animation
if not Pause then
begin
for I := High(Circles) downto 0 do
begin
Circles[I].Alpha := Circles[I].Alpha + Circles[I].Speed * Pitch;
Circles[I].Radius := Circles[I].Radius + Circles[I].Speed * 10.0;

if Circles[I].Alpha > 1.0 then
Circles[I].Speed := -Circles[I].Speed;

if Circles[I].Alpha <= 0.0 then
begin
Circles[I].Alpha := 0.0;
Circles[I].Radius := GetRandomValue(10, 40);
Circles[I].Position.X := GetRandomValue(Trunc(Circles[I].Radius), Trunc(ScreenWidth - Circles[I].Radius));
Circles[I].Position.Y := GetRandomValue(Trunc(Circles[I].Radius), Trunc(ScreenHeight - Circles[I].Radius));
Circles[I].Color := Colors[GetRandomValue(0, 13)];
Circles[I].Speed := GetRandomValue(1, 100) / 2000.0;
end;
end;
end;
//-------------------------------------------------------------------------------------------

// Draw
//-------------------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

for I := High(Circles) downto 0 do
DrawCircleV(Circles[I].Position, Circles[I].Radius, Fade(Circles[I].Color, Circles[I].Alpha));

// Draw time bar
DrawRectangle(20, ScreenHeight - 20 - 12, ScreenWidth - 40, 12, LIGHTGRAY);
DrawRectangle(20, ScreenHeight - 20 - 12, Trunc(TimePlayed), 12, MAROON);
DrawRectangleLines(20, ScreenHeight - 20 - 12, ScreenWidth - 40, 12, GRAY);

EndDrawing();
//-------------------------------------------------------------------------------------------
end;

// De-Initialization
//---------------------------------------------------------------------------------------------
UnloadMusicStream(Music); // Unload music stream buffers from RAM

CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)

CloseWindow(); // Close window and OpenGL context
//---------------------------------------------------------------------------------------------
end;
raylib in '..\..\..\raylib\raylib.pas',
raymath in '..\..\..\raylib\raymath.pas',
rlgl in '..\..\..\raylib\rlgl.pas',
audio_module_playing_src in 'audio_module_playing_src.pas';

begin
try
Expand All @@ -176,4 +19,3 @@ begin
Writeln(E.ClassName, ': ', E.Message);
end;
end.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Base>True</Base>
<AppType>Console</AppType>
<Config Condition="'$(Config)'==''">Debug</Config>
<FrameworkType>None</FrameworkType>
<MainSource>audio_module_playing.dpr</MainSource>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<ProjectGuid>{704D3EE7-E14F-48F5-9EFC-6B2DAC2B9129}</ProjectGuid>
<ProjectGuid>{F3AF60F8-DA40-4963-B747-000000000026}</ProjectGuid>
<ProjectVersion>19.4</ProjectVersion>
<TargetedPlatforms>3</TargetedPlatforms>
</PropertyGroup>
Expand Down Expand Up @@ -92,6 +92,9 @@
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="..\..\..\raylib\raylib.pas"/>
<DCCReference Include="..\..\..\raylib\raymath.pas"/>
<DCCReference Include="..\..\..\raylib\rlgl.pas"/>
<DCCReference Include="audio_module_playing_src.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down
92 changes: 92 additions & 0 deletions examples/audio/audio_module_playing/audio_module_playing.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="audio_module_playing"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="audio_module_playing.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="audio_module_playing_src.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="../../../raylib/raylib.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="../../../raylib/raymath.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="../../../raylib/rlgl.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../../raylib"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Conditionals Value="// libs
if TargetOS = &apos;darwin&apos; then
begin
LinkerOptions += &apos; ../../output/osx/libraylib.420.dylib -rpath @executable_path/&apos;;
OutputDir := &apos;../../output/osx/&apos;;
end;
if TargetOS = &apos;win64&apos; then
begin
OutputDir := &apos;../../output/win64/&apos;;
end;
if TargetOS = &apos;win32&apos; then
begin
OutputDir := &apos;../../output/win32/&apos;;
end;"/>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
</Debugging>
<Options>
<PassLinkerOptions Value="True"/>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>
14 changes: 14 additions & 0 deletions examples/audio/audio_module_playing/audio_module_playing.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
program audio_module_playing;

uses
SysUtils,
audio_module_playing_src;

begin
try
Main();
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Loading

0 comments on commit be6b68b

Please sign in to comment.