Author Topic: MP3 AAC/MP4 all play as mono on macOS  (Read 280 times)

BaseHead

  • Posts: 204
MP3 AAC/MP4 all play as mono on macOS
« on: 20 Dec '24 - 06:42 »
Hey Ian and gang!

Got a strange one.  We ported basehead to AvaloniaUI with .NET6 over the past 3 years and everything is rocking besides two issues, but I will only discuss one here.

For some strange reason MP3 AAC/MP4 only on macOS play and draw as dual mono and we have zero special cases for MP3 AAC/MP4 files when creating streams.
I've killed the mixmatrix and hard set the mixers back to 2 channels and nothing helps.  Playback is in both speakers but the same exact material making them sound mono.
Also tried bypassing all the addons also.
 I tried the same files in the Speakers test project on macOS and that is fine also.

Any suggestions for things to look for?
thx!

Steve

Ian @ un4seen

  • Administrator
  • Posts: 26223
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #1 on: 20 Dec '24 - 14:58 »
If the files are playing fine with the BASS examples then it sounds like the problem is related to something special that your app is doing. Is it definitely only affecting MP3/AAC/MP4 files, or is it just that MP3/AAC/MP4 are the only formats you've tried? If the latter, please try WAV or OGG too.

To narrow down where the problem is, you could try setting a WAV writer on an affected file stream using BASSenc (BASS_Encode_Start with BASS_ENCODE_PCM) and then see if the written WAV file is mono too. If the file is going through several streams (eg. mixers/splitters) before output, you could set a WAV writer at each stage.

BaseHead

  • Posts: 204
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #2 on: 20 Dec '24 - 16:25 »
WAV, AiF and FLAC are all fine, but OGG is also dual mono instead of stereo.   It's like it just hates compressed files but only on macOS.   Strange!
Let me try your suggestions and report back tomorrow.  Thx man!

BaseHead

  • Posts: 204
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #3 on: 3 Jan '25 - 05:19 »
Ok so I didn't even need to go past a test stream.  With a bit of Help of Claude inside VSCode he deteremined the Left and Right side data was indeed different but noticed that info.chans == "1" for these file types.

If I add this basic non-platform specific code
Code: [Select]
  Streams[0] = Bass.BASS_StreamCreateFile(path, 0, 0,  BASSFlag.BASS_STREAM_DECODE);

                if (Streams[0] != 0)
                {
                    var info = Bass.BASS_ChannelGetInfo(Streams[0]);
                    Helper.Utils.DeepLogWrite($"Stream Info: Channels: {info.chans}, Freq: {info.freq}");

                }

The same MP3's show as 2 channels on Windows but as only 1 channel on macOS in info.chans printed to a log file......Whaaa?

FYI: We are using .NET6 on mac with AvaloniaUI so I am not sure if that has anything to due with it but everything else works fine and works like butter besides the compressed formats chanel info.
Claude suggests // Set mono-to-stereo flag if available for specific file types in BASS but don't see one for streams in the docs.


Any idea how these can be reading as 1 channel when they are definately not?
Thx man and NYE!  ;-)

Steve


Ian @ un4seen

  • Administrator
  • Posts: 26223
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #4 on: 3 Jan '25 - 14:47 »
If I add this basic non-platform specific code
Code: [Select]
  Streams[0] = Bass.BASS_StreamCreateFile(path, 0, 0,  BASSFlag.BASS_STREAM_DECODE);

                if (Streams[0] != 0)
                {
                    var info = Bass.BASS_ChannelGetInfo(Streams[0]);
                    Helper.Utils.DeepLogWrite($"Stream Info: Channels: {info.chans}, Freq: {info.freq}");

                }

The same MP3's show as 2 channels on Windows but as only 1 channel on macOS in info.chans printed to a log file......Whaaa?

Strange indeed. Please confirm what flags you're using in your BASS_Init call, and in particular, does it include BASS_DEVICE_MONO? And if you call BASS_GetInfo, what "initflags" value to you see?

BaseHead

  • Posts: 204
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #5 on: 6 Jan '25 - 12:47 »
Here ya go!

Code: [Select]
#if IsOSX
                basehead.Services.bass.BASS_Free();
                if (isInitializedBASS = basehead.Services.bass.BASS_Init(-1, sampleRate, basehead.Services.bass.BASS_DEVICE_DEFAULT, IntPtr.Zero, IntPtr.Zero))
                {
                    Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER,50);
                    basehead.Services.bass.BASS_SetConfig(basehead.Services.bass.BASS_CONFIG_UPDATEPERIOD, 3);
                    basehead.Services.bass.BASS_SetConfig(basehead.Services.bass.BASS_CONFIG_FLOATDSP, 1);
                    basehead.Services.bass.BASS_SetConfig(basehead.Services.bass.BASS_CONFIG_SRC, _AudioOption.IdxPlaybackQuality);  //SRC Quality Setting
                    Helper.Utils.LogWrite(LogEventType.Information, "SoundPlayer InitBASS: OK!");
                }
                else
                {
                    int error = basehead.Services.bass.BASS_ErrorGetCode();
                    if (error != basehead.Services.bass.BASS_OK)
                    {
                        Helper.Utils.LogWrite(LogEventType.Error, "SoundPlayer InitBASS Error Code: >> " + error.ToString());
                    }
                }
#else

no BASS_DEVICE_MONO for sure as would affect WAV, FLAV and AIFF
Yup...as weird as it gets my friend.  ;-)

as far as initflags if I add this I get the value of 2 for "BASS Flags" written to our log.
Code: [Select]
            basehead.Services.bass.BASS_INFO bass_info = new basehead.Services.bass.BASS_INFO();
            basehead.Services.bass.BASS_GetInfo(ref bass_info);
            Helper.Utils.DeepLogWrite($"BASS Flags: {bass_info.initflags}");

thx for the help man!
s.

Ian @ un4seen

  • Administrator
  • Posts: 26223
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #6 on: 6 Jan '25 - 13:11 »
as far as initflags if I add this I get the value of 2 for "BASS Flags" written to our log.

2 = BASS_DEVICE_MONO :)

So that explains what you're seeing, but now the question is where that BASS_DEVICE_MONO came from. What is "basehead.Services.bass.BASS_DEVICE_DEFAULT" defined as? Also, did you call BASS_GetInfo straight after the BASS_Init call above? If not, is it possible there's another BASS_Init call (with different flags) elsewhere?

The BASS_DEVICE_MONO flag doesn't affect all decoders, so some streams may still be stereo, like you've seen.

BaseHead

  • Posts: 204
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #7 on: 10 Jan '25 - 13:33 »
It's getting weirder now....haha

I added flag checks in 3 other spots directly after BASS_Init() in the program and all 3 show a value of "2"
BUTTTTT the original one I added directly after basehead.Services.bass.BASS_ChannelPlay(Mixer, true); that said "2" before shows a value of "0" now.  HUH?
No where is a flag to set it to MONO.

Is there anyway to force STEREO just for these file types?

I am not sure why my coders is using this  basehead.Services. for the macOS version and not the PC version.  My guess it's some hack to use it on .NET6 on mac and I have a feeling this is causing the issue.  He is in the hospital now from a car accident so I can't really ask ATM.  8(

thx for any extra help and ideas to try man!

s.

Ian @ un4seen

  • Administrator
  • Posts: 26223
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #8 on: 10 Jan '25 - 16:28 »
I think I see what's going on now. "basehead.Services.bass.BASS_DEVICE_DEFAULT" is probably just BASS's BASS_DEVICE_DEFAULT flag, which is defined as 2 (eg. in BASS.H). That isn't a valid flag for a BASS_Init call but it happens to have the same value as BASS_DEVICE_MONO, so has the same effect. Try using 0 there instead:

Code: [Select]
                if (isInitializedBASS = basehead.Services.bass.BASS_Init(-1, sampleRate, 0, IntPtr.Zero, IntPtr.Zero))

Sorry to hear about your coder's misfortune! Hopefully it'll be possible to fix this without bothering them.

BaseHead

  • Posts: 204
Re: MP3 AAC/MP4 all play as mono on macOS
« Reply #9 on: 12 Jan '25 - 05:09 »
You nailed it!

Thx as always man.  You Rock!  8)
Steve