⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sound.html

📁 我师兄自己写的操作系统
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<tt>sendmidicommand()</tt>is called whenever a complete midi command hasbeen written to the emulator. It should then<ul><li>send the given midi command to the midi hardware.</li></ul>It will only be called after the midi output has been opened. Note thatif at all possible it should not wait for the completion of the commandand instead indicate that the device is not ready during the executionof the command. This is to avoid delays in the program while it isgenerating midi output.<p>Description of the parameters:<ul><li><a NAME="smcdelta"></a><tt>delta</tt> 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.</li><li><a NAME="smdcommand"></a><tt>command</tt> is the midi command byte (sometimescalled status byte), in the usual range of 0x80..0xff. For more informationplease see the midi standard specification.</li><li><a NAME="smclength"></a><tt>length</tt> is the number of data bytes thatare contained in the data structure. This does <i>not</i> include the statusbyte which is not replicated in the data array. It can only be greaterthan 3 for SysEx messages (commands <tt>0xF0</tt> and <tt>0xF7</tt>)</li><li><a NAME="smcdata"></a><tt>data[]</tt> is the array of these data bytes,in the order they have in the standard MIDI specification.Note, it might be <tt>NULL</tt> if length==0.</li></ul><h4><a NAME="closemidioutput"></a><tt>int closemidioutput()</tt></h4><tt>closemidioutput()</tt> is called before shutting down Bochs or when theemulator gets the <tt>stop_output</tt> command through the emulator port.After this, no more output will be necessary until <tt>openmidioutput()</tt>is called again, but <tt>midiready()</tt> might still be called. It should<ul><li>Wait for all remaining messages to be completed</li><li>Reset and close the midi output device</li></ul><h4><a NAME="openwaveoutput"></a><tt>int openwaveoutput(char *<a href="#owodevice">device</a>)</tt></h4><tt>openwaveoutput()</tt> is called when the first wave output occurs,and only if the selected wavemode is 1. It should<ul><li>Open the given device, and prepare it for wave output</li></ul><i>or</i><ul><li>Store the device name so that the device can be opened in <tt>startplayback()</tt>.</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><tt>openwaveoutput()</tt> will typically be called once, whereas<tt>startplayback()</tt>is called for every new DMA transfer to the SB16 emulation. If feasible,it could be useful to open and/or lock the output device in<tt>startplayback()</tt> as opposed to <tt>openwaveoutput()</tt>to ensure that it can be used by other applications while Bochs doesn'tneed it.<p>However, many older applications don't use the auto-init DMAmode, which means that they start a new DMA transfer for every singleblock of output, which means usually for every 2048 bytes or so.Unfortunately there is no way of knowing whether the application willrestart an expired DMA transfer soon, so that in these cases the<tt>startwaveplayback</tt> function will be called very often, and itisn't a good idea to have it reopen the device every time.<p>The buffer when writing to the device should not be overly large.Usually about four buffers of 4096 bytes produce best results. Smallerbuffers could mean too much overhead, while larger buffers contributeto the fact that the actual output will always be late when the applicationtries to synchronize it with for example graphics.<p>The parameters are<ul><li><a NAME="owodevice"></a><tt>device</tt> is the wave device selected bythe user. It is strictly system-dependent. The value is that of the<tt>WAVE=device</tt>configuration option.</li></ul>Note that only one wave 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="startwaveplayback"></a><tt>int startwaveplayback(int<a href="#swpfreq">frequency</a>,int <a href="#swpbits">bits</a>, int<a href="#swpstereo">stereo</a>, int<a href="#swpcodec">format</a>)</tt></h4>This function is called whenever the application starts a new DMA transfer.It should<ul><li>Open the wave output device, unless <tt>openwaveoutput()</tt> did thatalready</li><li>Prepare the device for data and set the device parameters to those givenin the function call</li></ul>The parameters are:<ul><li><a NAME="swpfreq"></a><tt>frequency</tt> is the desired frequency of theoutput. Because of the capabities of the SB16, it can have any value between5000 and 44,100.</li><li><a NAME="swpbits"></a><tt>bits</tt> is either 8 or 16, denoting the resolutionof one sample.</li><li><a NAME="swpstereo"></a><tt>stereo</tt> is either 1 for stereo output,or 0 for mono output.</li><li><a NAME="swpcodec"></a><tt>format</tt> is a bit-coded value (see below).</li></ul><table><tr VALIGN=TOP><td NOSAVE>The bits in <tt>format</tt> are<table BORDER=2 ><tr><th>Bit number</th><th>Meaning</th></tr><tr><td>0 (LSB)</td><td>0: unsigned data<br>1: signed data</td></tr><tr><td>1..6</td><td>Type of codec</td></tr><tr><td>7</td><td>0: no reference byte<br>1: with reference byte</td></tr><tr><td>8..x</td><td>reserved (0)</td></tr></table></td><td WIDTH="5%"></td><td>The codec can be one of the following:<table BORDER=2><tr><th>Value</th><th>Meaning</th></tr><tr><td>0</td><td>PCM (raw data)</td></tr><tr><td>1</td><td>reserved</td></tr><tr><td>2</td><td>2-bit ADPCM<br>(Creative Labs format)</td></tr><tr><td>3</td><td>2.4-bit (3-bit) ADPCM<br>(Creative Labs format)</td></tr><tr><td>4</td><td>4-bit ADPCM<br>(Creative Labs format)</td></tr></table>Other codecs are not supported by the SB hardware. In fact, most applicationswill translate their data into raw data, so that in most cases the codecwill be zero.</td></tr></table>The number of bytes per sample can be calculated from this as <tt>(bits / 8) * (stereo + 1)</tt>.<h4><a NAME="waveready"></a><tt>int waveready()</tt></h4>This is called whenever the emulator has another output buffer readyand would like to pass it to the output class. This happens every<tt>BX_SOUND_OUTPUT_WAVEPACKETSIZE</tt> bytes, or whenever a DMA transferis done or aborted.<p>It should return whether the output device is ready for another bufferof <tt>BX_SOUND_OUTPUT_WAVEPACKETSIZE</tt> bytes. If <tt>BX_SOUND_OUTPUT_ERR</tt>is returned, the emulator waits about 1/(frequency * bytes per sample) seconds and then asks again. The DMA transfer is stalled during that time, butthe application keeps running, until the output device becomes ready.<p>As opposed to <tt>midiready(), waveready()</tt> will <i>not</i> becalled unless the device is open.<h4><a NAME="sendwavepacket"></a><tt>int sendwavepacket(int <a href="#swplength">length</a>,Bit8u <a href="#swpdata">data[]</a>)</tt></h4>This function is called whenever a data packet of at most <tt>BX_SB16_WAVEPACKETSIZE</tt>is ready at the SB16 emulator. It should then<ul><li>Send this wave packet to the wave hardware</li></ul>This function <i>has</i> to be synchronous, meaning that it <i>has</i>to return immediately, and <i>not</i> wait until the output is done. Also,this function might be called before the previous output is done. If yourhardware can't append the new output to the old one, you will have to implementthis yourself, or the output will be very chunky, with as much silencebetween the blocks as the blocks take to play. This is not what you want.Instead, <tt>waveready()</tt> should return <tt>BX_SOUND_OUTPUT_ERR</tt>until the device accepts another block of data.<p>Parameters:<ul><li><a NAME="swplength"></a><tt>length</tt> is the number of data bytes inthe data stream. It will never be larger than <tt>BX_SB16_WAVEPACKETSIZE</tt>.</li><li><a NAME="swpdata"></a><tt>data</tt> is the array of data bytes.</li></ul><p><br>The order of bytes in the data stream is the same as that in theWave file format:<br>&nbsp;<table BORDER=2><tr><th>Output type</th><th ALIGN=LEFT>Sequence of data bytes</th></tr><tr><td>8 bit mono</td><td>Sample 1; Sample 2; Sample 3; etc.</td></tr><tr><td>8 bit stereo</td><td>Sample 1, Channel 0; Sample 1, Channel 1; Sample 2, Channel 0; Sample2, Channel 1; etc.</td></tr><tr><td>16 bit mono</td><td>Sample 1, LSB; Sample 1, MSB; Sample 2, LSB; Sample 2, MSB; etc.</td></tr><tr><td>16 bit stereo</td><td>Sample 1, LSB, Channel 0; Sample 1, MSB, Channel 0; Sample 1, LSB,Channel 1; Sample 1, MSB, Channel 1; etc.</td></tr></table><p>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 theSB16 is not limited to this. For further information on the codecs andthe use of reference bytes please refer to the Creative Labs Sound BlasterProgrammer's Manual, which can be downloaded from the Creative Labs website.<h4><a NAME="stopwaveplayback"></a><tt>int stopwaveplayback()</tt></h4>This function is called at the end of a DMA transfer. It should<ul><li>Close the output device if it was opened by <tt>startwaveplayback()</tt>.</li>and it's not going to be opened soon. Which is almost impossible to tell.</ul><h4><a NAME="closewaveoutput"></a><tt>int closewaveoutput()</tt></h4>This function is called just before Bochs exits. It should<ul><li>Close the output device, if this hasn't been done by <tt>stopwaveplayback()</tt>.</li></ul>Typically, <tt>stopwaveplayback()</tt> will be called several times, whenevera DMA transfer is done, where <tt>closewaveoutput()</tt> will only be calledonce. However, in the future it might be possible that <tt>openwaveoutput()</tt>is called again, for example if the user chose to switch devices whileBochs was running. This is not supported at the moment, but might be inthe future.</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -