BASSenc_AAC (AAC encoding)

Started by Ian @ un4seen,

orange

#40
I seem to have overlooked this   FileProcs.READ := nil;
Thank you very much for the answers to my questions. I will fix the problem based on your answer

orange

  if (StreamHandle = 0) and (AudioData <> nil) then
  begin
    StreamHandle := BASS_AAC_StreamCreateFileUser(STREAMFILE_BUFFER OR STREAMFILE_BUFFERPUSH, BASS_STREAM_DECODE,  FileProcs, AudioData);
    if StreamHandle = 0 then
    begin
 Memo1.Lines.Add('Error creating BASS stream: ' + IntToStr(BASS_ErrorGetCode));
    end;
  end;

Error creating BASS stream: 20

Chris

QuoteSTREAMFILE_BUFFER OR STREAMFILE_BUFFERPUSH

why are you placing both in the first Parameter ?
STREAMFILE_BUFFER  = buffered stream
STREAMFILE_BUFFERPUSH = Buffered, with the data pushed to BASS via BASS_StreamPutFileData

So only one of the both.

orange

Thank you very much, but nothing worked for me
I don't know where the problem is when there is an example of everything in Lib. I searched a lot in the forum and did not find  ??? ??? ???

Ian @ un4seen

What is it that you ultimately want to achieve? If it's low latency between recording and playing then you would probably be better off using Opus (instead of AAC) with the recent BASSenc_OPUS and BASSOPUS updates, which should also be simpler for you because you don't need any BASS_FILEPROCS callbacks. The updates are in this thread:

   www.un4seen.com/forum/?topic=20236.msg141570#msg141570

alicom

#45
I am trying to record audio to AAC using the ManagedBass.Enc wrapper:

    Sub RecTTS()

        If Bass.Init(-1, 44100, DeviceInitFlags.Default, IntPtr.Zero) AndAlso Bass.RecordInit(-1) Then

            Dim recordProc As RecordProcedure = AddressOf RecordCallback
            Dim recordingStream As Integer = Bass.RecordStart(44100, 2, BassFlags.RecordPause, recordProc, IntPtr.Zero)

            If recordingStream <> 0 Then

                BassEnc.EncodeStart(Handle:=recordingStream, CommandLine:="true_recorded_audio.aac", Flags:=BassFlags.AacStereo Or BassFlags.AutoFree, Nothing, IntPtr.Zero)
                Bass.ChannelPlay(recordingStream)

                Console.WriteLine("Recording started. Press any key to stop.")
                Console.ReadKey()

                Bass.ChannelStop(recordingStream)
                BassEnc.EncodeStop(recordingStream)
                Bass.RecordFree() ' Free recording resources

                Console.WriteLine("Recording saved to file")

            Else

                Console.WriteLine("Failed to start recording.")

            End If

            Bass.Free()

        Else

            Console.WriteLine("Failed to initialize Bass.")

        End If

        Console.WriteLine("Press any key to exit.")
        Console.ReadKey()

    End Sub


    Public Function RecordCallback(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean

        Return True

    End Function

The output file is not being written. Is ManagedBass.Enc addon sufficient to write AAC file? Am I making any mistakes with the flags? Many thanks.

alicom

Many thanks. On a side note, can ManagedBass only natively play wav, mp3, ogg and flac? I could see that ManagedBass.Enc can record opus, but I could not play that by creating stream. Or was I missing a particular flag?

Chris

This is a List of the supported AddOns.
The simplest way is to do it via e.g  Bass_PluginLoad("bassopus.dll") .
then you can load it via Bass_StreamCreateFile...

GTHvidsten

I'm struggling getting custom bitrates with this (v0.0.0.3).
Using the BASS.NET wrapper I'm creating the AAC encoder like this:

var encoder = new EncoderBassEnc_Aac(myMixer)
{
    FDKAAC_ConstantBitrate = 320 * 1024,
    UseAsyncQueue = true
};

(I've also tried multiplying by "1000")

No matter which bitrate I'm setting this results in a variable bitrate averaging 128k (Winamp reports it fluctuating between 125 and 133 kbps).
Trying to use Profile (object type) = 5 (HE_AAC) and the bitrate changes to an average of 64k regardless of the bitrate setting.
Changing the VBRMode to 1 has no effect.

How can I modify the bitrate?

Ian @ un4seen

I'm not seeing a problem here when using the "--bitrate" option with BASS_Encode_AAC_Start, so to check if it's a problem with BASS.Net's EncoderBassEnc_Aac wrapper class, please try using BASS_Encode_AAC_Start directly instead:

encoder = BassEnc_Aac.BASS_Encode_AAC_Start(myMixer, "--bitrate 320000", BASSEncode.BASS_ENCODE_QUEUE, null, IntPtr.Zero);

GTHvidsten

Using that command gives me an average of 320kbps in Winamp. It still varies a bit, though, so it's not 100% constant, but it at least matches what I've seen from other encoders at other times.

So I guess there's a problem with BASS.Net.

GTHvidsten

Decompiling the EncoderBassEnc_Aac class I can see it has a method BuildEncoderCommandLine() which doesn't build it up correctly. The bitrate is never set if CBR is chosen.

radio42

Correct, there is a bug in the EncoderBassEnc_Aac class - it will be fixed asap by tomorrow!

radio42

An update is up on this page - Bass.Net v2.4.17.8 - which fixed the command-line for the EncoderBassEnc_Aac