Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Musical note problem

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I want to make a small app so that a friend of mine who is learning the violin (at the age of 65) can tune it properly.
I need to produce the exact G, A, D and E.

I tired the beep API but it only sounds through the tiny motherboard beeper.

Is there a way of making it sound thru the normal audio output or another way entirely other than playing prerecorded wav files?
 
I think, could be wrong, but I think there is a setting somewhere that you can change and I believe it may be in the bios or if you have a computer that has access to the mother board settings through the OS... then again it has been such a long time, Windows may now have this option...

Well if there is a way, hopefully the person that knows will come along and point you in the right direction...



Good Luck

 



Hi,

All you need is A (440 hz). Every violenist, and all other orchestra members, tune their instruments to A.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks

I didn't want to have to modify the bios in a users computer.

Actually I also play the violin in an chamber orchestra of 20 players.
It is true that an experienced player will first tune the A string then tune the other strings by listening to the beat otherwise produced if they are not exactly tuned.

A beginner usually has great difficulty in doing this until their ear becomes attuned. You can be a whole note out and still get a beat which can trick you into thinking it is in tune. It is also hard when replacing a string.

Besides if you can get A 440 you can surely get any other.

The reason the other notes are not played by the oboe in an orchestra is that all wind instruments are notoriously slightly out of tune in every note because it is impossible to make the holes and spacings exactly accurate and they differ with the temperature of the air.

A string instrument (without frets) is capable of exact note pitch only dependent on the skill of the tuner and player. That's why they sound so horrible in the hands of a beginner because it is so easy to have it exactly wrong!

 
It's one of those occasions where if you had a VIC-20 kicking about you could probably write it in about 2 minutes!

Why don't you record yourself playing the four notes in question and then use the PlaySound API to play them.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
>Why don't you record yourself playing the four notes in question and then use the PlaySound API

Alteratively, write teeny piece of code to generate a sine wave of the correct frequency and play that through PlaySound using the SND_MEMORY parameter

Or use the MIDI api (this will take a little longer to write) to play the required note on a specific instrument through whatever MIDI synthesizer your soundcard pretends to be (all should at least support the Microsoft GS wavetable synth)
 
>Alteratively, write teeny piece of code to generate a sine wave of the correct frequency

I guess this goes back to the original question; how to generate a tone at a particular frequency.

Ted, if you decide to go down the MAPI route I've got some code for doing it that you might find useful - I would post a link to the source but it isn't included in the code, I seem to think I got it from experts-exchange.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
>back to the original question; how to generate a tone at a particular frequency

That's not quite what the original question asks.

>MAPI

I presume you meant to type MIDI
 
Thanks
I threw my old vic20 on the dump last year but as I remember you could not get exact frequencies, only approximate.

I didn't want to use a recording or midi, just produce a plain sine or square wave from the normal sound output from a single app without any additional files and being independent of the MIDI volume being adjusted correctly (which usually isn't).

Should I look elsewhere for this?
 
ted,
I've already advised you on the approach that needs to be taken to achieve the goal you have now clarified (no recordings, no midi) - generate a sine wave of the correct frequency and play that through PlaySound using the SND_MEMORY parameter (essentially you create a WAV file in memory and then play that back). I haven't provided further details because I know how much you normally like to figure this stuff out for yourself.

By the way, part of your original question post observed: "the beep API only sounds through the tiny motherboard beeper"

That's all it is supposed to do. The beep API is not a part of the normal sound APIs on a PC; it is a legacy of the days when PCs might not have a soundcard. The beep is generated from the 3rd output of the timer chip (which we previously talked about in the threads concerning clock accuracy), which is specifically reserved for this purpose. Basically we can program in a frequency and the clock generates the resulting square wave which is fed directly to the onboard (generally picoelectronic) speaker because the output of the clock is physically connected to that speaker.

i.e the beep API drives the PC speaker, and nothing else.
 
Well, for the basics you could get Audio test tone into wav and use it to make 4 .WAV files, one for each pitch. Sadly it won't create less than 1 second samples so they're a little large but what do you want for nothing?

Then you can create a VB6 program with 5 buttons (4 tones plus stop), and add your 4 WAVE samples as type "WAVE" and IDs of G, A, D, E. Then there isn't much left:
Code:
Option Explicit

Private Const SND_RESOURCE = &H40004 'Name is a resource name or atom.
Private Const SND_LOOP = &H8         'Loop the sound until next PlaySound.
Private Const SND_ASYNC = &H1        'Play asynchronously.

Private Declare Function PlaySound Lib "winmm" Alias "PlaySoundA" ( _
    ByVal lpszName As String, _
    ByVal hModule As Long, _
    ByVal dwFlags As Long) As Long

Private Sub cmdA_Click()
    PlaySound "A", App.hInstance, SND_RESOURCE Or SND_LOOP Or SND_ASYNC
End Sub

Private Sub cmdD_Click()
    PlaySound "D", App.hInstance, SND_RESOURCE Or SND_LOOP Or SND_ASYNC
End Sub

Private Sub cmdE_Click()
    PlaySound "E", App.hInstance, SND_RESOURCE Or SND_LOOP Or SND_ASYNC
End Sub

Private Sub cmdG_Click()
    PlaySound "G", App.hInstance, SND_RESOURCE Or SND_LOOP Or SND_ASYNC
End Sub

Private Sub cmdStop_Click()
    PlaySound vbNullString, 0&, 0&
End Sub
You can't test it in the IDE since it wants to reference the compiled EXE (module) for resource extraction at runtime. Seems to work fine though.
 
This is Ted, Hypetia; he's already stated that - for reasons not particularly clear - he doesn't want to use MIDI ...
 
strongm, or anybody, please correct me if I am wrong, but if you disable the speaker through the bios, the beep api will play, if present, through the sound card...
 
strongm, the thread I mentioned is not about MIDI, but for producing wave sounds on the fly.
 
>if you disable the speaker through the bios, the beep api will play, if present, through the sound card

Depends on the OS. Basically that happens for the 64bit OSs (XP 64bit, Vista 64, Windows 7 64), because of a dramatic rewrite of the Beep driver (yes, it had it's own driver dll).

Don't believe it is true of any of the 32bit OSs.
 
>not about MIDI, but for producing wave sounds on the fly

Apologies. I didn't read beyond the first several posts in that thread, and therefore commented unwisely.

Your Beep function code does exactly what I described to ted (albeit as an 8bit sample... ;-) ), and looks uncannily similar to the example I was knocking together (no surprise there, really).

Ted, look at Hypetia's Beep code in the thread he references. It should do what you want, including whacking the volume up to maximum ...
 
>Don't believe it is true of any of the 32bit OSs.

I just checked that Beep API on my PC is producing sounds from the sound card. I can open the mixer or volume controller, to change the volume, or mute the sound altogether.

I have Intel D915 board running 32-bit Windows 7.
 
Ah - slightly different. I believe that on some configs what you get if the 8254 PIT (or equivalent) is disabled or unavailable is the default Windows sound event, not the tone you request.

i.e you effectively get

sndPlaySound ".default", SND_ALIAS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top