views:

283

answers:

4

I'm attempting to write a very simple OS in ASM and C. (NASM assembler) I would like to access the sound card directly, with or without drivers. If I don't need drivers, how could I access and send a sample audio file to the sound card? (An example would be nice) If I do need drivers, is there anyway to interface them and call functions from the drivers? And how do I access and send a sample audio file to the sound card? (Another example would be nice)

+2  A: 

I hate to discourage you, but modern sound card drivers are extremely complicated, and as you probably know, OS-specific. This is one of the difficult challenges in OS development - driver support. It's not something that can be achieved with a simple code snippet.

In order to load a file, you need a file system. Have you implemented that yet? The fact that you used the "kernel" flag suggests that your OS is still in its infancy. I'm not sure I would want to put sound support into the kernel of an operating system.

That being said, there is a good emulator called Bochs that has Sound Blaster 16 emulation. And some really old documentation for how to program it. This might be your best bet. Accessing sound hardware was much easier back in the day.

Andy West
True. However, lots of soundcards / onboard chipsets are AC97 compatible. Programming these directly is easier than programming the SB16. With a bit of luck the OP has one of these chips..
Nils Pipenbrinck
Hmm.... I was actually thinking about the SB16. But, now that you mention it, AC97 is something that I recognize. However, I have no idea on how to program for that chipset... :P My onboard sound card, an Intel HDA based chipset, does support AC97, which is a perfect testing ground for this.
Jimmy Happy
+1  A: 

Of course you need a driver, and of course there's no easy way to interface with existing ones (there was some proposal for a unified OS-agnostic "Uniform Driver Interface" - but I don't think it got anywhere).

So, after you've written the code to read a file from your hard drive, you'll need to roll your own audio driver.

Now, I haven't done this in a while, so this may be outdated, but in the 90's you'd configure your sound card with a few 'out dx, al' (details varied across soundcards), and then setup DMA to send data from a memory buffer to your card. The card (or was it the DMA controller?) would fire off an interrupt when it reached the end of the buffer, which you'd use to fill the buffer with new data.

If your card has a working linux driver I'd start by looking at its code. Otherwise, you'll have to reverse engineer the windows driver, Soft-Ice's bpio (break on io port access) logging used to be good for that iirc.

Good luck.

foo
That "90's" type of interface is what I was thinking. I've heard people say that the newer sound cards can (probably) support SoundBlaster interfacing. The problem is - I have no idea how to get it to work! :P I am looking to only support the ALSA set of drivers. I will not go and attempt to disassemble or log the proprietary drivers themself since it just is a waste of time for one specific chipset. Maybe I could compile ALSA for my OS....? (I'm planning to implement ELF compatibility.)
Jimmy Happy
+1  A: 

Your best bet is probably to look at either the Linux or FreeBSD sound drivers and see what they do. You're not likely to get much better implementation documentation for any but the simplest sound card...

This is a hard problem. Be warned :-p

Steven Schlansker
I know. Too bad sound card makers don't focus on one implementation, and just run around making their own. :P I wonder if it's possible to port ALSA to my kernel...
Jimmy Happy
A: 

Here is a free open-sourced operating system written in all assembly. It is great reference for assembly kernel programming if you are new to it.

http://www.menuetos.net/index.htm

mrmadowl