SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
30.64k stars 3.19k forks source link

Kernel: es1370 AudioPCI sound card driver #4323

Open danboid opened 3 years ago

danboid commented 3 years ago

As it stands, Serenity only has the one soundcard driver and thats for the Soundblaster 16. Unfortunately its for the SB16 ISA, not PCI, because that is what qemu emulates. This isn't much use for us hardcore few wanting to run Serenity on bare metal because many desktop PCs of the Pentium 3/4 era (which are the majority of machines capable of running Serenity) had already ditched ISA slots.

Thankfully, both qemu-system-i386 and qemu-system-x86_64 support emulating the Esonique AudioPCI / es1370 PCI sound card, which is more accessible as a physical device simply by virtue of it being a PCI card. After the AudioPCI was released, Ensoniq was acquired by Creative Labs, which re-labeled the AudioPCI as the SoundBlaster PCI 64, and later the SoundBlaster PCI 128.

I was unable to get qemu's es1370 driver working under Ubuntu 20.04 or FreeBSD 12 VMs when running under virt-manager but I have got it working under a NetBSD 9.1 i386 qemu VM (running on a Ubuntu host) so we have a known-working-with-qemu, BSD licensed driver available as reference.

http://ftp.jp.freebsd.org/pub/NetBSD/misc/joerg/GENERIC/src/src/sys/dev/pci/eap.c.html ftp://ftp.alsa-project.org/pub/manuals/ensoniq/ (ES1370 and 1371 datasheets) https://wiki.osdev.org/Ensoniq_AudioPCI

$ qemu-img create netbsd-disk.img 20G
$ qemu-system-i386 -enable-kvm -m 2048M -drive file=netbsd-disk.img,if=virtio -cdrom \
             ./Downloads/NetBSD-9.1-i386.iso -display curses -boot d \
             -nic user,model=virtio-net-pci
# Install NetBSD then quit the installer and `poweroff`
$ qemu-system-i386 -enable-kvm -m 2048M -drive file=netbsd-disk.img,if=virtio -display curses -boot d -net nic -net user -soundhw es1370

# After booting into NetBSD:
$/etc/rc.d/dhcpcd onestart
$ ftp https://freewavesamples.com/files/Ensoniq-ZR-76-03-Dope-85.wav
$ audioplay Ensoniq-ZR-76-03-Dope-85.wav

I failed to get NetBSD 9.1 and 9.0 to boot under virt-manager but they boot fine under qemu with the above commands.

CodeforEvolution commented 3 years ago

As another possible reference driver, the Haiku operating system also has a driver for the ES1370 that functions under QEMU. It's licensed under the MIT license, though the audio output from the driver is a bit crackly at the moment when I recently tested, and only works on a recent "nightly" version of Haiku: https://github.com/haiku/haiku/tree/master/src/add-ons/kernel/drivers/audio/ac97/es1370

danboid commented 3 years ago

Haiku was actually the first OS that I tested looking for a reference driver but the latest nightly (at least from a couple of days ago) failed to boot under virt-manger for me. I then tried beta2 which did boot but didn't recognise qemu's es1370.

CodeforEvolution commented 3 years ago

Strange, than again, the nightlies are known to be hit or miss at times. :) The latest one worked for me, you'll also want to make sure that you specify "-m 512M", as the nightlies contain lots of debugging symbols, and can be heavier on boot.

danboid commented 3 years ago

I tried the latest nightly build ( haiku-master-hrev54756-x86_gcc2h-anyboot ) and yes, It both booted fine under virt-manager and I got it to recognise the qemu es1370 and play back the wav I linked to above.

This Haiku driver has the advantages of being C++ instead of C like the NetBSD driver and its currently approx one third of the size but it failed to play back my test wav correctly. It sounded like it was being played back at half speed. I wonder if the Haiku driver has been tested with a physical es1370 yet? I'll try that soon.

@awesomekling :

I'm pretty sure I've already highlighted this before to the Serenity community on IRC but Haiku's installer is a total tech wonder! When Serenity is mature enough to work on an installer, Haiku is the gold standard to beat or at least try to match in speed and simplicity. It honestly seems to defy all laws of computing in how fast it is.

Note that running and installing Haiku inside a VM on your beastly PC doesn't do the Haiku installer justice. What you need to do to truly understand how amazing it is is write Haiku onto the slowest USB drive you have that can fit the install image and then use that to install Haiku onto the slowest mechanical HD of the crappest machine that you can get it to boot on and watch how fast it installs a full OS complete with browser, gcc etc. It installs faster than it boots off the HD somehow - no joke!

awesomekling commented 3 years ago

Please calm down with feature requests unless you intend to work on them yourself. SerenityOS development is driven by people wanting to work on things, not by people being told what to do. :)

danboid commented 3 years ago

I do intend to work on this myself and I will stop making requests*.

My apologies @awesomekling

*Valid bug reports are still OK, right? : )

danboid commented 3 years ago

I have opened a bug report for the Haiku driver:

https://dev.haiku-os.org/ticket/16639

I'm happy to wait a while to see if the Haiku team can get their es1370 driver working well enough and if they do I'll ask if they mind me having a pop at porting it to Serenity, provided that no-one beats me to it by writing an all-new driver especially for Serenity.

tomuta commented 3 years ago

Conceptually looks pretty similar to the SB16, might be quite easy to implement once I finish my work on the audio driver framework. Maybe I'll even give it a try...

danboid commented 3 years ago

That would be very cool Tom! A few years ago I ported a wifi driver from FreeBSD to Haiku but that was easily done due to Haiku's network driver compatibility layer. This would definitely be more involved and not something I could hope to do overnight.

danboid commented 3 years ago

I have acquired a physical es1370 PCI card and I have successfully tested it under NetBSD 9.1 on one of the machines that can (usually) boot Serenity on bare metal.

No news on the Haiku driver yet but I'll keep you posted.