http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sound Card Programming!



Hi Everyone,

I have been a member ... let's say just a quite watcher of this fabulous 
site for some time, and I like the tone, that is easy discussion, but some 
of the discussion is way above my head, I am afraid, so I keep myself down. 
But these days, I wonder how would it be actually like to take part in the 
discusstion. So here I am, If anybody would advise me on what to do or where 
to look for information, it would be a big help to me. If anybody want to 
work with me on this project that currently I am doing (I hope somebody 
will), he/she will definite be welcome and I will send all the source code 
that I have developed and appreciate the effort.

Is anyone interested about Sound Card Programming ... I am a little new in 
this area and facing many problems and seeking help. With problems, I mean 
to say lack of information. If anybody would take the time, and answer all 
the question, that will be great, in fact, that is not what I hope to get 
(in my wildest dream), all I hope is to get is some pointers to the right 
direction, or some info will be nice.

I have developed a Piano Player program as a start, that is I have defined a 
keyboard layout, and upon key press, it plays a key (or note). I have also 
put some rhythm in the background, and be able to save and retreive using 
DMA. I want to check/set the microphone, line on the fly, but when I am 
using the DMA to record some, by default any input from the microphone or 
line is saved along with any other data.

Here's some of the things that I want to know:

1. I have a BNK file and some IBK files, found in disk came with a book, I 
merged them all in a different format (of my own), and I counted only about 
1056 Instrument definitions. I wonder if there is anywhere where I can find 
more Instrument data, BNK or IBK file(s) will be fine.

2. I can't seem to generate Stereo sound, the documentation that I have, 
said One Port for the Left Channel and another for the Right, but, if I put 
any value in any of these port, both the speakers make sound. I have Sound 
Blaster Compatible Sound Card. Is it something to do with OPL2/OPL3 
standard, the book said only about OPL2 but under stereo it said one for the 
left and one for the right would do the job. Have any info on that?

3. I can't seem to play rhythm instrument properly, the Base Drum and Tom 
Tom plays well, but it cann't play Cymbals, HiHats properly, I don't know 
why, I have set rhythmic mode of the sound card properly, and set Modulator 
and Operator data properly and when needed, and set and BDh register 
properly to have the sound, but it doesn't seem to work.

4. I am using a Timer code that is supposed to make the clock speed faster. 
Usually the clock ticks 18.2 times per second, this particular example that 
I have that shows how to make it tick 72 times per second. It sucks. It is 
enough for my rhythm beats, 72 beats per second is too much I think, but it 
sucks for being 72hz sample rate in order to check the input/output. After 
all, 44.1Khz means 44100 times per second approxmately right, to have a 
sample rate of 44.1Khz, one would have to read/write the port 44100 timers 
per second. How would I do it through loop? This looping is important for 
me, because I am generating rhythm beats on the fly, and it depends a lot on 
the timing. I also want to check out the input/output 44100 times per second 
in order to save/retreive them as well as play fine rhythm. All I want is to 
call a function 44100 times per second or better despite of machine speed, 
whether it is PII or PIII or just a 486 like mine.

5. Well, I have info on using DMA that will read/write the port 44100 times 
second, I don't know how, but it does the job, and all I had to do is set 
some register and set the buffer and start transferring, and sit duck while 
the DMA is active. Of course, I can use incremental looping to generate the 
rhythm timing, but it sucks, and varies from machine to machine which I 
don't want. Is it possible to set the DMA active and use the timer chip as 
well? I tried that, and the system chrashed like hell.

6. I tried to save something on the disk while the timer is on, and the 
machine crashed. Is it something I am doing that is wrong, or it is always 
the case? Same thing happened when the DMA is active.

7. After numerous efforts, mainly trial and error, I finally got the 
input/output, basically recording/playing in order. I can record/play in WAV 
format, thanks to a friend of mine for the format, only the format, no 
sample code or anything, and right now it is working properly. But an 
interesting rather mysterious thing is that I recorded/played say about 50 
files, I have played back right after I recorded and it played as expected. 
But when I exited from the program and browse the directory, I found some 
the files are missing, it was not saved properly, How is it possible, after 
all, I have closed the file handle properly, I checked the "wb" mode for 
fopen, it was okay, then I opened in "rb" mode and played the file, it 
played properly, and when I exited, there was no file in the directory, It 
doesn't always happen, sometime it is there, sometime it isn't. I wonder 
why? If I have the DMA on during the saving process, the system hanged. Is 
it something to do with the BIOS disk interrupt 13h? Or something to do with 
Cache?

8. IMPORTANT (to me): In this program, all I need to know to generate a note 
is the frequency, that is I have a list of notes and their frequencies in an 
array, and upon key press, it identifies the octave and the note, and sets 
the frequency as of from the array, the instrument is set previously with 
the settings as found the Instrument file, all the sustain/release, 
attack/decay, KSL/multi... does not change, only the frequency and key 
on/off state changes, and it WORKS. Now I checked the value read from the 
DSP as a Microphone input, It is only a value ranging from -127 to +127, 
correct me if I am wrong. If I save this value and afterward send this value 
directly to the DSP in the same speed, it produce the same sound, right?. 
But How do I know the frequency? I wanted to process something. Let me say 
what I want, I have inserted the cord/jack from my guitar into the 
Mincrophone input of the sound card, and I play along with the background 
Music, and Start saving with the DMA and It works, on retreival, it plays 
whatever I have played with my guitar, fine for me. Now, I want to change 
the tone of the Guitar, that is I want to produce PIANO sound on the notes 
played on the Guitar, or Flute, or Banjo or whatever. That is, all I want is 
that I play a note on the Guitar and It should play Piano/flute/... upon 
choice. All I need to do this is to identify the frequency of the note 
played in the Guitar. How do I do that? Is it something to do with the 
Physics formula, that frequency is equal to someting devided by time thing, 
won't it be time consuming? If I had to save the playing thing on a buffer, 
and check for the frequency, and then play back, it won't be realtime, 
right? I cann't imaging playing on my guitar and waiting for it to hear the 
output. My question is: How do I find out frequency of the input in 
realtime, because all I need is the frequency, that is whether it is a C, C 
sharp, D, D sharp ... note that is played on, so that I can generate similar 
tone with other instruments.

9. I am running the program from DOS, and it works okay with my Aztech Sound 
Card, But it does not work with my ESS sound card. If I ran the program from 
a DOS box of the Windows, it works with the ESS card as well. I don't 
understand, I am writing directly to the port to generate output, why do I 
need the driver? I am not calling any driver or anything. Don't laugh, 
seriously I am confused. How come it works with one Card, and does not work 
with another? Under Windows, generating output through the FM chip works, 
but recording/playing through the DMA doesn't work, some time the system 
crashes, sometime weird sound is generated. I don't know why.

10. IMPORTANT (to me): I am planning to port the system in Windows Platform. 
I don't know how. For a start, I don't know how to output data to the port 
under Windows. I know how to play entire WAV file under windows, But lack 
the information on how do I generate sound with frequency, set Instrument 
Data on the channel, etc. Any info, sample code, anything, will be 
appreciated.

The above defined statements are some of the BIG problems that I am facing, 
and don't know the solution. If anybody would advise me on what to do or 
where to look for information, it would be a big help to me. If anybody want 
to work with me on this project (I hope somebody will), he/she will definite 
be welcome and I will send all the source code that I have developed and 
appreciate the effort. Just drop me a line and I will contact you. Please 
note that anybody who doesn't like sharing information, needn't reply.

Regards,

Towhidun Nabi
naeeym@hotmail.com


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
=================================================================
To SUBSCRIBE or UNSUBSCRIBE please visit
http://gameprogrammer.com/mailinglist.html