Author Topic: Strange pan behavior  (Read 203 times)

quattj

  • Posts: 3
Strange pan behavior
« on: 19 Jan '25 - 16:10 »
I'm working on some MIDI files.  I am using CoolSoft VirtualMIDISynth, which uses the BASSMIDI libraries.

I am noticing that a full pan in either direction does not provide actual full panning.

See this post from the midi.org forums:
https://midi.org/community/creating-with-midi/pan-is-full-but-not-panned#post-9498

Another user tested pan using miditest.exe from BASSMIDI.ZIP, and created a chart showing exactly the pan issues I am experiencing.
A pan of 0 still plays audio from the right channel at 50% volume, and a pan of 127 still plays audio from the left channel at 50% volume, and strangely, values slightly higher/lower than the min/max actually play MORE panned than the full pan.

Is this a known issue?  I would imagine it is not intentional.

Ian @ un4seen

  • Administrator
  • Posts: 26264
Re: Strange pan behavior
« Reply #1 on: 20 Jan '25 - 12:51 »
Please confirm what soundfont (and preset from it) you're using. I suspect it's using 2 (or more) samples for the instrument, with one panned 100% left and another panned 100% right. The MIDI panning (CC10) is added to the soundfont's panning. For example, when CC10=0, the 100% left sample will still be 100% left (it can't go any further left) but the 100% right sample will now be in the centre.

Bavi_H

  • Posts: 4
Re: Strange pan behavior
« Reply #2 on: 20 Jan '25 - 15:33 »
Hello. I'm Bavi_H who posted the results in the midi.org forum: Re: Pan is full, but not panned?

The attached zip file contains the example files I used.

I used the soundfont Sine.sfz. As you probably know, the sfz format is just a text file so you can look at it in a text editor, and it can only contain one preset. It uses the wave file middle-c-sine.wav which is a one cycle sine wave.

I used the MIDI file 10-step-pan.mid. It plays 10 middle C notes at different pan values.

I used the miditest.exe program in the BASSMIDI zip file download to play the MIDI file with the sine soundfont. (The dialog box to open a soundfont doesn't show sfz files by default, but you can choose "All files" to see it then select it and it will work.) I turned off the "Reverb & Chorus" checkbox.

I recorded the results in Audacity and amplified the recording so the maximum amplitude reached the top of the graph. I wrote down the amplitudes visible in the sound wave graph in Audacity. (I made the amplitude ruler show "half wave" and it had tick marks from 0.0 to 1.0 in steps of 0.1. I estimated the amplitudes to about 0.02 or 0.03.)

The results were the following (same as the MIDI.org forum post)

P is the MIDI pan value
L is the left channel amplitude (percent of maximum)
R is the right channel amplitude (percent of maximum)

P___   L___   R___   
010050
159848
299250
438558
577865
716578
855885
995092
1134898
12750100

I used the current versions

bass.dll 2.4.17.0
bassmidi.dll 2.4.15.3

I also tried the current beta versions, but got the same results

bass.dll beta 2.4.17.41
bassmidi.dll beta 2.4.15.4

Ian @ un4seen

  • Administrator
  • Posts: 26264
Re: Strange pan behavior
« Reply #3 on: 20 Jan '25 - 17:10 »
The attached zip file contains the example files I used.

I used the soundfont Sine.sfz. As you probably know, the sfz format is just a text file so you can look at it in a text editor, and it can only contain one preset. It uses the wave file middle-c-sine.wav which is a one cycle sine wave.

I used the MIDI file 10-step-pan.mid. It plays 10 middle C notes at different pan values.

I used the miditest.exe program in the BASSMIDI zip file download to play the MIDI file with the sine soundfont. (The dialog box to open a soundfont doesn't show sfz files by default, but you can choose "All files" to see it then select it and it will work.) I turned off the "Reverb & Chorus" checkbox.

That's strange then. I'm unable to reproduce what's in your recording when trying the same here. As the soundfont/SFZ is mono, what I wrote in my last reply doesn't apply. I'm not sure what else could be causing it. Perhaps there's some processing of the sound after it's left BASSMIDI? Here's a modified MIDITEST.EXE that'll also write the BASSMIDI output to a WAV file:

   www.un4seen.com/stuff/miditest-wav.zip

Does the written WAV file look the same as your recording?

Bavi_H

  • Posts: 4
Re: Strange pan behavior
« Reply #4 on: 20 Jan '25 - 18:16 »
Here's a modified MIDITEST.EXE that'll also write the BASSMIDI output to a WAV file: [...]

Does the written WAV file look the same as your recording?

The directly written wav file has a typical looking pan response, see the table below and the attached graph.

So it looks like my original recording test was flawed, there must be some hardware or software issue on my computer when I record the audio from other programs.

(Strangely, even though the new directly written wave file looks correct, I can still hear a very audible tone on the silent channel even when the wave graph shows it is silence. However, that must be something strange on my computer, I'll continue investigating.)

_____

P is the MIDI pan value
L is the left channel amplitude (percent of maximum)
R is the right channel amplitude (percent of maximum)

P___   L___   R___   
01000
159817
299435
438650
577665
716576
855086
993594
1131798
1270100

David_AVD

  • Posts: 88
Re: Strange pan behavior
« Reply #5 on: 20 Jan '25 - 20:48 »
Could it be that there is an audio enhancement feature enabled for your sound output device?

Bavi_H

  • Posts: 4
Re: Strange pan behavior
« Reply #6 on: 20 Jan '25 - 21:54 »
Review so far: quattj (Jason on the midi.org forum) originally reported the problem on his computer that sound fully panned to one channel was still quite audible on the other channel. I tested on my computer and heard and recorded the same kind of problem. However the miditest.exe that outputs directly to a wav file creates a good looking sound wave on my computer. (It still sounds wrong, but I think that's some problem with my computer now.)

I'm interested if quattj also gets a good looking sound wave with the miditest.exe that outputs directly to a wav file. If yes, does it sound right or still sound wrong?

I wonder if quattj and I both have the same thing causing the problem on our computers, or different things causing the problem on our computers...


Could it be that there is an audio enhancement feature enabled for your sound output device?

I turned all of those settings off a long time ago. I checked and they're still all turned off. See the attached picture.

Bavi_H

  • Posts: 4
Re: Strange pan behavior
« Reply #7 on: 21 Jan '25 - 00:26 »
Could it be that there is an audio enhancement feature enabled for your sound output device?
I turned all of those settings off a long time ago. I checked and they're still all turned off. [...][The attached picture shows the Sound control panel. A subwindow for the output device is on the Enhancements page and has all the enhancement options unchecked.]

While researching about crosstalk problems, I found another page that also recommended checking that audio enhancements are disabled and mentioned there might be another control panel with audio enhancements in it.

It turns out that was my problem. In my Control Panel there's a "DTS Audio Control Panel". I opened it, went to the "Listening Experience" page and unchecked the "Audio Enhancements" box.

Now when I repeat my original pan test it sounds and records correctly, and the wav file that was created directly also sounds correctly.

(I may have thought "DTS audio" was only relevant when playing DVDs in my computer's DVD drive, so I may have never looked at that control panel much before.)
« Last Edit: 21 Jan '25 - 00:56 by Bavi_H »

quattj

  • Posts: 3
Re: Strange pan behavior
« Reply #8 on: 21 Jan '25 - 17:52 »
Very interesting.  In my case, even though the audio enhancements checkbox is enabled, that is not the cause for me.  It is actually that the samples in the soundfont must be stereo.  I use assorted soundfonts, but the instrument that I particularly noticed the issue on is 0:81 Square Lead in Timbres of Heaven.

I ran a test using bavi's sine wave sample, playback in Winamp as before, recording using audacity, and pan response is exactly as expected.  So I didn't even need to use the miditest to see results.

The MIDI panning (CC10) is added to the soundfont's panning. For example, when CC10=0, the 100% left sample will still be 100% left (it can't go any further left) but the 100% right sample will now be in the centre.
Can you explain the technicalities of this a little more?  Is there a reason it is simply added together rather than ... ummm... mathematically adjustificated so the pan would still audibly work the same? 
Not a huge deal, but now I'm curious about the math that would be required to make it effective, and what kind of performance issues it might cause.

EDIT: I made a test virtual pan slider in GameMaker to try some math out, and can post it if you're interested.  Essentially it gets a scale factor for the pan based on the initial pan in the soundfont, and uses that to scale the changes in pan values rather than simply adding them together.  Though it's feasibility in the "real world" is currently unknown to me.
« Last Edit: 21 Jan '25 - 20:13 by quattj »

Ian @ un4seen

  • Administrator
  • Posts: 26264
Re: Strange pan behavior
« Reply #9 on: 22 Jan '25 - 12:52 »
Can you explain the technicalities of this a little more?  Is there a reason it is simply added together rather than ... ummm... mathematically adjustificated so the pan would still audibly work the same? 
Not a huge deal, but now I'm curious about the math that would be required to make it effective, and what kind of performance issues it might cause.

All samples are mono in the SF2 format, with stereo being formed by having 2 mono samples, panned 100% left and 100% right. The SF2 spec states that normal panning processing still applies in that case, which means the CC10 value is added to the soundfont's panning for each of the samples. If you try the same soundfont on Creative/SoundBlaster hardware, you will hear the same result. I would expect the same from other SF2 synths too.

SFZ does support stereo sample data, and BASSMIDI applies CC10 as a balance control in that case, ie. the left and right channels never mix, only their levels change. BASSMIDI and the XMPlay MIDI plugin mostly share the same code, but there is an "Alternative stereo sample panning" option that only the XMPlay MIDI plugin currently has, which will detect stereo samples in SF2 soundfonts (by them being panned 100% left and right) and apply CC10 to them as a balance control. Perhaps that option can be added to BASSMIDI too. To see if such an option is what you need, please try your files with the XMPlay MIDI plugin (you'll need XMPlay too).

quattj

  • Posts: 3
Re: Strange pan behavior
« Reply #10 on: 22 Jan '25 - 18:41 »
Yes, the "Alternative Stereo Sample Panning" does exactly what I originally expected from panning in my files ;D

I suppose one plus side to the way it currently works without that feature is that it sounds really good on my Logitech surround speakers in the stereo to 5.1 sound expansion mode  ;)

Ian @ un4seen

  • Administrator
  • Posts: 26264
Re: Strange pan behavior
« Reply #11 on: 23 Jan '25 - 15:19 »
OK, here's a BASSMIDI update that includes the same option:

   www.un4seen.com/stuff/bassmidi.zip

The option is currently called BASS_MIDI_FONT_STEREO (for stereo sample detection), but it isn't enabled by default, so existing code would need to be updated to enable it in their BASS_MIDI_FontInit and/or BASS_MIDI_FontFlags function calls.