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
Last revisionBoth sides next revision
fmodaudio [2019/03/08 10:46] – [Android] adminfmodaudio [2020/01/09 14:20] – [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>
  
 +__**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 ===== ===== Examples =====
  
Line 67: 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 90: 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 118: 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 126: 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 177: 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>
Line 194: Line 206:
  
 {{ ::fmod-android-config.jpg?600 |}} {{ ::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>
 +
 +Next step: [[assetsmanager|Assets Manager]]