Adjustable Soundbuffers for low latency sound

Here you can provide suggestions on how to improve the product, website, etc.
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Adjustable Soundbuffers for low latency sound

Post by personal1984 »

NERD ALERT!!

I have ASIO drivers installed in the guest inside the virtual machine on a linux host. This means everthing inside guest cannot be lowered. I want virtualbox to have adjustable number of soundbuffers and adjustable soundbuffer size. The problem is not in the guest, but in the virtual machine, probably alsa code.

I have Karmic Kubuntu with latest Virtual Box installed, i unfortunately need the closed source part of virtual Box to connect my Roland PCR Usb Midi Controller. I have a latency wich i guess to be at at least 70 milliseconds. I studied some code, because i use ALSA i first tried a RT Kernel, with no success.

In the code 'alsaaudio.c' i found very large sound buffers.

#ifdef HIGH_LATENCY
INIT_FIELD (.buffer_size_in =) 400000,
INIT_FIELD (.period_size_in =) 400000 / 4,
INIT_FIELD (.buffer_size_out =) 400000,
INIT_FIELD (.period_size_out =) 400000 / 4,
#else
#define DEFAULT_BUFFER_SIZE 1024

I want to change the number of buffers, and i want the buffers to be smaller so i can reach below 40 milliseconds (still audiable).

So reason runs fine, all my songs without problem, but i want to produce music on linux in this virtual machine with a network mapped drive to my self produced music.

Many others want reason with low latency too.

But!!! I can recompile only without the USB part. So i can have lower latency, but without the USB closed source part it is of no use.

Solution, Sun can provide an option in the Sound System selection of the Virtual Box main window
1 how many soundbuffers
2 how large soundbuffers are

Then i would not have to boot up windows anymore to produce music.

Image
Reason with around 70ms
Last edited by personal1984 on 15. Jan 2010, 17:41, edited 1 time in total.
Technologov
Volunteer
Posts: 3342
Joined: 10. May 2007, 16:59
Location: Israel

Re: Adjustable Soundbuffers for low latency sound

Post by Technologov »

There are some patches sent recently about PulseAudio.... maybe they can guide you if you are a developer
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Re: Adjustable Soundbuffers for low latency sound

Post by personal1984 »

I made an example video, i see a future for musicians where windows is nothing more than a virtual machine, i am also explaining in the video how far i got.

Technologie preview see youtube video:
http://www.youtube.com/watch?v=KfmtfkFwLpA

Midicontrollers opera: Yes
Sound glitches: No
Latency: around 70 ms

Buffers of sound for virtual machine not changeable without closed source USB part: unfortunately we depend for a very small change in the source code on SUN. Not a change in the closed source part. Just to change the audio buffers.
DeiF
Posts: 4
Joined: 15. Jan 2010, 19:14
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: Windows XP

Re: Adjustable Soundbuffers for low latency sound

Post by DeiF »

I vote for this feature.

Currently music production in Linux is impossible (at least for certain level of quality) because:
  • Native music apps (like Rosegarden, Ardour, etc) lack essential features (I know this is very subjective though), and there are no professional sound "packs" (Garritan Personal Orchestra, etc) available natively for Linux.
  • Wine isn't 100% compatible with all the Windows plugins, plus the function "CreateScalableFontResourceW" isn't implemented yet, which prevents any music app from displaying a musical score.
  • Virtualized solutions like VirtualBox/VMWare/Parallels/etc have a high latency, and thus can't be used.
Add to that the current audio mess in Linux (OSS, ALSA, Jack, PulseAudio, etc).

But if it's true that 70ms of latency in VirtualBox is achievable, then it could mean a new era of music production in Linux (half of that latency or less would be the ideal though).

Please, include that feature.
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Re: Adjustable Soundbuffers for low latency sound

Post by personal1984 »

Hi, thank you for voting, i assure you it is less then 100 milliseconds, but absolutely more than 60, i guess at 70ms, i can play on it but i need at least 35 milliseconds to make it not becoming uncomfortable.

I use these ASIO drivers, they work very well:
http://www.asio4all.com/

Anyway, Reason is especially well programmed audio software, it would be a breakthrough to get reason -although in a virtual machine- working below 35 milliseconds. Like i said all my songs perform well without glitches.

We always have the RealTime RT Kernel, Virtual Box only has to recompile its kernel module and so the ATI/NVIDIA kernel module has to be recompiled (less than 24 minutes needed)

The box of magic is still filled with tricks.
I see a future for windows existing as virtual machine inside linux.

I just wanna play on linux, here another example what i wanna play on Kubuntu Karmic
http://www.youtube.com/watch?v=-cpv4dQZ99k
(You can take latency into account when playing)
Aceler
Posts: 8
Joined: 16. Oct 2007, 21:14
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu
Location: Nizhny Novgorod
Contact:

Re: Adjustable Soundbuffers for low latency sound

Post by Aceler »

I was able to setup WindowsXP and Cubase LE inside VirtualBox with latency of 16ms.

The recipe:

Kubuntu x86_64, rt kernel. VirtualBox from VirtualBox official repository (Version 3.0.12, not OSE). Windows XP x64, ASIO4ALL, Cubase LE, some VST instruments from Cubase. AMD-V is turned on.

Set up ASIO driver buffers to 1024, compensation to 1024, turn hardware buffer off.

Drivers said, that the latncy is 16ms, I feel that it is true. I still have some issues on a high CPU load.
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Re: Adjustable Soundbuffers for low latency sound

Post by personal1984 »

Hi, thank you for trying cubase, well reason inside the guest says: 22milliseconds, however this is not true, when i play 'the incredible hulk' on it i notice the latency is around 70 milliseconds, yes i can play but it is absolutely not 22 milliseconds.

My question is, did you hook op a midi device to cubase? Did you try to play on your midi controller e.g. a sonate? Did you play live?

But you just confirmed the problem is not inside the guest, ASIO4ALL does a good job.

Anyhow, can you make a video and place it on youtube? People want to see this with there own eyes.
(i do)

Yesterday i tried again installed the realtime kernel, compiled virtual box module and nvidia module for it, with no better result than with a standard linux kernel.

I tried rosegarden, but it is a mystery to me. For rosegarden you need to do much more than simply installing virtual box and simply installing windows in that virtual machine and installing reason in it.

So the linux native software for musicproduction is even complicater for me than running reason setting up reason, setting up virtual machines, installing windows etc...
But no shame, i saw another geek baffled with it too, after 2 days he gave up, not making a single note audiable on linux, and he went back to windows.
Aceler
Posts: 8
Joined: 16. Oct 2007, 21:14
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu
Location: Nizhny Novgorod
Contact:

Re: Adjustable Soundbuffers for low latency sound

Post by Aceler »

My question is, did you hook op a midi device to cubase? Did you try to play on your midi controller e.g. a sonate? Did you play live?
Yes, of course. I have an Yamaha MM-6 device, which is connected via USB, and I installed a Yamaha USB2MIDI drivers from Yamaha website inside the guest OS. I tried to play live the latency was less that 20ms, I can feel this.

For the linux sound software, I use Ardour 3, but it is still in development. But it works :)

I'll try to make a video, it will have a poor quality, because I only have camera in my smartphone.
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Re: Adjustable Soundbuffers for low latency sound

Post by personal1984 »

As i understand you are not playing a midi out instrument, but a VST instrument with 20ms latency?
I know what you mean with 'i can feel it'. I said i can hear it, but you are right, it is really a low latency 'feeling', you touch (and feel) and hear the result.

20ms latency with a VST instrument really surprises me, it makes me wonder why i cannot reach 20ms latency with Reason.

I tried Pulse audio, Alsa audio, and OSS audio, so what one did you use on the host? It is quite shocking to me that you can reach 20ms on a VST instrument. I also tried latency compensation inside the guest within reason, no result.

Did you use a virtual soundblaster or a virtual ICH AC97 as virtual audio device?

I understand you have a CPU capable of virtualization, i have a Q8200 without virtualisation. But i have seen Virtual Box source code, the buffers are huge (in the eye of a musician).

I too have a mobilephone with internal camera for my youtube vids...

What i mean: MIDI is at a boutrate of approx. 31kbits, that is nothing even for a virtual machine, if you play with MIDI IN-> CUBASE -> MIDIOUT ->sound from MIDI OUT device (almost instantly) it does not surprise me. It would surprise me with this MIDI IN -> CUBASE -> VST Instrument -> sound from VST instrument (20 milliseconds)
Aceler
Posts: 8
Joined: 16. Oct 2007, 21:14
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu
Location: Nizhny Novgorod
Contact:

Re: Adjustable Soundbuffers for low latency sound

Post by Aceler »

DeiF
Posts: 4
Joined: 15. Jan 2010, 19:14
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: Windows XP

Re: Adjustable Soundbuffers for low latency sound

Post by DeiF »

OpenSuSE 11.2 64bit here, desktop kernel (2.6.31 with preempt enabled), with VirtualBox 3.1.2 r56127 (not OSE) running a Windows XP SP3 (32bit) guest.
My CPU is an Athlon 64 3000+ @ 1.8Ghz, 2GB RAM, etc. No AMD-V extension is present.

I downloaded some free VSTi (DVS Saxophone, Prova, Triangle II...) and tested them with savihost.
The 3 audio options present in the program are MME, DS and ASIO4ALL.
Of the 3, only MME gets no cracking noise. I tried also Aceler's suggestion of 1024 driver buffers, compensation to 1024 and hardware buffer off for ASIO4ALL (to no avail).
All of the 3 get like 250ms latency (the duration of a eighth note in a 120 bpm tempo).

I tried also Cakewalk Pro Audio 9, put some notes in the staff view and hit play: same latency.
It's even worse: sometimes (specially the first time that something is played) the notes get the timing wrong. I wrote 8 eighth notes and some of them sounded slightly out of time. Could this be attributed to the CPU changing frequencies on demand in the host?
Aceler
Posts: 8
Joined: 16. Oct 2007, 21:14
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Mostly Ubuntu
Location: Nizhny Novgorod
Contact:

Re: Adjustable Soundbuffers for low latency sound

Post by Aceler »

First of all, VirtualBox's documentation says that running 32-bit Windows guest on 64-bit Linux host will cause a performance issues.

Second, I think, that hardware virtualization is essential.
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Re: Adjustable Soundbuffers for low latency sound

Post by personal1984 »

I have seen your video, at the end you show a VST instrument, and i conclude from that, that you have very low latency, unfortunately i do not have a Virtualization capable CPU.

So i cannot run a 64bit guest, however i have to look at the manuel of virtual box, i am running a 32bit guest (xp) on a 32bit Kubuntu Karmic version, it was said that running a 32bit guest on a 64bit host has performance pennalty.

So the conclusion might be,
1 Virtual Box allready supports low latency if you have VT Virtualization and are running 64 bit guest on 64 bit host.
2 Virtual Box does not support low latency otherwize.

But howcome i have seen so large soundbuffers inside the Virtual Box source code, i probably am void in a mystery.

in case 1 virtualbox makers can say 'well its working if you have a VT CPU and a 64bit host and a 64bit guest'.

Would this be the whole story? Not for me, i am stuck at the HIGHLATENCY part in the virtual box source code. I can run Reason without any sound glitch with ASIO4ALL and DX PRIMARY both as well. But the latency...

So a few sad smilies here for me :( :( :( :(

Another example, playing the terminator inside the virtual machine....
http://www.youtube.com/watch?v=8Np4MitMmfk
DeiF
Posts: 4
Joined: 15. Jan 2010, 19:14
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: Windows XP

Re: Adjustable Soundbuffers for low latency sound

Post by DeiF »

Aceler wrote:First of all, VirtualBox's documentation says that running 32-bit Windows guest on 64-bit Linux host will cause a performance issues.

Second, I think, that hardware virtualization is essential.
I haven't been able to find such info in the manual. Care to link to the source?

Unfortunately 64-bit guests on 64-bit hosts without hardware virtualization is not supported in VirtualBox, according to the docs.

I will try to compile Virtualbox-OSE from the sources and change the audio latency to see if things improve.
personal1984
Posts: 11
Joined: 14. Jan 2010, 14:17
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: XP

Re: Adjustable Soundbuffers for low latency sound

Post by personal1984 »

"I will try to compile Virtualbox-OSE from the sources and change the audio latency to see if things improve."

I wanted to do this too, but i advise you to do it on a system used for testing. You might mess up your installation??? However without the USB part you cannot connect a midi controller or synthesizer, so you cannot 'just feel' the latency. The only way to actually test is if you have a midi controller/synthesizer and are able to 'feel' the latency yourself by playing.
Post Reply