Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
fmodaudio [2019/03/08 10:41] adminfmodaudio [2019/08/13 09:16] – [Remarks] admin
Line 33: Line 33:
 </code> </code>
  
-To simplify usage of the massive amount of functions, Gorilla3D provides higher level structure declarations in Gorilla.Audio.FMOD.* units. +To simplify usage of the massive amount of functions, Gorilla3D provides higher level structure declarations in Gorilla.Audio.FMOD.Intf.* and Gorilla.Audio.FMOD.* units.  
 + 
 +<code> 
 +Gorilla.Audio.FMOD.Intf.System 
 +Gorilla.Audio.FMOD.Intf.Channel 
 +Gorilla.Audio.FMOD.Intf.ChannelGroup 
 +Gorilla.Audio.FMOD.Intf.DSP 
 +Gorilla.Audio.FMOD.Intf.Sound 
 +Gorilla.Audio.FMOD.Intf.SoundGroup 
 +Gorilla.Audio.FMOD.Intf.Reverb3D 
 +Gorilla.Audio.FMOD.Intf.Geometry 
 +</code>
  
 <code> <code>
Line 53: Line 64:
 </code> </code>
  
-===== To load an audio file at runtime =====+__**Remarks:**__ The higher level structures are based on a interface-class architecture, so you need to take care of reference counting. In your application you should only use the interfaces! 
 +===== Examples ===== 
 + 
 +==== To load an audio file at runtime ====
  
 <file pascal Form1.pas> <file pascal Form1.pas>
Line 65: Line 79:
 procedure TForm1.FormShow(Sender: TObject); procedure TForm1.FormShow(Sender: TObject);
 var LPath : String; var LPath : String;
-    LSound : PGorillaFMODSound;+    LSound : IGorillaFMODSound;
 begin begin
   FFMOD := TGorillaFMODAudioManager.Create(Self);   FFMOD := TGorillaFMODAudioManager.Create(Self);
Line 82: Line 96:
 </file>  </file>
  
-===== Output playback position =====+==== Output playback position ====
  
  
Line 88: Line 102:
 uses uses
   Gorilla.Audio.FMOD,   Gorilla.Audio.FMOD,
-  Gorilla.Audio.FMOD.Sound, +  Gorilla.Audio.FMOD.Intf.Sound, 
-  Gorilla.Audio.FMOD.Channel;+  Gorilla.Audio.FMOD.Intf.Channel;
  
 procedure TForm1.Timer1Timer(Sender: TObject); procedure TForm1.Timer1Timer(Sender: TObject);
-var LSound : PGorillaFMODSound+var LSound : IGorillaFMODSound
- LMS, LLenMS : UInt32;+    LMS, LLenMS : UInt32;
 begin begin
   {...}   {...}
-  LMS := FChannel^.Position[FMOD_TIMEUNIT_MS]; +  LMS := FChannel.Position[FMOD_TIMEUNIT_MS]; 
-  LSound := PGorillaFMODSound(LChannel^.GetCurrentSound());+  LSound := LChannel.GetCurrentSound() as IGorillaFMODSound;
   if Assigned(LSound) then   if Assigned(LSound) then
   begin   begin
-    LLenMS := LSound^.Length[FMOD_TIMEUNIT_MS];+    LLenMS := LSound.Length[FMOD_TIMEUNIT_MS];
     Self.Caption := Format('sound #%s %d / %d', [IntToHex(NativeInt(LSound), 16), LMS, LLenMS]);     Self.Caption := Format('sound #%s %d / %d', [IntToHex(NativeInt(LSound), 16), LMS, LLenMS]);
   end;    end; 
Line 107: Line 121:
   
  
-===== Add a FadePoint =====+==== Add a FadePoint ====
  
 <file pascal Form1.pas> <file pascal Form1.pas>
Line 116: Line 130:
  
 procedure TForm1.FormShow(Sender: TObject); procedure TForm1.FormShow(Sender: TObject);
-var LSound : PGorillaFMODSound+var LSound : IGorillaFMODSound
-    LChannel : PGorillaFMODChannel+    LChannel : IGorillaFMODChannel
- LClock, LPClock : UInt64;+    LClock, LPClock : UInt64;
 begin begin
   {...}   {...}
Line 124: Line 138:
   if Assigned(LChannel) then   if Assigned(LChannel) then
   begin   begin
-    LChannel^.GetDSPClock(LClock, LPClock); +    LChannel.GetDSPClock(LClock, LPClock); 
-    LChannel^.AddFadePoint(LPClock, 0.0); +    LChannel.AddFadePoint(LPClock, 0.0); 
-    LChannel^.AddFadePoint(LPClock + 48000, 1.0);+    LChannel.AddFadePoint(LPClock + 48000, 1.0);
   end;     end;  
 end; end;
Line 132: Line 146:
   
  
-===== Set 3D Listener Position =====+==== Set 3D Listener Position ====
  
 <file pascal Form1.pas> <file pascal Form1.pas>
Line 166: Line 180:
   
  
-===== Loop sample =====+==== Loop sample ====
  
 <file pascal Form1.pas> <file pascal Form1.pas>
Line 175: Line 189:
  
 procedure TForm1.FormShow(Sender: TObject); procedure TForm1.FormShow(Sender: TObject);
-var LSound : PGorillaFMODSound;+var LSound : IGorillaFMODSound;
 begin begin
   {...}   {...}
   LSound := LFMOD.LoadSoundFromFile('drumloop.wav');   LSound := LFMOD.LoadSoundFromFile('drumloop.wav');
-  LSound^.Mode := FMOD_LOOP_NORMAL; +  LSound.Mode := FMOD_LOOP_NORMAL; 
 end; end;
 </file> </file>
   
-===== Usage =====+===== Android =====
    
 Using FMOD in Android needs some additional configuration. Because on Android the FMOD engine uses a Java library (fmod.jar), we need to attach those to our project.  Using FMOD in Android needs some additional configuration. Because on Android the FMOD engine uses a Java library (fmod.jar), we need to attach those to our project. 
  
 To allow correct loading of this FMOD Java library, we created an extra Java library (Gorilla.jar). This library loads the FMOD library in the right context.  To allow correct loading of this FMOD Java library, we created an extra Java library (Gorilla.jar). This library loads the FMOD library in the right context. 
- 
  
 Go to your project tree and select Android as destination platform. Then enter the library section and add these 2 files: fmod.jar, Gorilla.jar to your project. You can find them in the "lib" folder of your package download.  Go to your project tree and select Android as destination platform. Then enter the library section and add these 2 files: fmod.jar, Gorilla.jar to your project. You can find them in the "lib" folder of your package download. 
 +
 +{{ ::fmod-android-config.jpg?600 |}}
 +
 +Next step: [[assetsmanager|AssetsManager]]
 +
 +===== Remarks =====
 +It is not allowed to release FMOD interfaces when the TGorillaFMODAudioManager component, especially the IGorillaFMODSystem interface inside of it, is already destroyed.
 +In this case you will receive an AccessViolation, because FMOD can not destroy the internal handle anymore.
 +
 +**WRONG:**
 +<file pascal>
 +var LFMOD : TGorillaFMODAudioManager;
 +    LSound : IGorillaFMODSound;
 +    
 +[...]
 +
 +LFMOD := TGorillaFMODAudioManager.Create(nil);
 +try
 +  LSound := LFMOD.LoadSoundFromFile(Common_MediaPathRaw('drumloop.wav'));
 +finally
 +  FreeAndNil(LFMOD);
 +  LSound := nil; // <<< WRONG!
 +end;
 +</file>
 +
 +**CORRECT:**
 +<file pascal>
 +var LFMOD : TGorillaFMODAudioManager;
 +    LSound : IGorillaFMODSound;
 +    
 +[...]
 +
 +LFMOD := TGorillaFMODAudioManager.Create(nil);
 +try
 +  LSound := LFMOD.LoadSoundFromFile(Common_MediaPathRaw('drumloop.wav'));
 +finally
 +  LSound := nil; // !!! CORRECT!
 +  FreeAndNil(LFMOD);
 +end;
 +</file>