home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / soundx / sound.doc < prev    next >
Encoding:
Text File  |  1996-11-20  |  15.0 KB  |  602 lines

  1.  
  2.    Copyright 1993 by Peter Sprenger   Pete@amber.dinoco.de
  3.                      Muenchener Str.6
  4.                      50170 Kerpen
  5.                      Germany
  6.  
  7.    Permission to use, copy, modify, and distribute this
  8.    software and its documentation for any purpose and without
  9.    fee is hereby granted, provided that the above copyright
  10.    notice appear in all copies.  The author Peter Sprenger
  11.    makes no representations about the suitability of this
  12.    software for any purpose.  It is provided "as is" without
  13.    express or implied warranty.
  14.  
  15.  
  16.  
  17.  
  18. Welcome to SoundX!
  19.  
  20. SoundX is a library for making fm sound and playing samples on Adlib/
  21. Soundblaster cards. The following features are implemented:
  22.  
  23.  
  24. 1. Recognition of soundcard. It recognizes none,adlib,sb,sbpro cards.
  25.    It will set the FM ports correctly. It search for enironment string,
  26.    but when none found it finds the correct addresses, intr and dma channel.
  27.    It will test for DSP of course.
  28.  
  29. 2. Digi play routines. It will play 8bit or adpcm samples. You will only
  30.    have to give a far ptr or a normalized address in the 16mbyte space.
  31.    It works with an interrupt routine, which handles automagically the
  32.    dma transfer over 64k pages. Just say to play the sample and it works
  33.    fully transparent in the background. The adcmp modes are not tested
  34.    yet, they are implemented and should work accordingly to my docs.
  35.  
  36. 3. Sample routines. It works the same like 2. They are not tested.
  37.    Programmed according the Creative Labs docs.
  38.  
  39. 4. FM support. Routines to set the cells of the FM chips. Just give a ptr
  40.    to the 16 byte intrument description (in fact only 11 byte) and a channel
  41.    nr and it will set the characteristics. Also implemented routines to
  42.    set pitch (note) and to play the voice. The parameters are similiar
  43.    to the original SBK routines. Also switch to rythm mode and vice versa
  44.    implemented.
  45.  
  46. 5. VOC play routines. Just give a ptr to the buffer and the voc will
  47.    be played. Support of silence blocks and loops is implemented.
  48.  
  49.  
  50. 6. Mixer routines. Reset the mixer, set input source, set output
  51.    mode. Set or get the volume of various registers ( not tested yet,
  52.    since I have a sb 2.0, not a pro).
  53.  
  54. 7. Midi interrupt routines ( not sure, because I have no midi cable and
  55.    no midi hardware to test).
  56.  
  57. 8. I included a c program voclook.c, that is capable of analyzing voc
  58.    files with detail description.
  59.  
  60.  
  61. What is missing? 
  62.  
  63. 1. Recognition of GUS.
  64.  
  65. 2. Midi and CMF background player for the SoundX FM routines.
  66.  
  67.  
  68.  
  69. Please send my your bug reports, bug fixes and suggestions. My e-mail
  70. address is:
  71.                  Pete@amber.dinoco.de
  72.  
  73.  
  74. Why I made this library: I was myself in a search of a good library
  75. for soundblaster programming. What I encountered was the SBF, that
  76. was a nice idea but written in a such a hurry, that it was still
  77. useless. I has still bugs, too. Some other packages looked
  78. interesting but are quite expensive. I just bought the original SBK
  79. from Creative Labs and was disappointed. It was expensive and bad!
  80. In their design I lost control of Timer 0, that I needed for my other
  81. programming.
  82. So I decided to make a good freeware soundblaster bibleothek. Up to
  83. now I spent about 200 hours working time in this project. It is my
  84. hope that their will be other people who make freeware that can be
  85. used. If every programmer would spend about 100 hours for freeware in
  86. the lifetime, not everybody had to reinvent the wheel again. Look at
  87. the guys from GNU and OSF they are doing a great job!
  88.  
  89. If you can use this routines use them! There must be non false shame.
  90. I wrote this stuff that not everybody has to write his own routines.
  91. But it would be nice, that when you make something commercial with my
  92. routines, that you send me a copy of your project or send me some bucks,
  93. just enough for pizza and coke to support my night programming sessions.
  94. If you send me nothing, ok. But USE the stuff, if you can need it!
  95.  
  96. Have fun with SoundX,
  97.  
  98.             Pete
  99.  
  100. Germany, 27-Jun-93
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. --------------------  Documentation  ----------------------------
  108.  
  109.  
  110.  
  111.  
  112.  
  113. 1. -----------------  FM routines  ------------------------------
  114.  
  115.  
  116.  
  117.  
  118. All of the FM routines will only work, if fm_addr is set to the correct
  119. FM address. The vriable fm_addr is set in the SB_Setup() call.
  120. Further details will follow.
  121.  
  122.  
  123. void FM_Write(WORD data);
  124.  
  125. With FM_Write() you can write data to the FM chip. The high byte of
  126. the argument is the register number to write into, the low byte is
  127. the data that will be written in the FM register. E.g.
  128. FM_Write(0x1020) will write a 0x20 into register 1.
  129.  
  130.  
  131. void FM_Reset();
  132.  
  133.   This routine will reset the FM chip (both if you have a sbpro).
  134.  
  135.  
  136. BYTE FM_Status();
  137.  
  138.   This function returns the value of the status register of the FM
  139.   chip.
  140.  
  141.  
  142. void FM_SetChan(fm_chan channel);
  143.  
  144.   This routine lets the programmer choose which FM chips are used by
  145.   calling the FM routines. Valid arguments are left,right,both.
  146.   FM_SetChan sets the correct value of fm_addr. All calls will set
  147.   "both" if you have an adlib or sb 2.0 card.
  148.  
  149.  
  150. void FM_SetVoice(BYTE voice,BYTE *ins);
  151.  
  152.   FM_SetVoice will load an instrument definition in the FM cells
  153.   corresponding to the voice parameter. Voice is valid in the range of
  154.   0-8. The 2nd parameter of this call is a pointer to an 11 byte array
  155.   (officially an instrument definition is 16 byte long, but only 11 are
  156.   used).
  157.  
  158.  
  159. void FM_SetNote(BYTE voice,BYTE note);
  160.  
  161.   Here you can set the pitch (freq.) of the voice. This routine
  162.   acceptsa MIDI note as note paremeter.
  163.  
  164.  
  165. void FM_SetVol(BYTE voice,BYTE vol);
  166.  
  167.   Here you can set the volume of a voice. The range of vol is from 0 to
  168.   0x7f. From there an turnaround occurs.
  169.  
  170.  
  171. void FM_KeyOn(BYTE voice);
  172.  
  173.   This call will play the note.
  174.  
  175.  
  176. void FM_KeyOff(BYTE voice);
  177.  
  178.   FM_KeyOff() shuts off the voice.
  179.  
  180.  
  181.   The above definitions are similiar to the low level calls of the SBK
  182.   from Creative Labs.
  183.  
  184.   sbfd_not_on(0,60,0x40) -> FM_SetNote(0,60);FM_SetVol(0,0x40);FM_KeyOn(0);
  185.  
  186.  
  187. void FM_RythmMode(BYTE bool);
  188.  
  189.   Here you can enable the rythm instruments, when you supply a logical
  190.   TRUE as argument. Else you enable melodic mode.
  191.  
  192.  
  193. void FM_RythmOn(BYTE inst);
  194.  
  195.   With this call you can play rythm instruments. You can choose the
  196.   instruments with or'ing the following defintions together.
  197.  
  198.   FM_HIHAT  
  199.   FM_TOPCYM 
  200.   FM_TOMTOM 
  201.   FM_SNARE  
  202.   FM_BASS   
  203.  
  204.   E.g. FM_RythmOn(FM_HIHAT|FM_SNARE);
  205.  
  206.  
  207. void FM_RythmOff(BYTE inst);
  208.  
  209.   This procedures stops playing the selected rythm instrument. The same
  210.   argument as FM_RythmOn().
  211.  
  212.  
  213.  
  214.  
  215. 2. -----------------  Mixer routines  ---------------------------
  216.  
  217.  
  218.  
  219.  
  220. void MIX_Reset();
  221.  
  222.   With this call you reset the mixer.
  223.  
  224.  
  225. void MIX_SetInput(BYTE opt);
  226.  
  227.   Here you can set the input source and the input filter. You can
  228.   select it by or'ing the input source and input filter definitions.
  229.   Input source:
  230.  
  231.   MIX_IN_MICRO 
  232.   MIX_IN_CD 
  233.   MIX_IN_MICRO2
  234.   MIX_IN_LINE 
  235.  
  236.   Input filter:
  237.  
  238.   MIX_LOW_FILT 
  239.   MIX_HIGH_FILT
  240.   MIX_NO_FILT
  241.  
  242.   E.g. MIX_SetInput(MIX_IN_CD|MIX_NO_FILT);
  243.  
  244.  
  245. void MIX_SetOutput(BYTE opt);
  246.  
  247.   You can select stereo or mono, or to bypass the output filter.
  248.   definitions:
  249.  
  250.   MIX_BYPASS_OUT_FILT
  251.   MIX_STEREO 
  252.   MIX_MONO
  253.  
  254.   E.g. MIX_SetOuput(MIX_STEREO);
  255.  
  256.  
  257. void MIX_SetVolume(BYTE reg,BYTE left,BYTE right);
  258.  
  259.   With this routine you can set the volume of the left or right
  260.   channel. For the arguments left and right only values in range from
  261.   0 to 15 are used. For the 1st parameter the following values are
  262.   sensible:
  263.  
  264.   MIX_VOICE_VOL
  265.   MIX_MICRO_VOL
  266.   MIX_INPUT
  267.   MIX_OUTPUT
  268.   MIX_MASTER_VOL 
  269.   MIX_FM_VOL
  270.   MIX_CD_VOL
  271.   MIX_LINE_IN_VOL
  272.  
  273. void MIX_GetVolume(BYTE reg,BYTE *left,BYTE *right);
  274.  
  275.   MIX_GetVolume() returns you the left and right volume of the
  276.   specified mixer register. The register definition is the same as in
  277.   MIX_SetVolume(). The function returns the volumes in the variables
  278.   which pointers are defined as the 2nd and 3rd argument.
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. 3. -----------------  MIDI routines  ----------------------------
  286.  
  287.  
  288.  
  289. Sorry none of the MIDI routines are tested yet, because I own no MIDI
  290. hardware.
  291.  
  292.  
  293. void MIDI_Write(BYTE data);
  294.  
  295.   Writes the argument to the MIDI port.
  296.  
  297.  
  298. void MIDI_WriteBuf(BYTE *data,int length);
  299.  
  300.   Supply a pointer to a byte array with the data that should be send.
  301.   The 2nd parameter is the number of bytes that will be send to the
  302.   MIDI port. This routine will wait until all is sent, because the
  303.   soundblaster DSP supports no interrupt MIDI writing, only reading.
  304.  
  305.  
  306. WORD  MIDI_ByteAvail();
  307.  
  308.   This function returns the number of bytes that are available in the
  309.   MIDI read buffer.
  310.  
  311.  
  312. BYTE MIDI_GetByte();
  313.  
  314.   With this routine you get one byte out of the read buffer.
  315.  
  316.  
  317. void MIDI_ReadBuf(WORD count,BYTE *buffer);
  318.  
  319.   MIDI_ReadBuf() will get "count" bytes out of the read buffer and
  320.   will store it in "buffer" (2nd argument).
  321.  
  322.  
  323. int MIDI_Init(BYTE mode,WORD buflen);
  324.  
  325.   This will enable MIDI interrupt mode. The 1st parameter specifies
  326.   normal interrupt mode or UART mode:
  327.  
  328.   DSP_MIDI_READI
  329.   DSP_MIDI_UART
  330.  
  331.   The 2nd parameter is the length of the read buffer.
  332.  
  333.   Only in UART mode you can read and write to the MIDI ports
  334.   simultaneously. But BEWARE, if you enter UART mode, you have to use
  335.   DSP_Write(midi_byte) to write to the MIDI port. All data sent to
  336.   the DSP is sent to the MIDI port. To resume to normal action you
  337.   must use a DSP_Reset(). MIDI_Remove() will do that for you.
  338.  
  339.  
  340. void MIDI_Remove();
  341.  
  342.   This procedure will leave the MIDI modes and deallocate the buffer.
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349. 4. -----------------  DSP routines  -----------------------------
  350.  
  351.  
  352.  
  353. WARNING: Most function will only work after a DSP reset. This will
  354. already be done in SB_Setup().
  355.  
  356.  
  357. int DSP_Reset();
  358.  
  359.   This resets the DSP.
  360.  
  361.  
  362. BYTE DSP_Read();
  363.  
  364.   This function returns a byte from the DSP.
  365.  
  366.  
  367. void DSP_Write(BYTE output);
  368.  
  369.   DSP_Write() writes byte data to the DSP.
  370.  
  371.  
  372. WORD DSP_Get_Version();
  373.  
  374.   This function returns the version number of the DSP. The major
  375.   number is in the high byte, the minor number in the low.
  376.  
  377.  
  378. DSP_Write(DSP_SPKR_ON);
  379.  
  380.   Use this to turn the DSP speaker on.
  381.  
  382.  
  383. DSP_Write(DSP_SPKR_OFF);
  384.  
  385.   Andto turn the DSP speaker off.
  386.  
  387.  
  388.  
  389.  
  390. 5. -----------------  Sample routines  --------------------------
  391.  
  392.  
  393.  
  394.  
  395. WARNING: Most functions will only work, when correct IO address, the
  396. interrupt number and the dma channel is set. This will already be
  397. done in SB_Setup().
  398.  
  399. To avoid clicking, the speaker will be turned on ONLY in SB_Setup().
  400. If you shut it off during operation, you have to shut it on by
  401. yourself.
  402.  
  403.  
  404.  
  405. void SetRate(DWORD rate);
  406.  
  407.   Here you can set the sample rate of the DSP. Give the sample rate
  408.   as an unsigned integer.
  409.  
  410.  
  411. void SetHighRate(DWORD rate);
  412.  
  413.   If you want to use high speed mode (over 23khz output), use
  414.   SetHighRate() instead of SetRate().
  415.  
  416.  
  417. int Play(char *data,playmode mode,DWORD length);
  418.  
  419.   This routine will play a sample out of memory with dma. The 1st
  420.   parameter is a far ptr to the data. The 2nd parameter specifies how
  421.   the sample is played:
  422.  
  423.   bit8
  424.   bit4
  425.   bit26
  426.   bit2
  427.   high
  428.  
  429.   The normal mode is "bit8" (unpacked). The modes
  430.   "bit4","bit26","bit2" are adpcm modes. If you supply "high", high
  431.   speed mode with unpacked data (8-bit) is used.
  432.   The 3rd parameter is the length of the sample.
  433.   To set the correct sample rate use SetRate() or SetHighRate().
  434.  
  435.   If you call Play before the end of a previous sample, the previous
  436.   one will be interrupted, and the new one is played.
  437.  
  438. int PlayXMS(DWORD data,playmode mode,DWORD length);
  439.  
  440.   Nearly the same as Play(), but you can specifiy the sample address
  441.   as an unsigned long word (only 24 bits used), to play samples that
  442.   are in memory >1mbyte.
  443.  
  444.  
  445. int Sample(char *data,playmode mode,DWORD length);
  446.  
  447.   Sample() will record "Length" bytes of an input source into memory
  448.   with dma. The modes taht are available are:
  449.  
  450.   bit8
  451.   high
  452.  
  453.  
  454. DSP_Write(DSP_HALT_DMA);
  455.  
  456.   This call will halt playing a dma sample.
  457.  
  458.  
  459. DSP_Write(DSP_CONT_DMA);
  460.  
  461.   And this will continue playing.
  462.  
  463.  
  464.  
  465.  
  466.  
  467. 6. -----------------  voc routines  -----------------------------
  468.  
  469.  
  470.  
  471. WARNING: Most functions will only work, when correct IO address, the
  472. interrupt number and the dma channel is set. This will already be
  473. done in SB_Setup().
  474.  
  475. To avoid clicking, the speaker will be turned on ONLY in SB_Setup().
  476. If you shut it off during operation, you have to shut it on by
  477. yourself.
  478.  
  479.  
  480.  
  481. int VocPlay(char far *data);
  482.  
  483.   This procedure will play a whole voc file that lies at the memory<
  484.   address "adr".
  485.  
  486.  
  487. void VocStop();
  488.  
  489.   This will stop playing the voc file.
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496. 7. -----------------  SB setup routines  ------------------------
  497.  
  498.  
  499.  
  500.  
  501. int SB_Setup();
  502.  
  503.   SB_Setup() does all what is necessary to startup work with SoundX.
  504.   It resets the DSP. It scans for the soundblaster environment string
  505.   and tests the settings. If they are not correct it will scan all
  506.   possible IO addresses, interrupt numbers and dma channels.
  507.   Then it detects the FM chip, and analyzes if this is an adlib, a
  508.   sb20, a sbpro or no soundcard available.
  509.   The vriable dsp_vers is set to the DSP version (highbyte is major
  510.   number). The variable wh_chard is set to one of the following defs:
  511.  
  512.   none
  513.   adlib
  514.   sb20
  515.   sbpro  
  516.  
  517.   The following variables are set by SB_Setup() (actually
  518.   WhichCard() ):
  519.  
  520.   io_addr -- IO port address
  521.   intnr   -- interrupt number
  522.   dma_ch  -- dma channel
  523.   card_id -- Creative Labs soundcard id
  524.   fm_addr -- the actual address of the FM chip
  525.   fm_both -- the address for both chips
  526.   fm_left -- the address for the left chip
  527.   fm_right-- the address for the right chip
  528.  
  529.   you can use them with an extern statement from your module.
  530.  
  531.  
  532. void SB_SetVect(vect which);
  533.  
  534.   This sets the vector to the midi or sample interrupt routine.
  535.   The possible modes are:
  536.  
  537.   midi
  538.   sample
  539.  
  540.   If you want only to use the FM chip, there is no need in calling
  541.   SB_SetVect().
  542.  
  543.  
  544. void SB_RemoveVect();
  545.   
  546.   SB_RemoveVect() restores the original interrupt ventor.
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554. 8. -----------------  Misc. routines  ---------------------------
  555.  
  556.  
  557.  
  558.  
  559. int get_sb_env();
  560.  
  561.   This routine sets variables out of the environment string:
  562.  
  563.   io_addr -- IO port address
  564.   intnr   -- interrupt number
  565.   dma_ch  -- dma channel
  566.   card_id -- Creative Labs soundcard id
  567.  
  568.  
  569. int CardCheck();
  570.  
  571.   This routine makes another card check. Upon this it return:
  572.  
  573.   FM_DETECT
  574.   DSP_DETECT
  575.  
  576.   The definitions stand for bits. If the bits are set the feature is
  577.   found. E.g. if(ret&DSP_DETECT) printf("yupieee, dsp detected\n");
  578.   
  579.  
  580. cardtype WhichCard();
  581.  
  582.   This is the subprocedure which is used by SB_Setup() to determine
  583.   the sound card and to set the addresses. It returns:
  584.  
  585.   none
  586.   adlib
  587.   sb20
  588.   sbpro  
  589.  
  590.  
  591.  
  592.  
  593.  
  594. -----------------------------------------------------------
  595.  
  596.  
  597.  
  598. Vers.                          History
  599.                                -------
  600.  
  601.  1.00 27-Jun-93  SoundX library 1.0 released
  602.