I am not trying to write a game.

Are there any API's that give the pitches in music such as:
c c# d d# e f etc.??

I have investigated PlaySound, IDirectMusicPerformance and
snaplaysound and they DON'T fill the bill.

I don't think MIDI is what I want either.
Looked in Petzolds book and found nothing.
Maybe there is a wav. file somewhere???

Thanks,
JPS
Posted on 2003-02-27 18:28:00 by shankle
By pitch, do you mean frequency?

One octave difference is a doubling of frequency. Since there are 12 notes in an octave (counting all the sharps and flats, ie, counting every key on a piano) leads to a formula of:

F(n) = Fo * 2 ^ (n/12) ; where Fo is some standard frequency,
; and n is the number of notes away from Fo (negative is OK)

Concert scale middle C is 440 Hz.
Posted on 2003-02-27 21:07:36 by Ernie
Pitch " is " the frequency.

Don't know anything about making sound on a computer though.

What is the format of the data that you might send to a speaker through a port?

Does a double word represent a frequency and you just kepp sending that packet for your duration time?

:confused:
Posted on 2003-02-27 21:30:42 by IwasTitan
I'm not doubting that your math calc will work but that does not
help me keep in the windows API rut to conform with the rest of
windows. I think I should be using some API to handle the job.

In other words it doesn't seem right to write 90% of a program
conforming to windows specs and 10% in some low level code.

I am referring to the sound that hitting Middle C on the piano
would make.

Thanks,
JPS
Posted on 2003-02-27 22:14:27 by shankle
I'm interested in this one too. Last time i played with sound was on an Apple II back in the mid 80's, all you had to do was beep the speaker, you achieved pitch by having the right length delay loop between beeps. And the C64 was easy too, you just had (IIRC) to nominate the pitch, then the attack/decay/sustain/ release for that note.

Nowdays, i have no freakin' idea how to generate music from scratch.
Posted on 2003-02-27 22:21:42 by sluggy
well, the way it used to be accomplished outside of Windows on an PC was by pulsing the speaker in and out after replacing one of the interrupts (don't remember which one, but it was the one which was called by the computer to update the clock).

back with DOS's GW-BASIC (and even /w QB), you could use the "SOUND" statement to generate a note from the speaker. SOUND frequency, length (in milliseconds). but QB (and maybe basica?) also had the "play" statement, greatly simplifying sound production. and then there was, of course, the beep statement, which played a fixed note for a fixed time interval. still exists in VB for Win (VB for DOS had it, i think), but sound and play have been removed. Perhaps there *is* no Windows API for it, except through MIDI.
Posted on 2003-02-27 22:49:43 by jademtech
Hi

Something I remember seeing you might look at..

http://www.stormpages.com/bojanjurca/CSamples.htm

Producing PC speaker sounds under Windows 9.x just as well as under Windows NT and 2000

Speaker.dll exports Sound function that produces a sound of a desired frequency and duration similar to Beep function under Windows NT but with one exception. The Sound function works under Windows 9.x as well.

Download Speaker.zip (6 KB) containing C source and compiled .dll file.

Kayaker
Posted on 2003-02-27 23:46:03 by Kayaker
You could just generate the sound (using sin or whatever you want) and then use the Windows API sound functions to play it.
Posted on 2003-02-28 00:26:55 by gliptic
You might want to search for:

FM (Frequency Modulation) Synthesis
WaveTable Synthesis

but I can't be sure since I don't study on this area. :)
Posted on 2003-02-28 01:07:23 by arkane

By pitch, do you mean frequency?

One octave difference is a doubling of frequency. Since there are 12 notes in an octave (counting all the sharps and flats, ie, counting every key on a piano) leads to a formula of:

F(n) = Fo * 2 ^ (n/12) ; where Fo is some standard frequency,
; and n is the number of notes away from Fo (negative is OK)

Concert scale middle C is 440 Hz.
middle A, not middle C. :)

C is about 261.6 Hz (or 523.2 Hz the octave higher).
Posted on 2003-02-28 03:04:13 by Maverick
It appears that I my ONLY choice is to use interrupts and play with
the speaker. Since I am using Windows 98 2nd ed what will happen
if I take the program to windows XP? Most likely it will bomb.

Middle C is 261.63 hz and the A above it is 440hz. I found a list of all
the frequencies called equal-tempered at www.phy.mtu.edu/~suits/
notefreqs.html

Thanks for all the input,
JPS
Posted on 2003-02-28 08:20:20 by shankle
You could use the api beep instead of interrupt! :)

BOOL Beep(

DWORD dwFreq, // sound frequency, in hertz
DWORD dwDuration // sound duration, in milliseconds
);:

It will work on winXP too if I recall correctly.
Posted on 2003-02-28 10:57:58 by david
I have included code that partially solves the problem of generating sound
in MASM32. I don't like what I hear and don't know if it's my crummy
speaker or something else.

Here is the code in BASIC that I used to create the MASM32 code:

10 count = 1193280! / 3000 ; 3000 is the desired frequency
20 lo.count = count mod 256 ; calculate low-order byte value
30 hi.count = count / 256 ; calculate high-order byte value
40 out &h43, &hb6 ; get timer ready
50 out &h42, lo.count ; load low-order byte
60 out &h42, hi.count ; load high-order byte

The bytes of this code have to be turned off to stop the sound.

The code I have included in MASM32 does not include the calculation
of the remainder of the frequency as I don't know how to do it.
Maybe that's why the sound is so bad.
What is the equivalent of "MOD" in MASM32??
Posted on 2003-03-02 08:38:53 by shankle
My guess is you would need to make a wav engine, and feed this directly to the MAPI. You'd need to set up callbacks to generate the next note 'wav' in memory, and queue it befor the first finished playing. (Basically double buffering).

Somewhere a long time ago i did some wave stuff with this. Try here

:alright:
NaN
Posted on 2003-03-02 09:39:11 by NaN
.
Posted on 2003-03-03 16:44:13 by comrade
Havent looked at your source, but its not working correctly on Win98SE. The tone starts, and then turns into a very dull rumble (longer than the specified duration). I have a CreativeLive sound card that never gives me any fuss about anything.

:NaN:
Posted on 2003-03-04 00:20:55 by NaN