Creative Labs X-Fi
From Gentoo Linux Wiki
The X-Fi series of sound cards from Creative Labs is one of the best consumer oriented pieces of audio hardware today. It features:
- Full Hardware Processing
- CMSS-3D for virtual headphone surround sound
- Crystalizer for enhancing compressed audio
- THX Certified
- Hardware DTS and Dolby EX
Unfortunately, for years after the Windows release of the card, there existed no Linux driver. Creative has released two drivers now, 1.14, and latest, 1.18. Both have significant reliability problems and do not even compile on most systems.
This HOWTO will demonstrate how to use the 1.18 driver on Gentoo with ALSA built into the kernel. It is a complete and very BAD hack. I will repeat this: THIS IS A COMPLETE HACK!
Contents |
[edit] Non-Working Features
The following features do not work at all:
CMSS 3D 24 Bit Crystalizer X-RAM (Platinum Models)
[edit] Requirements
- alsa-utils 1.0.14 or higher
- alsa-headers 1.0.14 or higher
- alsa-lib 1.0.14 or higher
- Kernel 2.6.24 or higher
- Sound support configured as built-in
- ALSA support with all features configured as modules
- snd_usb_audio configured as a module (under card drivers)
[edit] Downloading
First of all, download the driver tarball.
or manually enter the command:
wget http://ccftp.creative.com/manualdn/Drivers/AVP/10530/0xE84AB36F/XFiDrv_Linux_US-1.18.tar.gz
[edit] Modifying and Patching
The following listed errors show up in /var/log/creative-installer.log when the installer fails with a Make error 2.
Decompress the internal bz2 file:
tar xvjf XFiDrv_Linux_US-1.18.tar.bz2
[edit] LinuxSys.c
Modify the LinuxSys driver file (drivers/src/ossrv/LinuxSys.c).
Remove the following line (~line 1581):
set_fs(fs);
Modify and Add the following lines from Vasko (~line 1558):
HRESULT
sysGetFileSize(CTVOID *This, CTDWORD *pdwSize, CTHANDLE hFile)
{
stFileHdl *pFileHdl = (stFileHdl *) hFile
to
HRESULT
sysGetFileSize(CTVOID *This, CTDWORD *pdwSize, CTHANDLE hFile)
{
stFileHdl *pFileHdl = (stFileHdl *) hFile; // Comments By Vasko
if(!pFileHdl)
{
printk(KERN_WARNING "sysGetFileSize: no file handle\n");
CTRETURN(E_INVALIDARG);
}
if(!pdwSize)
{
printk(KERN_WARNING "sysGetFileSize: no pointer to return value (pdwSize)\n");
CTRETURN(E_INVALIDARG);
}
Replace SA_SHIRQ with IRQF_SHARED (~line 648):
if (request_irq(phInterrupt->uIRQ, interrupt_callback, SA_SHIRQ, "x-fi", phInterrupt)) {
to
if (request_irq(phInterrupt->uIRQ, interrupt_callback, IRQF_SHARED, "x-fi", phInterrupt)) {
Add two include files (~line 33 and 37 respectively):
#include <linux/fs.h> //Included From Vasko
#include <asm-generic/fcntl.h> // otherwise, some MACROS are undefined
[edit] ctsound
The drivers/ctsound init script loads all the necessary modules into the kernel and alerts ALSA as to the card's presence. The modules, however, are called in wrong order. In the original version it looks like this:
drivers="ctossrv ctsfman emupia ct20xut ctexfifx cthwiut haxfi ctalsa"
It must be:
drivers="ctossrv emupia ctsfman haxfi ctalsa ct20xut ctexfifx cthwiut"
[edit] Baselayout 2 and OpenRC Users
An alternate ctsound file must be used. Download and unpack it. Then, replace drivers/ctsound with this file.
| FIXME: How? |
Thanks to the_root on the Gentoo Forums!
[edit] Kernel Source
If you choose to compile without Creative's ./installer you can skip this step.
Error:
make -C /lib/modules/2.6.24-16-generic/build SUBDIRS=/tmp/xfisrc/src/ossrv modules make[3]: Entering directory `/usr/src/linux-headers-2.6.24-16-generic' scripts/Makefile.build:46: *** CFLAGS was changed in "/tmp/xfisrc/src/ossrv/Makefile". Fix it to use EXTRA_CFLAGS. Stop. make[3]: *** [_module_/tmp/xfisrc/src/ossrv] Error 2 make[3]: Leaving directory `/usr/src/linux-headers-2.6.24-16-generic' make[2]: *** [module] Error 2 make[2]: Leaving directory `/opt/Creative/XFiDrv_Linux_US-1.18/drivers/src/ossrv' make[1]: *** [ctossrv] Error 2 make[1]: Leaving directory `/opt/Creative/XFiDrv_Linux_US-1.18/drivers'
Extremely hack fix: Edit
/usr/src/linux/scripts/Makefile.build
around line 46 and comment out the following lines:
#ifeq ($(KBUILD_NOPEDANTIC),)
#ifneq ("$(save-cflags)","$(CFLAGS)")
#$(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
#endif
#endif
I'm assuming that you'll want to either unfix this or re-emerge gentoo-sources before you recompile your kernel again.
[edit] Kernel 2.6.25-r5
Please format this article according to the guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article
Verify that the following kernel options are set:
Kernel hacking -> Enable unused/obsolete exported symbols[*]
General setup -> Choose SLAB allocator (SLAB)
Verify that the entire ALSA sound system is build as modules
Device Drivers -> Sound -> Sound card support -> ALSA [M]
Download this modified driver from here
[edit] Installing
[edit] Without Creative's ./installer
Remove all previous installation attempts by deleting:
rm /etc/init.d/ctsound && rm -R /etc/creative && rm -R /lib/modules/`uname -r`/kernel/drivers/ssound/
Reboot the machine or clear your environment with
env-update
Unpack the installation archive, "cd" to drivers directory, then execute the following:
./configure && make clean && make KBUILD_NOPEDANTIC=1 && make install
[edit] ctsound
After ctsound has been added to /etc/init.d/ctsound, it must be modified. Replace the entire contents of /etc/init.d/ctsound with the following:
#!/sbin/runscript
# ctsound: This shell script takes care of starting and stopping
# the Creative X-Fi soundcard driver.
# Author: Vasil Tsintsev
# Date: Apr 30 2008
depend() {
need localmount modules
before alsasound
after bootmisc modules isapnp coldplug hotplug ctsound
}
is_mods_installed() {
local KV=$(uname -r)
local MODPATH=/lib/modules/${KV}/kernel/drivers/ssound
if [ ! -d "${MODPATH}" ]; then
eerror "${MODPATH} does not exist. Please reinstall."
return 1
fi
}
start() {
is_mods_installed || return 1
local DRIVERS="ctossrv emupia ctsfman haxfi ctalsa ct20xut ctexfifx cthwiut"
ebegin "Loading X-Fi drivers "
local LOADED_MODULES="$(lsmod | sed -n -e 's/^\(snd[^ ]*\) .*/\1/p')"
local MODULE
for MODULE in ${LOADED_MODULES} ; do
rmmod "${MODULE}"
done
rmmod soundcore 2>/dev/null
rmmod gameport 2>/dev/null
if [ ! -c "/dev/emupia" ]; then
mknod /dev/emupia c 14 11;
chmod 666 /dev/emupia;
fi
if [ ! -c "/dev/x-fi" ]; then
mknod /dev/x-fi c 14 15;
chmod 666 /dev/x-fi;
fi
for MOD in ${DRIVERS}; do
modprobe ${MOD}
done
modprobe snd_usb_audio
modprobe snd-seq
eend 0
if [ -f /etc/creative/creative.state ]; then
ebegin "Restore Drv Default Mix Val"
sleep 10
alsactl -F -f /etc/creative/creative.state restore > /dev/null 2>&1 || :
rm -f /etc/creative/creative.state
eend 0
else
ebegin "Alsa control restore"
alsactl restore >/dev/null 2>&1 || :
eend 0
fi
}
stop() {
ebegin "Unloading X-Fi drivers"
local RMDRIVERS="ctalsa haxfi cthwiut ctexfifx ct20xut emupia ctsfman ctossrv"
/usr/sbin/alsactl store >/dev/null 2>&1 || :
for MOD in ${RMDRIVERS}; do
rmmod ${MOD}
done
eend 0
}
restart() {
ebegin "Reloading X-Fi drivers"
stop
sleep 5
start
eend 0
}
[edit] With Creative's ./installer
Simply run:
./installer
Be sure the "drivers" directory is repacked. This script automatically unpacks it.
[edit] Running
Unless you're willing to do a multi-card ALSA configuration, do the following:
rc-update add ctsound default (does not work on OpenRC, see seperate section)
Reboot, disable your onboard sound you've been using until now :)
The next time Linux loads up, ALSA will start with errors because it's trying to load modules for your now disabled on-board sound.
In the event ctsound didn't load itself:
/etc/init.d/ctsound start
And enjoy!
[edit] Re-Installing
The default /etc/init.d/ctsound script should rebuild all required modules from the modified source code stored in /opt/Creative/XFiDrv_Linux_US-1.18/ by itself when it finds that the modules don't exist in the running kernel's build. In the event that this fails, or the system is running Baselayout-2/OpenRC, cd to /opt/Creative/XFiDrv_Linux_US-1.18/drivers and follow directions for installing without Creative's ./installer.
[edit] Compatible X-Fi Models (add yours)
- X-Fi XtremeGamer
- X-Fi XtremeMusic
- X-Fi Platinum
[edit] Troubleshooting and Known Problems
[edit] Kernel Oops with Reiser FS
If you are using reiserfs you can expect kernel opps, it can be fixed, just open:
/usr/src/linux/fs/reiserfs/file.c , go to "const struct file_operations reiserfs_file_operations = {"
and add this line:
.llseek = generic_file_llseek,
it should look like this:
const struct file_operations reiserfs_file_operations = {
.llseek = generic_file_llseek,
.read = do_sync_read,
Source: Gentoo forums
[edit] Ctsound script kills other sound cards
Comment out the following lines in /etc/init.d/ctsound:
#local LOADED_MODULES="$(lsmod | sed -n -e 's/^\(snd[^ ]*\) .*/\1/p')"
#local MODULE
#for MODULE in ${LOADED_MODULES} ; do
# rmmod "${MODULE}"
#done
#rmmod soundcore 2>/dev/null
#rmmod gameport 2>/dev/null
[edit] Wine
Wine will not see the X-Fi as the default sound card unless it is the only one on the system. If more than one sound card is installed, Wine will need to be configured manually for ALSA card recognition. See this post for more information.
[edit] Alternatives
Open sound system drivers support some X-Fi models (1102:0005 or 1102:0009 pci id), but the support is limited (only stereo/96000 playback, recording may or may not work). On the other hand, these drivers typically don't present the risk of locking up the computer.

