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.
You should also have a look at the exisiting files,
The main include file for a lowlevel sound driver is
Bochs Sourceforge.net site revealed that the version of Bochs I was using had a bug in the serial driver (a fix is apparently in the current CVS tree). So I rebooted Windows under Bochs in safe mode and disabled the serial device. That allowed me to continue with the Windows configuration. Here is version 0.5b, with some bugfixes. This version is to be included in Bochs 2.2. 2005-03-07: vruppert: Version 0.5a of the LGPL'd VGABios with Cirrus support for Bochs and Qemu is available now. It will be included in the first pre-release of Bochs 2.2. 2003-11-06: cbothamy: Version 0.4c is a bugfix release. 2003-11-04: cbothamy. Bosch Impact Drivers at Total Tools. 80+ stores nationwide & access to over 60,000 Tools online. Every Tool, Every Trade. Bochs is first emulator which allowed me to let Windows 98 SE run on my Windows 10 AMD Ryzen 5 3600 machine, others crash. Volker Ruppert - 2020-10-03 The release binaries are compiled with Cirrus support. For compiling with Cirrus support you can use the shortcut script for your platform (e.g.conf.linux or.conf.win32-cygwin). Download the latest Bochs installer for Windows. A Windows 98 CD-ROM or an ISO image of a CD Creating a Hard Disk Image First, run the “Disk Image Creation Tool” to create a hard disk image.
Additionally, every output driver will have an include file, which should beincluded on top of
To actually make the emulator use any specific driver as the default,
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
The maximum size of a wave data packet, the return values of the lowlevelfunctions, the structure for the PCM parameters and the default parameterset are also important for the sound driver development. They can be foundin the main include file
All lowlevel sound methods called from the device code have to return either
The following classes are involved with the sound lowlevel interface:
bx_soundmod_ctl_c is a pseudo device that is used toinitialize the sound drivers depending on the configuration. bx_sound_lowlevel_c is the base class of thelowlevel sound support. It has methods to return pointers to the objects forthe available services waveout, waveinand midiout. The base class returns NULL for all services. bx_sound_dummy_c is derived from bx_sound_lowlevel_c.It returns vaild pointers for all services, but the output classes are onlyimplemented as stubs and the wavein service returns silence.This 'dummy' driver is used whenever a OS specific driver does not implementall services. bx_soundlow_waveout_c, bx_soundlow_wavein_cand bx_soundlow_midiout_c are the base classes for theservices provided by the Bochs lowlevel sound support. Some methods are stubsand used by the 'dummy' sound driver, others are helper methods and used bythe OS specific implementations derived from these base classes. bx_sound_OS_c is derived from bx_sound_lowlevel_c.It returns vaild pointers for all services it implements for the selected OS (operating system / library) or NULL for services it doesnot implement. In the second case the Bochs sound init code falls back to the'dummy' driver.
The base class for sound lowlevel support is derived from the

The base class for wave output support is also derived from the
The constructor should
This table shows the waveout class methods, where are they called from andif a platform / library specific implementation is required.
Table 2-4. Waveout methods
MethodCalled fromPlatform codeopenwaveoutput()Sound init codeRequiredset_pcm_params()openwaveoutput() and sendwavepacket()Requiredsendwavepacket()Sound device emulationOptionalget_packetsize()Mixer threadOptionaloutput()Mixer threadRequiredclosewaveoutput()Sound device emulationOptionalregister_wave_callback()openwaveoutput() and sound device emulationOptionalunregister_wave_callback()class destructor and sound device emulationOptionalmixer_common()Mixer threadOptionalconvert_pcm_data()InternalNostart_mixer_thread()InternalNo2.9.5.1. int openwaveoutput(const char *wavedev)Set up the default PCM parameters for output.
Open the given device, and prepare it for wave output.
Register the callback function for the PCM buffer queue (
sendwavepacket()adds the output to the queue and the mixer thread gets it from there). Start the mixer thread, unless the sound library has it's own one (e.g. SDL).
The parameters are the following:
wavedev is the wave output device selected by the user.It is strictly system-dependent. Some sound libraries currently ignore thisvalue and use the default one instead. The value is that of the waveout=deviceconfiguration parameter of the sound bochsrc option.
Note that only one wave output device will be used at any one time.
This function should called from
Open the wave output device, unless
openwaveoutput() did thatalready. Prepare the device for data and set the device parameters to those givenin the function call.
The parameters are the following:
param is a pointer to a structure containing the set ofparameters required to set up a sound device for PCM output.
The members of the structure
samplerate is the desired frequency of theoutput. Because of the capabities of the soundcards, it can have any valuebetween 5000 and 48,000. bits is either 8 or 16, denoting the resolutionof one sample. channels is the number of channels (2 for stereo output,or 1 for mono output. format is a bit-coded value (see below). volume is the output volume to be used by the mixer code.The 16 bit value consists of two 8 bit values for each channel.
Table 2-5. format bits
Bit numberMeaning 0 (LSB)0: unsigned data
1: signed data
1..6 Type of codec (see below) 70: no reference byte
1: with reference byte
8..x reserved (0)Table 2-6. codecs
ValueMeaning 0 PCM (raw data) 1 reserved 2 2-bit ADPCM (Creative Labs format) 3 2.4-bit (3-bit) ADPCM (Creative Labs format) 4 4-bit ADPCM (Creative Labs format)Other codecs are not supported by the SB hardware. In fact, most applications willtranslate their data into raw data, so that in most cases the codec will be zero.
The number of bytes per sample can be calculated from this as (bits / 8) * channels.
2.9.5.3. int sendwavepacket(int length, Bit8u data[], bx_pcm_param_t *src_param)This function is called whenever a data packet of at most
Add this wave packet to the waveout buffer chain after converting to 16 bit signedlittle endian. If the samplerate has been changed
set_pcm_params()should be called to update the sound hardware settings.
Parameters:
length is the number of data bytes inthe data stream. It will never be larger than BX_SOUNDLOW_WAVEPACKETSIZE. data is the array of data bytes. src_param is a pointer to a structure containing the PCM parameters(see above).
The order of bytes in the data stream is the same as that in the Wave file format:
Table 2-7. wave output types
Output typeSequence of data bytes 8 bit mono Sample 1; Sample 2; Sample 3; etc. 8 bit stereo Sample 1, Channel 0; Sample 1, Channel 1; Sample 2, Channel 0; Sample 2, Channel 1; etc. 16 bit mono Sample 1, LSB; Sample 1, MSB; Sample 2, LSB; Sample 2, MSB; etc. 16 bit stereo Sample 1, LSB, Channel 0; Sample 1, MSB, Channel 0; Sample 1, LSB, Channel 1; Sample 1, MSB, Channel 1; etc.Typically 8 bit data will be unsigned with values from 0 to 255, and16 bit data will be signed with values from -32768 to 32767, although thesoundcard emulations are not limited to this.site.
2.9.5.4. int get_packetsize()This function is called from the mixer thread to retrieve the size of a wave datapacket based on the current samplerate. By default the packet size is big enoughto send output for 0.1 seconds. If the host sound driver / library uses a differentvalue, this value should be returned with this method.
2.9.5.5. int output(int length, Bit8u data[])This function is called from the mixer thread to send the mixed PCM output tothe host sound hardware.
Parameters:
length is the number of data bytes inthe data stream. It will never be larger than the value returned from get_packetsize. data is the array of data bytes.

This function is currently only called from the soundcard emulation if the 'file'driver is used. This makes the runtime change of the output file possible.By default this method does nothing and the wave output device is closed in thedestructor of the specific class.
2.9.5.7. int register_wave_callback(void *arg, get_wave_cb_t wd_cb)This function is called from
Parameters:
arg is the pointer to the device emulation object. wd_cb is the pointer to a static function that returnswave data from the device emulation. This function is usually called from the mixer_common() method.

This function is usually called from the destructor of the sound emulationdevice to unregister it's registered function to poll PCM data. If thedriver / library doesn't use the default mixer thread, a specific implementationof this method my be required.
Parameter:
callback_id is the ID of the function to unregister.
This is the main wave output mixing function. It is called from the mixerthread, it polls the wave data from all registered sources and it mixes thedata using a simple algorithm (addition and clipping). The return valueindicates whether or not wave data is available for output.
Parameters:
buffer is the output buffer for the wave data. len is the maximum length of the output buffer.
Drivers Boost
This function converts the PCM data sent from the sound device emulation to the16 bit stereo signed little endian format. It should be called in
Parameters:
src is the buffer containing data sent from the sound emulation. srcsize is the amount of wave data to be converted. dst is the buffer for the converted wave data. dstsize is the size of the destination buffer. param is a pointer to the struture containing the formatparameters of the source data.
This function starts the mixer thread and it should be called in
Drivers Books
bx_soundlow_wavein_cThe base class for wave input support is also derived from the
The constructor of the base class only initializes the timer ID. OS specificimplementations should initialize other required members here.
The destructor of the base class only calls
Open the given device, and prepare it for wave input
Store the device name so that the device can be opened in
startwaverecord().
In addition to this the record handler value should be stored and the record timershould be registered. This is the definition of record handler callback function:
The parameters are the following:
device is the wave device selected by the user. It isstrictly system-dependent. The value is that of the wavein=deviceconfiguration parameter of the sound bochsrc option. rh is a pointer to the record handler method of the soundemulation. When sound recording is active, this handler is called periodicly tonotify the sound emulation about newly available data.
Note that only one wave input device will be used at any one time.
This method receives a pointer to the required PCM parameters (samplerate,data format) as the argument and it should set up the input device for recording,calculate the size of the recording packet for 0.1 second and start the recordtimer.
2.9.6.3. int getwavepacket(int length, Bit8u data[])This method is called from the record handler method of the sound emulation deviceto retrieve the recorded wave data packet.
2.9.6.4. int stopwaverecord()This method is called to stop the wave recording. It deactivates the timer thatcalls the method to perform the recording.
2.9.7. The midiout base class bx_soundlow_midiout_cThe base class for MIDI output support is also derived from the
OS specific implementations should initialize required members in the constructor.
The destructor of the base class only calls
openmidioutput() is called when the first midi output starts.It is only called if the midi output to the driver is active (midimode 1). It shouldprepare the given MIDI hardware for receiving midi commands.
Description of the parameters:
mididev is a system-dependent variable.The value is that of the midiout=deviceconfiguration parameter of the sound bochsrc option. Note that only one midi output device will be used at any one time.
devicemay not have the same value throughout one session, but it will be closedbefore it is changed.
Return values:
BX_SOUNDLOW_OK if the midi output device is ready. BX_SOUNDLOW_ERR if it isn't ready.

Description of the parameters:
delta is the number of delta ticks thathave passed since the last command has been issued. It is always zero forthe first command. There are 24 delta ticks per quarter, and 120 quartersper minute, thus 48 delta ticks per second. command is the midi command byte (sometimescalled status byte), in the usual range of 0x80..0xff. For more informationplease see the midi standard specification. length is the number of data bytes thatare contained in the data structure. This does not include the statusbyte which is not replicated in the data array. It can only be greaterthan 3 for SysEx messages (commands 0xF0 and 0xF7) data[] is the array of these data bytes,in the order they have in the standard MIDI specification.Note, it might be NULL if length0.
Drivers Boost 8
2.9.7.4. int closemidioutput()Drivers Boos
Wait for all remaining messages to be completed
Reset and close the midi output device