Recent

Author Topic: Core Audio  (Read 2781 times)

AL

  • Full Member
  • ***
  • Posts: 181
Core Audio
« on: December 24, 2019, 02:11:56 am »
What Core Audio elements do we have access to in Lazarus?
I have seen several units in MacOSAll.  Is there a list of elements we can access?
I want to record from the microphone to a buffer.
I was thinking of using Audio Queue Services as this seems the easiest.  Is there any facilities in Lazarus/Cocoa?

If that make a difference, I am cross compiling from Windows.

Thanks.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

indigo80

  • New Member
  • *
  • Posts: 31
Re: Core Audio
« Reply #1 on: December 24, 2019, 04:37:44 am »

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #2 on: December 24, 2019, 03:24:22 pm »
Yes thank you for that.
I was hoping to use more native code but may have to resigne to use PortAudio or UOS.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
  • Former Delphi 1-7, 10.2 User
Re: Core Audio
« Reply #3 on: December 25, 2019, 11:14:29 am »
There's a Core Audio source directory: fpc-3.3.1/packages/cocoaint/src/coreaudio.

See: https://developer.apple.com/documentation/avfoundation/avcaptureaudiofileoutput

See also (which looks nicely step-by-step and is largely ANSI-C rather than OBJ-C:  https://developer.apple.com/library/archive/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/AQRecord/RecordingAudio.html#//apple_ref/doc/uid/TP40005343-CH4-SW1

Other than that, I'm not able to help, but good luck!
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #4 on: December 27, 2019, 04:20:21 pm »
Thank you Trev,
unfortunately the audioQueue doesn't seem to be implemented in CocoaAll.
However I was able to translate/compile this one :

 https://developer.apple.com/library/archive/technotes/tn2091/_index.html

I am not sure that my translation will run OK as I have never done this before.
Especially all the * and & .

Is  {$modeswitch objective c1(c2)} would be able to understand the code without translating?
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #5 on: December 28, 2019, 12:03:15 am »
Looking more closely I see that I DO NOT have such directory.
The closest I have is  C:\Lazarus\fpcsrc\packages\cocoaint\src\coredata
IMy fpc is 3.2, I will try to get 3.3.1 as yours.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
  • Former Delphi 1-7, 10.2 User
Re: Core Audio
« Reply #6 on: December 28, 2019, 01:18:33 am »
I don't know whether it will help or not, but yesterday I had some success in implementing the AVAudioPlayer class from the AVFoundation framework. I documented it in the wiki: https://wiki.lazarus.freepascal.org/macOS_Audio_Player

It looks like if you implement the AVAudioRecorder class, you could be home and hosed in time for tea :-)
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #7 on: December 28, 2019, 01:36:28 am »
Will look at that thank you.
I just installed (with difficulty) PFC 3.3.1
For some reason fpcupdeluxe had trouble installing it over my version 3.2
I had to reinstall in a new dir.
See also:https://forum.lazarus.freepascal.org/index.php/topic,47916.msg344280/topicseen.html#new
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #8 on: December 28, 2019, 04:24:35 pm »
Unfortunately AVAudiorecorder wil only save to a file.  I need the sound sample in a buffer.
 :(
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
  • Former Delphi 1-7, 10.2 User
Re: Core Audio
« Reply #9 on: December 29, 2019, 01:08:38 am »
For recording to buffers, there's AVCaptureAudioDataOutput

https://developer.apple.com/documentation/avfoundation/avcaptureaudiodataoutput
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #10 on: December 31, 2019, 08:08:33 pm »
I see that there is AVAudioEngine in fpcsrc/packages/cocoaint/src/AVfoundation

How can I access this?

I have:
interface
{$linkframework AVFoundation}

uses
  Classes, SysUtils, StdCtrls, CocoaALL, MacOSAll ,LCLType ;       

but get unknown identifier when  declaring:

VAR   engine: AVAudioEnginePTR ;
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

syntonica

  • Full Member
  • ***
  • Posts: 120
Re: Core Audio
« Reply #11 on: January 12, 2020, 12:51:29 am »
This is probably a little late in the game, but...

Add AVFoundation to your uses clause and you can probably drop the PTR part. You're dealing with a class and unless you're trapped in somebody else's framework, you shouldn't need to use pointers directly.

Also, if you are using 3.3.1, you'll need to change any Boolean to ObjCBOOL. You can define that type as Boolean if you have to drop back to 3.0.4.

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #12 on: January 26, 2020, 04:16:56 pm »
Syntonica:
Thank you for the hints.
Not being able to resolve the issue, I changed my strategy to use AudioQueue.
So far it compile ( this is cross compile from Win10 to MacOS)  without error, but I could not try it in my virtual Mac as I have other problems.
My TAChart is still showing as mirror image, buttons not showing, etc
see: https://forum.lazarus.freepascal.org/index.php/topic,48043.0.html
It looks like the LCL is not translated properly to Cocoa ??
Could this be coming from the ObjCBol type not changed in TAChart.
Should I change my FPC compiler back to 3.2 ?
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 938
  • Former Delphi 1-7, 10.2 User
Re: Core Audio
« Reply #13 on: January 26, 2020, 11:15:42 pm »
In the meantime I implemented AVAudioRecorder (see Wiki: https://wiki.lazarus.freepascal.org/macOS_Audio_Recorder). I know you wanted the recording in a buffer, but maybe you could save to a file and then read into a buffer?
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

AL

  • Full Member
  • ***
  • Posts: 181
Re: Core Audio
« Reply #14 on: January 26, 2020, 11:58:55 pm »
Thank you, I have seen that today.  Nicely done.

I am still trying to find what is causing my buttons, charts, etc. to not behave correctly in MacOS

I am attaching what I made so far with AudioQueue.  May be you can make a use of it.
It is not tested, It does compile but I have not tested it.
It should capture a buffer of about 2 seconds mono 16 bits.
Laz 2.1.0, fpc 3.3.1, Win10
Laz 2.1.0, fpc 3.3.1, Mac OS Mojave running on VMWare
Laz 2.1.0  fpc 3.3.1 Ubuntu 20.04

 

TinyPortal © 2005-2018