Author Topic: Encoding AAC with ManagedBass  (Read 339 times)

Hanuman

  • Posts: 85
Encoding AAC with ManagedBass
« on: 25 Jul '22 - 23:07 »
Since ManagedBass looks pretty dead lately; I'm looking to add ACC support (and fix a parameter problem) to it.

I could easily copy BassEnc_Opus and edit it for BassEnc_Acc; but for IOS, it needs to use the built-in API.

It comes down to calling BASS_Encode_StartCAFile
https://github.com/ManagedBass/ManagedBass/blob/master/src/AddOns/BassEnc/Shared/PInvoke/Encoding.cs#L334=

Here, ftype and atype are of type int. What do I do with them, and how do I know what are the valid values?

Then for bitrate, I need to parse from the options string of BassEnc_Acc... does IOS support only CBR, or how do I know what value to give it?

Code: [Select]
  --object-type <value> ... "value" can be: 2/5/23/29/39. See here for descriptions: www.wikipedia.org/wiki/MPEG-4_Part_3#MPEG-4_Audio_Object_Types
  --vbr <value> ... "value" can be 0 (CBR) or 1-5 (VBR levels).
  --bitrate <value> ... bitrate (bps) for CBR.

Ian @ un4seen

  • Administrator
  • Posts: 24589
Re: Encoding AAC with ManagedBass
« Reply #1 on: 26 Jul '22 - 17:18 »
The "ftype" paramater should be set to kAudioFileAAC_ADTSType, and "atype" paramater set for the BASSenc_AAC "--object-type" value you want as follows:

   2 = kAudioFormatMPEG4AAC
   5 = kAudioFormatMPEG4AAC_HE
   23 = kAudioFormatMPEG4AAC_LD
   29 = kAudioFormatMPEG4AAC_HE_V2
   39 = kAudioFormatMPEG4AAC_ELD

Those IDs (and others) can be found in Apple's documentation:

   https://developer.apple.com/documentation/audiotoolbox/1576497-audio_file_types
   https://developer.apple.com/documentation/coreaudiotypes/1572096-audio_format_identifiers

The CoreAudio AAC encoder doesn't appear to have any VBR options, so I don't think it'll be possible to support BASSenc_AAC's "--vbr" option.

Hanuman

  • Posts: 85
Re: Encoding AAC with ManagedBass
« Reply #2 on: 26 Jul '22 - 19:47 »
How do I know what int value kAudioFormatMPEG4AAC represents?

and in the doc it's instead passing a string like 'mp4f'; but the API wants an int. It's an int constant, or a pointer to a string?

Ian @ un4seen

  • Administrator
  • Posts: 24589
Re: Encoding AAC with ManagedBass
« Reply #3 on: 27 Jul '22 - 11:04 »
Those 4 character strings are converted to 32-bit integers by the compiler, with each character taking 8 bits. I don't know if .Net supports them. If not, you can do the conversion yourself. For example: 'm' = 0x6d, 'p' = 0x70, '4' = 0x34, 'f' = 0x66, and so 'mp4f' = 0x6d703466