Recent

Author Topic: Core Audio  (Read 6876 times)

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

Guva

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

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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!

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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 :-)

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 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

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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?

AL

  • Sr. Member
  • ****
  • Posts: 256
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 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

 

TinyPortal © 2005-2018