📄 sound.html
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Author" content="Josef Drexler"> <meta name="Description" content="A brief description of how the portable part of the sound subsystem of Bochs works, and how it should or could be ported to other platforms than those already supported."> <title>Bochs Sound Blaster 16 Emulation</title></head><body text="#000000" bgcolor="#ECECEC" link="#3333CC" vlink="#666666"><center><h1>Sound Blaster 16 emulation</h1></center><h1>About SB16 emulation for bochs</h1>This is Sound Blaster 16 emulation for bochs, written and donated byJosef Drexler.You can see also check out his related web page<a href="http://publish.uwo.ca/~jdrexler/bochs/">here</a>. The entire set of his SB16 patches have been integrated intobochs, so you will not need to do so.<p>It has been tested with several soundcards and versions of Linux. Please give<a href="mailto:jdrexler@julian.uwo.ca">Josef</a>feedback on whether is does or doesn't workon your combination of software and hardware.<h3>How much does work?</h3>Right now, MPU401 emulation is next to perfect. It supports UARTand SBMIDImode, because the SB16's MPU401 ports can't do anything else as well.<p>The digital audio basically works, the emulation is too slow for fluentoutput unless the application doesn't do much in the background (or theforeground, really). The sound tends to looping or crackle on slowercomputer, but the emulation appears to be correct. Even a MODplayer works, although only for lower sampling speeds.<p>Also, the MIDI data running through the MPU401 ports can be writteninto a SMF, that is the standard midi file. The wave outputcan be written into a VOC file, which has a format defined byCreative Labs. This file format can be converted to WAV bysox for example.<h3>Output to a sound card</h3>Output is supported on Linux and Windows 95 at the moment.<p>On Linux, the output goes to any file or device. If you have awavetable synthesizer, midi can go to /dev/midi00, otherwise you may needa midi interpreter. For example, the midid program from theDosEmu project would work. Wave output should go to /dev/dsp. These devices are assumed to be OSS devices, if they're notsome of the ioctl's might fail.<p>On Windows, midi and output goes to the midi mapper and the wave mapper,respectively. A future version might have selectable output devices.<hr><h1>Installation on Linux</h1><h3>Prerequisites</h3>A wavetable synthesizer on /dev/midi00 and a working /dev/dsp if you want real time music and sound, otherwise output to midi and wave files is also possible. Optionally, you can use a software midi interpreter, such as the midid program from the DosEmu project instead of /dev/midi00. <h3>Configuring bochs</h3><pre>There are a few values in config.h that are relevant to the sound functions.Edit config.h after running configure, but before compiling.BX_USE_SB16_SMF should be 1 unless you intend to have several sound cardsrunning at the same time.BX_USE_SOUND_VIRTUAL can be 0 or 1, and determines whether the output classuses virtual functions or not. The former is more versatile and allows toselect the class at runtime (not supported at the moment), while the latteris slightly faster.BX_SOUND_OUTPUT_C is the name of the class used for output. The default isto have no output functions, so you need to change this if you want any sound.The following are supported at the moment: bx_sound_linux_c for output to /dev/dsp and /dev/midi00 on Linux (and maybe other OSes that use the OSS driver) bx_sound_windows_c for output to the midi and wave mapper of Windows 3.1 and higher. bx_sound_output_c for no output at all.Setup the SB16 emulation in your .bochsrc, according to instructionsin that file.</pre><hr><h1>Runtime configuration</h1>The source for the SB16CTRL program that is used to modifythe runtime behaviour of the SB16 emulator is included in<b>misc/sb16</b>. You can compile it or download the<a href="http://publish.uwo.ca/~jdrexler/bochs/">executable</a>.<p><pre>misc/sb16/ contains a C program that can be run inside the emulator, and theexecutable for DOS. It currently supports the following commands:-i <number>: shows the selected emulator info string, e.g. sb16ctrl -i 3 to show how many patch translations are active-t <six numbers>: loads a translation into the translation table. The numbers are: OldBankMSB,OldBankLSB,OldProgram,NewBankMSB,NewBankLSB,NewProgram All values can be 0..127 or 255. 255 for Old values means "match any" and for New values means "don't change", e.g. sb16ctrl -t 255,255,0,255,255,32 to change patch 0 (Piano) to patch 32 (Acoustic Bass)-r: Reset the patch translation table e.g. sb16ctrl -r-m <some numbers>: Upload the given numbers to the midi output device. Note that it should be a complete midi message, and also that it is subject to patch translation. e.g. sb16ctrl -m 0x80,64,0 to send a note-off message to channel 0.-f <filename>: Reads in a file and executes the commands in it. These have the same format as the above commands, except that they don't have the dash "-" in front of them. Comment lines are supported and start with a hash sign "#".-h: Show a brief summary of the commands.All numbers can be valid parameters to the strtol() function, so hex andoctal notation is fine. They have to be delimited by either commas "," orslashes "/", spaces are not allowed.The command line can have any number of commands. However, if none are given,"-f -" is assumed, which means commands are taken from stdin.</pre><hr><h1>Features planned for the future</h1><ul><li>Ports to more OS's, but I can't do this myself<li>Finishing the OPL3 FM emulation by translating the music to midi data</ul><hr><h1>Description of the sound output classes</h1>This file is intended for programmers who would like to port the soundoutput routines to their platform. It gives a short outline what serviceshave to be provided.<p>You should also have a look at the exisiting files, <tt>SOUNDLNX.CC</tt>for Linux and <tt>SOUNDWIN.CC</tt> for Windows and their respectiveheader files to get an idea about how these things <i>really</i> work.<h2>Overview</h2><h3>Files</h3>The main include file is <tt>"bochs.h"</tt>. It has all definitions for the system-independent functions that the SB16 emulation uses, whichare defined in <tt>"sb16.h"</tt>.<p>Additionally, every output driver will have an include file, whichshould be included at the end of <tt>sb16.h</tt> to allow the emulatorto use that driver.<p>To actually make the emulator use any specific driver, <tt>BX_SOUND_OUTPUT_C</tt> has to be set to the name of the respectiveoutput class.<p>Note that if your class contains any system-specific statements,include-files and so on, you should enclose both the include-file andthe CC-file in an <tt>#if defined(<i>OS-define</i>)</tt> construct.Also don't forget to add your file to the object list in<tt>iodev/Makefile</tt> and <tt>iodev/Makefile.in</tt>.<h3>Classes</h3>The following classes are involved with the SB16 emulation:<ul><li><tt>bx_sb16_c</tt> is the class containing the emulator itself, thatis the part acting on port accesses by the application, handling theDMA transfers and so on. It also prepares the data for the outputclasses.</li><li><tt>bx_sound_output_c</tt> is the base output class. It has allthe methods used by the emulator, but only as stubs and does notactually produce any output. These methods are then called bythe emulator whenever output is necessary.</li><li><tt>bx_sound_<i>OS</i>_c</tt> is derived from <tt>bx_sound_output_c</tt>. It contains the code to generate output for the <tt><i>OS</i></tt> operating system. It is necessary to override allthe methods defined in the base class, unless virtual functionsare used. Note that this should remain an option, so try tooverride all methods, even if only as stubs. They should bedeclared <tt>virtual</tt> if and only if <tt>BX_USE_SOUND_VIRTUAL</tt>is defined, just as in the examples. The constructor should call the inherited constructoras usual, even though the current constructor does not doanything yet.</li></ul><h3>Methods</h3>The following are the methods that the output class has to override.All but constructor and destructor have to return either<tt>BX_SOUND_OUTPUT_OK</tt> (0) if the function was successful, or <tt>BX_SOUND_OUTPUT_ERR</tt> (1) if not. If any of the initializationfunctions fail, output to that device is disabled until the emulatoris restarted.<p>Constructor and destructor:<ul><li><tt><a href="#constructor">bx_sound_<i>OS</i>_c(bx_sb16_c *sb16)</a></tt></li><li><tt><a href="#destructor">~bx_sound_<i>OS</i>_c()</a></tt></li></ul><p>Midi functions:<ul><li><tt><a href="#openmidioutput">int openmidioutput(char *device)</a></tt></li><li><tt><a href="#sendmidicommand">int sendmidicommand(int delta,int command, int length, Bit8u data[])</a></tt></li><li><tt><a href="#midiready">int midiready()</a></tt></li><li><tt><a href="#closemidioutput">int closemidioutput()</a></tt></li></ul>Wave functions:<ul><li><tt><a href="#openwaveoutput">int openwaveoutput(char *device)</a></tt></li><li><tt><a href="#startwaveplayback">int startwaveplayback(int frequency,int bits, int stereo, int format)</a></tt></li><li><tt><a href="#waveready">int waveready()</a></tt></li><li><tt><a href="#sendwavepacket">int sendwavepacket(int length, Bit8u data[])</a></tt></li><li><tt><a href="#stopwaveplayback">int stopwaveplayback()</a></tt></li><li><tt><a href="#closewaveoutput">int closewaveoutput()</a></tt></li></ul><hr SIZE=4 WIDTH="100%"><h2>Details</h2><h3>Methods</h3><h4><a NAME="constructor"></a><tt>bx_sound_<i>OS</i>_c(bx_sb16_c*<a href="#conssb16">sb16</a>)</tt></h4>The emulator instantiates the class at the initialization of Bochs.<p>Description of the parameter:<ul><li><a NAME="conssb16"></a><tt>sb16</tt> is a pointer to the emulator class. This pointer can then be usedto access for example the <tt>writelog</tt> function to generatesound-related log messages. Apart from that, no access to the emulatorshould be necessary.</ul>The constructor should <i>not</i> allocate the output devices. This shouldn't be done until the actual outputoccurs; in either <tt>initmidioutput()</tt> or <tt>initwaveoutput()</tt>.Otherwise it would be impossible to have two copies of Bochs running concurrently (if anybody ever wants to do this).</li></ul><h4><a NAME="destructor"></a><tt>~bx_sound_<i>OS</i>_c()</tt></h4>The instance is destroyed just before Bochs ends.<h4><a NAME="openmidioutput"></a><tt>int openmidioutput(char *<a href="#omodevice">device</a>)</tt></h4><tt>openmidioutput()</tt> is called when the first midi output starts.It is only called if the midi output mode is 1 (midimode 1). It should<ul><li>prepare the given MIDI hardware for receiving midi commands.</li></ul><tt>openmidioutput()</tt> will always be called before <tt>openwaveoutput()</tt>,and <tt>closemidioutput()</tt>will always be called before <tt>closewaveoutput()</tt>,but not in all cases will both functions be called.<p>Description of the parameters:<ul><li><a NAME="omodevice"></a><tt>device</tt> is a system-dependent variable.It contains the value of the <tt>MIDI=device</tt> configuration option.</li></ul>Note that only one midi output device will be used at any one time.<tt>device</tt>may not have the same value throughout one session, but it will be closedbefore it is changed.<h4><a name="midiready"></a><tt>int midiready()</tt></h4><tt>midiready()</tt> is called whenever the applications asks if themidi queue can accept more data. <p>Return values:<ul><li><tt>BX_SOUND_OUTPUT_OK</tt> if the midi output device is ready</li><li><tt>BX_SOUND_OUTPUT_ERR</tt> if it isn't ready</ul><b>Note: </b><tt>midiready()</tt> will be called a few times<i>before</i> the device is opened. If this is the case, it shouldalways report that it is ready, otherwise the application (not Bochs)will hang.<h4><a NAME="sendmidicommand"></a><tt>int sendmidicommand(int <a href="#smcdelta">delta</a>,int <a href="#smdcommand">command</a>, int <a href="#smclength">length</a>,Bit8u <a href="#smcdata">data</a>[])</tt></h4>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -