Информационный сервер для программистов: Исходники со всего света. Паскальные исходники со всего света
  Powered by Поисковый сервер Яndex: Найдется ВСЁ!
На Главную Исходники Форум Информер Страны мира
   Demo Making    >>    otsample
   
 
 Outlaw Triad Demo Series, Part 8 - SOUND SAMPLES  Vulture/OT 10.07.96

Демо серия группы Outlaw Triad, Выпуск №8. Вывод звука на SoundBlaster.
This time we will talk about something completely different, sound-coding! We will create a basic .RAW sound player using the soundblaster (sorry, no GUS). Sound will be played using DMA transfers, just like modplayers.



23k 
 

- THE OUTLAW TRIAD DEMO-SERIES - ----------------------- PART VIII ---------------------------------- Written by : Vulture/OT Code in : Pascal/Asm Topic : Samples ---------------------- Introduction -------------------------------- Welcome to the Outlaw Triad demo-series! In these series we will be talking about programming demo-effects in either pascal or assembler. Theory behind the effects shall be discussed while a full sourcecode is also provided. This time we will talk about something completely different, sound-coding! We will create a basic .RAW sound player using the soundblaster (sorry, no GUS). Sound will be played using DMA transfers, just like modplayers. Enjoy! ------------------------- Theory ----------------------------------- Notes: In this example I will use the most basic soundcard and that's the soundblaster 2.0 (is 1.0 still alive?). Reason for this is that I'm the lucky owner of such a device :-) and have absolutely no money to buy a better card. Allright! Let's start by talking about some soundblaster basics such as port adresses and writing and reading from the card. Fundamental things like that cannot be done any other way like described below. The soundblaster can be programmed through 4 ports. These are: Reset 2x6h Read data 2xAh Write command/data output 2xCh Write buffer status input 2xCh Data available 2xEh The x is 1 for base address 210h, 2 for 220h њњњ and 6 for 260h. Now, before you can program the DSP, you will have to reset it. The reset takes around a 100 micro-seconds so if the reset takes longer than that, you can assume an error has occured and abort the program. - Write a 1 to the RESET port (2x6h) - Wait for 3 micro-seconds - Write a 0 to the RESET port (2x6h) - Read the byte from the DATA AVAILABLE (2xEh) port until bit 7 = 1 - Poll for a ready byte (AAh) from the READ DATA port (2xAh) Ok, now the soundblaster can be programmed. Here's how to write a byte to the card: - Read the WRITE BUFFER STATUS port until bit 7 equals 0 - Write value to the WRITE COMMAND/DATA port And how to read from it: - Read the DATA AVAILABLE port (2xEh) until bit 7 = 1 - Read data from the READ DATA port (2xAh) There! It should be fairly easy to write some procedures which perform these tasks. Take a look at the source to see how it can be done. Ok, you understand the basics? Good! Now we are going to play a sample (raw sound data) through the soundblaster. We need to setup the DMA and soundblaster ports for output of raw data. The procedure for playing raw data using DMA transfers is as follows: 1. Load sound data into memory 2. Setup the DMA chip for the tranfer 3. Set the DSP TIME_CONSTANT to the sampling rate 4. Write DMA_TYPE_VALUE value to the DSP 5. Write DATA_LENGTH to the DSP (2 bytes, LSB first) where DATA_LENGTH = number of bytes to send + 1 Let's take a look at this in detail. 1. Simple. Just get the required memory using the GETMEM procedure and load the data using a BLOCKREAD command. 2. We will be using DMA channel 1 for transfering the sound data to the soundblaster. Here's how to setup the DMA chip for the transfer: - Calculate 20 bit address of the memory buffer you are using like this: Segment * 16 + Offset - Send value 05h to port 0Ah (mask off channel 1) - Send value 00h to port 0Ch (clear the internal DMA flip/flop) - Send value 49h to port 0Bh (playback) or 45h to port 0Bh (recording) - Write LSB (bits 0 - 7) of the 20 bit memory address to port 02h - Write MSB (bits 8 - 15) of the 20 bit memory address to port 02h - Write Page (bits 16 -> 19) of the 20 bit memory address to port 83h - Send LSB of DATA_LENGTH to port 03h - Send MSB of DATA_LENGTH to port 03h - Send value 01h to port 0Ah (enable channel 1) I've used assembler to do most of this stuff but it isn't very hard to convert it to Pascal or whatever language you use. 3. Setting the frequency of the sample must be done by calculating a certain time constant with: 256 - 1000000 / frequency. After you've done this, you write the value to the soundblaster by writing value 40h to the card immidiately followed by the time constant. Note: for frequencies between 22 Khz - 44Khz, use the following formula: (MSB of) 65536 - (256000000 / frequency) 4. Various types of DMA transfers are provided. Here's a list which shows them. +---------------+--------------------+-----------------------+ |DMA_TYPE_VALUE | Description | Frequency Range | +---------------+--------------------+-----------------------+ | 14h | 8 bit | 4KHz -> 23 KHz | | 74h | 4 bit ADPCM | 4KHz -> 12 KHz | | 75h | 4 bit ADPCM with | 4KHz -> 12 KHz | | | reference byte | | | 76h | 2.6 bit ADPCM | 4KHz -> 13 KHz | | 77h | 2.6 bit ADPCM with | 4KHz -> 13 KHz | | | reference byte | | | 16h | 2 bit ADPCM | 4KHz -> 11 KHz | | 17h | 2 bit ADPCM with | 4KHz -> 11 KHz | | | reference byte | | +---------------+--------------------+-----------------------+ In this example we are transfering 8 bit samples so we simply write 14h to the soundblaster. 5. Just write the low byte of the data length followed by the high byte and you're done. Remember to increase the data length by 1. Well, that's all there is to it. Immediately after you've done these steps, output will start and the sample will be played. It isn't very hard to code just because you simply follow a set of basic rules. However, it's important to implement this stuff correctly because these routines are the basics of soundblaster programming. Ok, this is all for now. Happy coding! -Vulture/Outlaw Triad- ----------------------- Distro Sites ------------------------------- Call our distrobution sites! All our releases are available at: BlueNose World HQ +31 (0)345-619401 The Force Distrosite +31 (0)36-5346967 More distros wanted! Bugs'R'Us Distrosite +31 (0)252-686092 (preferably outside ShockWave South African HQ +27 (011)888-6345 of the Netherlands) Society HQ United States HQ +1 (518)465-6721 Also check the major FTP sites for Outlaw Triad productions. -------------------------- Contact --------------------------------- Want to contact Outlaw Triad for some reason? You can reach us at our distrosites in Holland. Or if you have e-mail access, mail us: Vulture (coder/pr) comma400@tem.nhl.nl Our internet homepage: http://www.tem.nhl.nl/~comma400/vulture.html These internet adresses should be valid at least till june 1997. ---------------------------------------------------------------------- Quote: 43.3% of statistics are useless