Subject: Mixing frequency/resolution in UADE.. little wishlist

From: Lem
Date: Sat Sep 24 13:03:01 2005

To: Kohina-UADE-Forum
Hi guys,

 Feature for UADE .. selectable mixing frequency? I wanted to play around with higher sampling rates than 44100Hz, but wasn't sure how to get UADE to do that. I'm using UADE 1.03.

 Letting the user either enter a custom mixing frequency, or having selectable presets (48000, 88K, 96K, 192K, etc) would be cool. 24bit output would be cool. 

 And, offtopic wishlist: customisable playlist entries in the XMMS/BMP plugin. Allow the user to say how the mods will be presented in the playlist (for example, %f for format, %t for songname/filename, so they could specify %f.%t, or %t.%f, or just %t .. etc).

Little wishlist :)

Cheers,
Lem

---

From: shd
Date: Sat Sep 24 14:26:03 2005

To: Kohina-UADE-Forum
[quote:82a570018b="Lem"]

[/quote:82a570018b]

Uade 1.0x is in feature freeze, so new features won't be added by me. Bugs can be fixed though. But hey, anyone can submit me source patches to add new features into 1.0x, but I'm spending my time with uade2..

48 kHz is possible with the command line tool, but the XMMS and BeepMP plugins will break. As this is not a feature, but rather a bug of the 1.0x, I can fix this for the next release.

For the command line tool just edit the uaerc file if you need 48 kHz. I don't know exact limits on the Hz range, but audio drivers could be the biggest limitation.

What is the reason for bigger sampling frequency? I would not like to add that for uade2 without a good reason. 44.1 kHz 16-bits stereo is more than enough for Amiga sound synthesis.

[quote:82a570018b]
[/quote:82a570018b]

I like that idea. We could add that into uade2 when we port it for xmms/beepmp.

---

From: shd
Date: Sat Sep 24 17:48:29 2005

To: Kohina-UADE-Forum
[quote:dca46c8ea9="Lem"]

[/quote:dca46c8ea9]

Please test the current cvs version, or apply the following patch to test sampling frequency change:

http://zakalwe.virtuaalipalvelin.net/uade/patches/patch-2005-09-24-samplingrate.diff

You must edit uaerc to change sampling frequency. btw. listening with 11025 Hz gives nice sound ;)

Please report back of success or failure. The sooner I get reports that it works, the sooner I'll release it.

---

From: Lem
Date: Mon Sep 26 14:32:22 2005

To: Kohina-UADE-Forum
I applied the diff to a clean uade-1.03 tree, then compiled (GCC-4.01 on AMD64 Debian Sid). UADE runs fine. I changed sound_frequency in ~/.uaerc to 96000 and tried dumping the sound to a raw file like this:

uade Be\ Funky.mod -outpipe 1 &gt;Be_Funky.raw

I then open the result in baudline (www.baudline.com), and find that the result is 44100Hz 16bit stereo, rather than 96000Hz 16bit stereo. Have I perhaps done something wrong?

---

From: Lem
Date: Mon Sep 26 14:46:17 2005

To: Kohina-UADE-Forum
Ah, I noticed /usr/share/uade/uaerc .. I changed sound_frequency in this file to 96000 and 58000 (just below maximum Paula outut, in case of possible emulation quirkiness), but I still got 44100Hz raw output.

---

From: shd
Date: Mon Sep 26 15:06:05 2005

To: Kohina-UADE-Forum
[quote:2581add190="Lem"]Ah, I noticed /usr/share/uade/uaerc .. I changed sound_frequency in this file to 96000 and 58000 (just below maximum Paula outut, in case of possible emulation quirkiness), but I still got 44100Hz raw output.[/quote:2581add190]

Try what strace says:

$ strace uade song 2&gt;errfile
&lt;ctrl-c&gt;
$ less errfile

Search for uaerc. I get:

access("/home/shd/.uade/uaerc", R_OK)   = 0
open("/home/shd/.uade/uaerc", O_RDONLY) = 3

Editing that file to, say 11025, gives me very audible results.

---

From: shd
Date: Mon Sep 26 15:08:04 2005

To: Kohina-UADE-Forum
[quote:b138e976cd="Lem"]I applied the diff to a clean uade-1.03 tree, then compiled (GCC-4.01 on AMD64 Debian Sid). UADE runs fine. I changed sound_frequency in ~/.uaerc to 96000 and tried dumping the sound to a raw file like this:

I then open the result in baudline (www.baudline.com), and find that the result is 44100Hz 16bit stereo, rather than 96000Hz 16bit stereo. Have I perhaps done something wrong?[/quote:b138e976cd]

Ah.. Noticed the error. ~/.uaerc is _not_ the file you should edit. It is ~/.uade/uaerc. The file in ~/.uade/uaerc takes precedence over /usr/local/share/uade/uaerc. Would editing ~/.uade/uaerc solve your problem?

---

From: Lem
Date: Tue Sep 27 01:32:56 2005

To: Kohina-UADE-Forum
Thanks shd, I got it working. I found that the uade binary ignores /usr/share/uade/uaerc. It does load ~/.uade/uaerc, and changing the sound_frequency works perfectly, all the way up to 192000Hz here.

I tried mixing at 44100 and 88200, and I heard a noticable difference. It's sort of like weak interpolation but not. I have an Audigy2 ZS (supports up to 24bit 192kHz 2 channel or 24bit 96kHz 6/8 channel, but I'm not sure how featured the Linux emu10k1 driver is, that is, does it even allow sampling rates above 48000Hz without downmixing in either software or hardware? I thought maybe the weak interpolation-like effect I heard was maybe from either software or hardware downmixing. In either case, the sound was cleaner &gt;44100Hz (in the case of be funky.mod and minute.mod by Hollywood).

I did a bit of experimenting. I have uade compiled with ALSA support. When I try to pass mixing frequencies &gt;192000Hz, uade reports "Couldn't open audio: Couldn't set audio parameters: Invalid argument", so I guess 192kHz does work. At certain frequencies above 100kHz, it sounds like the mod is slightly lower in pitch, quirky.

Have you tried higher mixing frequencies, and if so, can you hear any difference? Someone with a fully supported high resolution sound card might be able to test this, if there's anyone here with such a card.

Which file does the XMMS uade plugin try to load?

---

From: shd
Date: Tue Sep 27 06:54:29 2005

To: Kohina-UADE-Forum
[quote:1d8aac5319="Lem"]
Which file does the XMMS uade plugin try to load?[/quote:1d8aac5319]

The same as command line tool. The algorithm is. First try uaerc in home directory. If that doesn't exist, try to find a global uaerc.

---

From: alankila
Date: Sun Nov 13 20:39:24 2005

To: Kohina-UADE-Forum
UADE CVSversion features a new antialiasing output mode that can be turned on with either

interpolator ansi

or --interpolator=ansi and it should significantly alleviate the need to go for very high synthesis frequencies like 96 kHz. Going for higher rates might help slightly though, but the filters are designed for 44.1 kHz frequency and will not work at different rates...

If we want to support higher mixing rates the src/audio.c should compute the filter coefficients from the actual formulas for each sampling rate desired.

That being said I don't think it's necessary quality-wise. Based on my measurements the antialiasing interpolator works very well.

---

From: alankila
Date: Wed Nov 16 02:25:26 2005

To: Kohina-UADE-Forum
Me bozo. I meant anti, not ansi.

---

From: alankila
Date: Sat Dec 17 22:54:08 2005

To: Kohina-UADE-Forum
I hope I can push some changes to shd that further improve the antialiased output quality. The antialiasing output works by averaging the sample data between the periods that audio output is picked.

The problem is to resample the audio output that Paula generates at 3.5 MHz in desired audio output frequency such as 44.1 kHz. The correct solution for this job is a convolution with the sinc function (sin(x*pi)/(x*pi)) but using it is fairly expensive due to the excessive amount tof multiplications and summations required for every sample of generated output.

The first version of the antialiasing filter simply estimated the average of Paula's output between the sampling period (which is 80 Paula clocks). This is conceptually the same as convolution with the block function, which has a constant positive value in some range and falls to zero outside that range. (Unfortunately the convolution was calculated "after the fact" by investigating the audio state variables, and that estimation algorithm had a bug which caused the output to occasionally overshoot and clip, which is why shd disabled it for the -pre10.)

However, the block filter is in fact not terribly accurate and tends to average the audio over too wide a region, resulting in some loss of signal power in treble. The error is small, perhaps -0.8 dB for frequencies above 10 kHz, but nevertheless can be easily discerned on FFT. Perceptibly, this may appear as the audio coming out a bit too "smooth".

I now realized it's possible to produce a cheap, better approximation of the sinc function with the triangle function (1 - abs(x) for x in [-1, 1], 0 otherwise). The triangle function is just a combination of two straight lines, and it's very easy to compute the convolutions of such lines in this case.

However, since the triangle shape is a bit too narrow in respect to the sinc shape, some extra treble noise is now introduced, but it should be quite hard to hear. I hope I can improve the simulation a bit further with some cheap filtering...

---

From: alankila
Date: Thu Jan 12 10:10:36 2006

To: Kohina-UADE-Forum
http://bel.fi/~alankila/amiga/anti-sinc.diff

This one applies against the latest CVS version, but it is likely it works just fine against the 2.01 release too. This patch is not meant to inclusion, and it doesn't preserve the old antialiasing interpolator. However, it is a preview of what is to come.

It implements a 4096-point FIR sinc-based resampling algorithm with a cutoff frequency at 20 kHz. The transition band is quite narrow, only some 3 kHz, so all aliasing effects should become fully eliminated. You can see its performance here:

http://bel.fi/~alankila/amiga/uade-sinc.png

With this, any need for a mixing frequency above 44.1 kHz should be eradicated -- you can now think that the mixing happens at 3.5 MHz as it really does, and a resampling step is then applied to perform the conversion to the desired sampling frequency.

This is a fast algorithm because it makes use of the fact that a convolution with a constant can be implemented by an integral and one multiplication. Additionally, because the resampling rate is constant, it's possible to tabularize the integral, which is done. It uses about 6 % of CPU on my AMD64.

The magical 4096-point table is computed by a short python program that computes the sinc function for the right resampling effect and multiplies it with the hanning window, and then integrates numerically. The filter has a bit of ripple before the passband, something like 0.3 dB -- this may explain part of the problem.

It is however unknown at the present time why the curves do not line up perfectly above 15 kHz. There may be some additional lowpass filtering occuring in the audio path. I've seen this effect before, but I could not know whether it was due to sampling noise or aliasing, so I needed this sinc patch to know whether the effect was real.

It could be that the A1200E filter needs a lowpass filter to take care of that -- or then the effect could be due to extra pops and clicks in the PTK-Prowiz player or due to more bugs in the audio state machine. (Almost anything could contribute to the slight excess treble energy, we're talking about less than 0.5 dB in total here.)

---

From: alankila
Date: Sun Jan 15 20:46:47 2006

To: Kohina-UADE-Forum
The sinc interpolator was merged in CVS yesterday. It's now available from configuration or command line by choosing sinc as the interpolator. The previous patch had at least one bug too, and is obsolete now.