Forum > Audio and Video
Future Composer Player
Guva:
raylib used only audio
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit raudio; {$mode ObjFPC}{$H+} interface uses DynLibs, SysUtils, CTypes; const{$IFDEF windows} RAUDIO_LIB_NAME = 'raylib.dll';{$ENDIF}{$IFDEF unix} {$IFDEF darwin} RAUDIO_LIB_NAME = 'libraylib.dylib'; {$ELSE} RAUDIO_LIB_NAME = 'libraylib.so'; {$ENDIF}{$ENDIF} type (* Wave, audio wave data *) PWave = ^TWave; TWave = record frameCount : LongWord; // Total number of frames (considering channels) sampleRate : LongWord; // Frequency (samples per second) sampleSize : LongWord; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) channels : LongWord; // Number of channels (1-mono, 2-stereo, ...) data : Pointer; // Buffer data pointer end; PrAudioBuffer = ^TrAudioBuffer; TrAudioBuffer = record end; PrAudioProcessor = ^TrAudioProcessor; TrAudioProcessor = record end; (* AudioStream, custom audio stream *) PAudioStream = ^TAudioStream; TAudioStream = record buffer : PrAudioBuffer; // Pointer to internal data used by the audio system processor : PrAudioProcessor; // Pointer to internal data processor, useful for audio effects sampleRate : LongWord; // Frequency (samples per second) sampleSize : LongWord; // Bit depth (bits per sample): 8, 16, 32 (24 not supported) channels : LongWord; // Number of channels (1-mono, 2-stereo, ...) end; (* Sound *) PSound = ^TSound; TSound = record stream : TAudioStream; // Audio stream frameCount : LongWord; // Total number of frames (considering channels) end; (*Music, audio stream, anything longer than ~10 seconds should be streamed *) PMusic = ^TMusic; TMusic = record stream : TAudioStream; // Audio stream frameCount : LongWord; // Total number of frames (considering channels) looping : Boolean; // Music looping enable ctxType : Integer; // Type of music context (audio filetype) ctxData : Pointer; // Audio context data, depends on type end; type PAudioCallback = ^TAudioCallback; TAudioCallback = procedure (bufferData: Pointer; frames: LongWord); cdecl; var (* Audio device management functions *) InitAudioDevice: procedure(); cdecl; // Initialize audio device and context CloseAudioDevice: procedure(); cdecl; // Close the audio device and context IsAudioDeviceReady: function(): boolean; cdecl; // Check if audio device has been initialized successfully SetMasterVolume: procedure(volume: single); cdecl; // Set master volume (listener) GetMasterVolume: function(): single; cdecl; // Get master volume (listener) (* Wave/Sound loading/unloading functions *) LoadWave: function(const fileName: PChar): TWave; cdecl; LoadWaveFromMemory: function (const fileType: PChar; const fileData: PByte; dataSize: Integer): TWave; cdecl; IsWaveValid: function(wave: TWave): Boolean; cdecl; LoadSound: function(const fileName: PChar): TSound; cdecl; LoadSoundFromWave: function(wave: TWave): TSound; cdecl; LoadSoundAlias: function(source: TSound): TSound; cdecl; IsSoundValid: function(sound: TSound): Boolean; cdecl; UpdateSound: procedure(sound: TSound; const data: Pointer; sampleCount: Integer); cdecl; UnloadWave: procedure(wave: TWave); cdecl; UnloadSound: procedure(sound: TSound); cdecl; UnloadSoundAlias: procedure(alias: TSound); cdecl; ExportWave: function(wave: TWave; const fileName: PChar): Boolean; cdecl; ExportWaveAsCode: function(wave: TWave; const fileName: PChar): Boolean; cdecl; (* Wave/Sound management functions *) PlaySound: procedure(sound: TSound); cdecl; StopSound: procedure(sound: TSound); cdecl; PauseSound: procedure(sound: TSound); cdecl; ResumeSound: procedure(sound: TSound); cdecl; IsSoundPlaying: function(sound: TSound): Boolean; cdecl; SetSoundVolume: procedure(sound: TSound; volume: Single); cdecl; SetSoundPitch: procedure(sound: TSound; pitch: Single); cdecl; SetSoundPan: procedure(sound: TSound; pan: Single); cdecl; WaveCopy: function(wave: TWave): TWave; cdecl; WaveCrop: procedure(wave: PWave; initFrame, finalFrame: Integer); cdecl; WaveFormat: procedure(wave: PWave; sampleRate, sampleSize, channels: Integer); cdecl; LoadWaveSamples: function(wave: TWave): PSingle; cdecl; UnloadWaveSamples: procedure(samples: PSingle); cdecl; (* Music management functions *) LoadMusicStream: function(const fileName: PChar): TMusic; cdecl; LoadMusicStreamFromMemory: function(const fileType: PChar; const data: PByte; dataSize: Integer): TMusic; cdecl; IsMusicValid: function(music: TMusic): Boolean; cdecl; UnloadMusicStream: procedure(music: TMusic); cdecl; PlayMusicStream: procedure(music: TMusic); cdecl; IsMusicStreamPlaying: function(music: TMusic): Boolean; cdecl; Upda]"]>BlockedsicStream: procedure(music: TMusic); cdecl; StopMusicStream: procedure(music: TMusic); cdecl; PauseMusicStream: procedure(music: TMusic); cdecl; ResumeMusicStream: procedure(music: TMusic); cdecl; SeekMusicStream: procedure(music: TMusic; position: Single); cdecl; SetMusicVolume: procedure(music: TMusic; volume: Single); cdecl; SetMusicPitch: procedure(music: TMusic; pitch: Single); cdecl; SetMusicPan: procedure(music: TMusic; pan: Single); cdecl; GetMusicTimeLength: function(music: TMusic): Single; cdecl; GetMusicTimePlayed: function(music: TMusic): Single; cdecl; (* AudioStream management functions *) LoadAudioStream: function(sampleRate, sampleSize, channels: LongWord): TAudioStream; cdecl; IsAudioStreamValid: function(stream: TAudioStream): boolean; cdecl; UnloadAudioStream: procedure(stream: TAudioStream); cdecl; UpdateAudioStream: procedure(stream: TAudioStream; const data: Pointer; frameCount: Integer); cdecl; IsAudioStreamProcessed: function(stream: TAudioStream): Boolean; cdecl; PlayAudioStream: procedure(stream: TAudioStream); cdecl; PauseAudioStream: procedure(stream: TAudioStream); cdecl; ResumeAudioStream: procedure(stream: TAudioStream); cdecl; IsAudioStreamPlaying: function(stream: TAudioStream): Boolean; cdecl; StopAudioStream: procedure(stream: TAudioStream); cdecl; SetAudioStreamVolume: procedure(stream: TAudioStream; volume: Single); cdecl; SetAudioStreamPitch: procedure(stream: TAudioStream; pitch: Single); cdecl; SetAudioStreamPan: procedure(stream: TAudioStream; pan: Single); cdecl; SetAudioStreamBufferSizeDefault: procedure(size: Integer); cdecl; SetAudioStreamCallback: procedure(stream: TAudioStream; callback: TAudioCallback); cdecl; AttachAudioStreamProcessor: procedure(stream: TAudioStream; processor: TAudioCallback); cdecl; DetachAudioStreamProcessor: procedure(stream: TAudioStream; processor: TAudioCallback); cdecl; AttachAudioMixedProcessor: procedure(processor: TAudioCallback); cdecl; DetachAudioMixedProcessor: procedure(processor: TAudioCallback); cdecl; {Special function for dynamic loading of lib ...}var rAudio_Handle: TLibHandle = dynlibs.NilHandle; ReferenceCounter: cardinal = 0; // Reference counter function rAudio_IsLoaded: Boolean; inline;function rAudio_Load(const libfilename: string): Boolean; // load the libprocedure rAudio_Unload(); // unload and frees the lib from memory : do not forget to call it before close application. implementation function rAudio_IsLoaded: Boolean;begin Result := (rAudio_Handle <> dynlibs.NilHandle);end; function rAudio_Load(const libfilename: string): Boolean;varthelib: string;begin Result := False; if rAudio_Handle<>0 then begin Inc(ReferenceCounter); result:=true {is it already there ?} end else begin {go & load the library} if Length(libfilename) = 0 then thelib := RAUDIO_LIB_NAME else thelib := libfilename; rAudio_Handle:=DynLibs.LoadLibrary(thelib); // obtain the handle we want if rAudio_Handle <> DynLibs.NilHandle then begin {now we tie the functions to the VARs from above} (* Audio device management functions *) Pointer(InitAudioDevice):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('InitAudioDevice')); Pointer(CloseAudioDevice):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('CloseAudioDevice')); Pointer(IsAudioDeviceReady):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsAudioDeviceReady')); Pointer(SetMasterVolume):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetMasterVolume')); Pointer(GetMasterVolume):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('GetMasterVolume')); (* Wave/Sound loading/unloading functions *) Pointer(LoadWave):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadWave')); Pointer(LoadWaveFromMemory):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadWaveFromMemory')); Pointer(IsWaveValid):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsWaveValid')); Pointer(LoadSound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadSound')); Pointer(LoadSoundFromWave):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadSoundFromWave')); Pointer(LoadSoundAlias):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadSoundAlias')); Pointer(IsSoundValid):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsSoundValid')); Pointer(UpdateSound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UpdateSound')); Pointer(UnloadWave):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadWave')); Pointer(UnloadSound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadSound')); Pointer(UnloadSoundAlias):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadSoundAlias')); Pointer(ExportWave):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadSoundAlias')); Pointer(ExportWaveAsCode):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadSoundAlias')); (* Wave/Sound management functions *) Pointer(PlaySound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('PlaySound')); Pointer(StopSound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('StopSound')); Pointer(PauseSound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('PauseSound')); Pointer(ResumeSound):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('ResumeSound')); Pointer(IsSoundPlaying):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsSoundPlaying')); Pointer(SetSoundVolume):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetSoundVolume')); Pointer(SetSoundPitch):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetSoundPitch')); Pointer(SetSoundPan):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetSoundPan')); Pointer(WaveCopy):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('WaveCopy')); Pointer(WaveCrop):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('WaveCrop')); Pointer(WaveFormat):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('WaveFormat')); Pointer(LoadWaveSamples):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadWaveSamples')); Pointer(UnloadWaveSamples):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadWaveSamples')); (* Music management functions *) Pointer(LoadMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadMusicStream')); Pointer(LoadMusicStreamFromMemory):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadMusicStreamFromMemory')); Pointer(IsMusicValid):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsMusicValid')); Pointer(UnloadMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadMusicStream')); Pointer(PlayMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('PlayMusicStream')); Pointer(IsMusicStreamPlaying):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsMusicStreamPlaying')); Pointer(Upda]"]>BlockedsicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('Upda]"]>BlockedsicStream')); Pointer(StopMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('StopMusicStream')); Pointer(PauseMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('PauseMusicStream')); Pointer(ResumeMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('ResumeMusicStream')); Pointer(SeekMusicStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SeekMusicStream')); Pointer(SetMusicVolume):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetMusicVolume')); Pointer(SetMusicPitch):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetMusicPitch')); Pointer(SetMusicPan):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetMusicPan')); Pointer(GetMusicTimeLength):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('GetMusicTimeLength')); Pointer(GetMusicTimePlayed):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('GetMusicTimePlayed')); (* AudioStream management functions *) Pointer(LoadAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('LoadAudioStream')); Pointer(IsAudioStreamValid):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsAudioStreamValid')); Pointer(UnloadAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UnloadAudioStream')); Pointer(UpdateAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('UpdateAudioStream')); Pointer(IsAudioStreamProcessed):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsAudioStreamProcessed')); Pointer(PlayAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('PlayAudioStream')); Pointer(PauseAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('PauseAudioStream')); Pointer(ResumeAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('ResumeAudioStream')); Pointer(IsAudioStreamPlaying):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('IsAudioStreamPlaying')); Pointer(StopAudioStream):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('StopAudioStream')); Pointer(SetAudioStreamVolume):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetAudioStreamVolume')); Pointer(SetAudioStreamPitch):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetAudioStreamPitch')); Pointer(SetAudioStreamPan):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetAudioStreamPan')); Pointer(SetAudioStreamBufferSizeDefault):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetAudioStreamBufferSizeDefault')); Pointer(SetAudioStreamCallback):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('SetAudioStreamCallback')); Pointer(AttachAudioStreamProcessor):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('AttachAudioStreamProcessor')); Pointer(DetachAudioStreamProcessor):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('DetachAudioStreamProcessor')); Pointer(AttachAudioMixedProcessor):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('AttachAudioMixedProcessor')); Pointer(DetachAudioMixedProcessor):=DynLibs.GetProcedureAddress(rAudio_Handle,PChar('DetachAudioMixedProcessor')); end; Result := rAudio_IsLoaded; ReferenceCounter:=1;end; end; procedure rAudio_Unload();begin if ReferenceCounter > 0 then dec(ReferenceCounter); if ReferenceCounter > 0 then exit; if rAudio_IsLoaded then begin DynLibs.UnloadLibrary(rAudio_Handle); rAudio_Handle:=DynLibs.NilHandle; end;end; end.
Guva:
C language wrapper library for Future Composer audio decoding
https://github.com/mschwendt/libfc14audiodecoder
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit fc_lib; {$mode delphi}{$H+}{$PACKRECORDS C} interface uses DynLibs, SysUtils, CTypes; const {$IFDEF windows} FCLIB = 'fc14audiodecoder.dll'; {$ENDIF} {$IFDEF linux} FCLIB = 'libfc14audiodecoder.so.1.0.0'; {$ENDIF} type pfc14 = Pointer; var fc14dec_new: function: pfc14; cdecl; fc14dec_delete: procedure(decoder: pfc14); cdecl; fc14dec_detect: function(decoder: pfc14; buffer: Pointer; length: LongInt): Integer; cdecl; fc14dec_init: function(decoder: pfc14; buffer: Pointer; length: LongInt): Integer; cdecl; fc14dec_restart: procedure(decoder: pfc14); cdecl; fc14dec_mixer_init: procedure(decoder: pfc14; frequency: Integer; precision: Integer; channels: Integer; zero: Integer); cdecl; fc14dec_song_end: function(decoder: pfc14): Integer; cdecl; fc14dec_duration: function(decoder: pfc14): Cardinal; cdecl; fc14dec_seek: procedure(decoder: pfc14; ms: LongInt); cdecl; fc14dec_format_name: function(decoder: pfc14): PChar; cdecl; fc14dec_buffer_fill: function(decoder: pfc14; buffer: Pointer; length: LongInt): LongInt; cdecl; fc14_Handle: TLibHandle = dynlibs.NilHandle; ReferenceCounter: cardinal = 0; function fc14_IsLoaded: Boolean; inline; function fc14_Load(const libfilename: string): Boolean; procedure fc14_Unload(); implementation function fc14_IsLoaded: Boolean;begin Result := (fc14_Handle <> dynlibs.NilHandle);end; function fc14_Load(const libfilename: string): Boolean;varthelib: string;begin Result := False; if fc14_Handle<>0 then begin Inc(ReferenceCounter); result:=true {is it already there ?} end else begin {go & load the library} if Length(libfilename) = 0 then thelib := FCLIB else thelib := libfilename; fc14_Handle:=DynLibs.LoadLibrary(thelib); // obtain the handle we want if fc14_Handle <> DynLibs.NilHandle then begin {now we tie the functions to the VARs from above} (fc14dec_new):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_new')); (fc14dec_delete):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_delete')); (fc14dec_detect):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_detect')); (fc14dec_init):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_init')); (fc14dec_restart):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_restart')); (fc14dec_mixer_init):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_mixer_init')); (fc14dec_song_end):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_song_end')); (fc14dec_duration):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_duration')); (fc14dec_seek):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_seek')); (fc14dec_format_name):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_format_name')); (fc14dec_buffer_fill):=DynLibs.GetProcedureAddress(fc14_Handle,PChar('fc14dec_buffer_fill')); end; Result := fc14_IsLoaded; ReferenceCounter:=1;end; end; procedure fc14_Unload();begin if ReferenceCounter > 0 then dec(ReferenceCounter); if ReferenceCounter > 0 then exit; if fc14_IsLoaded then begin DynLibs.UnloadLibrary(fc14_Handle); fc14_Handle:=DynLibs.NilHandle; end;end; end.
TRon:
--- Quote from: Guva on November 25, 2024, 07:39:55 am ---I will make my contribution
--- End quote ---
Thank you very much for the raudio example Guva !
--- Quote ---However, there is a problem . For some reason it only works in {$mode delphi}
--- End quote ---
Tested with your fc library I did not had a problem (but I did not test your raudio headers).
I took a stab at it based on your example, perhaps that works for you in Delphi mode as well.
Linux/Bash required.
Guva:
--- Quote from: TRon on November 26, 2024, 03:28:09 am ---
--- Quote from: Guva on November 25, 2024, 07:39:55 am ---I will make my contribution
--- End quote ---
Thank you very much for the raudio example Guva !
--- Quote ---However, there is a problem . For some reason it only works in {$mode delphi}
--- End quote ---
Tested with your fc library I did not had a problem (but I did not test your raudio headers).
I took a stab at it based on your example, perhaps that works for you in Delphi mode as well.
Linux/Bash required.
--- End quote ---
Oh yes thank you!
the problem was with my binding for Future Composer
Roland57:
--- Quote from: TRon on November 26, 2024, 03:28:09 am ---I took a stab at it based on your example, perhaps that works for you in Delphi mode as well.
Linux/Bash required.
--- End quote ---
Very nice bash scripts! This one works perfectly here (Linux Mageia). The one that you posted before works also, excepted that I don't have libao installed, and my package manager offers only the 32-bit version.
Navigation
[0] Message Index
[#] Next page
[*] Previous page