Hi,

I am brand new to this forum. I am a programmer/guitarist. I am not a midi programmer which is why I am hear I guess. I have a MS access database program that has a script that can produce various beep, buzzer, siren, etc sounds that was working just fine on an I3 machine running Win XP but it will not run properly on an I5 machine running Win 7 (64 bit). So the code is VBA (visual basic for applications) with a Windows API definition for the beep and VBA calls to this code (I just figured out I can place the code properly so it is below). I am posting to this forum because I discovered that the various sounds improved if I ran a program called "Band In A Box" which uses midi drivers (not perfect but it ran better). If I closed down the BIAB program the Beep code stopped working again. Without running the Band In A box program (BIAB) I increased the duration value sent to the API beep call from a value of 5 on some of the VBA call functions up to about a value of 50 and that allowed at least some sounds to come out (not perfect but again at least I heard something). I have a few things I can try. I can put the Win 7 (64 bit) operating system on a 2nd partition on the I3 machine, I could run win XP emulation on the I5 machine, I could create a 2nd partition on the I5 machine to do a fresh install of Win 7 (64 bit), and last but not least I could spend $109+tax to get Win 7 Home Premium 32 bit to see if it works under the 32 bit operating system. So I am not sure if this is the place to ask questions but any suggestions would be great. I am wondering if the sound card drivers are just not up to producing these sounds properly. I can say one thing. The VBA code below has lots of comments about Midi and he certainly communicated with some people who know about midi to write it. Unfortunately I know nothing about midi programming at all.

One more point. The person who submitted this code to the Utter Access forum said it would not run on MultiMedia speakers. I am not sure this is correct. I am thinking it should be "it may not work on some sound cards due to the drivers". This would be the reason for my putting Win 7 (64 bit) on the I3 machine on a 2nd partition so I can eliminate Win 7 (64 bit) not having Midi drivers as a possible reason.

Also I just noticed a comment that 100 is a good length for the duration. As mentioned above, I got the code originally with a duration of 5 and increase it to 50 to get it to work (to at least produce some sounds). Again, on the I3 machine under XP it ran fine with a duration of 5.

Also the Windows API sleep declaration was suggested by a person on the Utter Access forum to assist with the increase in duration of the beep declaration. I think it may have helped. Regardless, if it helped many of the sounds do not sound correct. For example a siren sound was reduced to a series of slow strange beeps.


Thanks,
John

Code:
Option Compare Database
Option Explicit


'Sample Calls. The first number is frequency and the second number is the length. 100 is a good length.
'Beep 440, 400
'Beep 800, 100
'Beep 880, 400
'Beep 1000, 400


'This generates completely random tones. It lasts about 5 seconds or so then stops
' call myRandTones


'Another siren sound with upward and downward sweeps
'    Call mySiren


'This generates a warning tone with 3 repeats
' Call myWarnTone


' this is another type of warning tone (upward)
'    Call phzup


' this is another type of warning tone but downward
'    Call phzdn


'This plays a scale up
'    Call myScaleUp




'This plays a scale down
'    Call myScaleDown






Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)


Public Declare Function Beep Lib "kernel32" _
(ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
 
Dim I As Long
 
'Usage: Beep freq, lngth
' freq = frequency (in Hertz - range of 37 through 32,767; because 20,000 is above
' most speaker limits, and 0 (zero) results in no response, 20,000 is used as a
' "rest" note in the frequency value)
' lngth = duration - in milliseconds
' Test in debug window: Beep 440, 800
' MIDI to Frequency: (440 / 32) * (2 ^ ((X - 9) / 12))
'     (see fToM below)                  {X = MIDI note [0-127]}
' Frequency to MIDI: Int(((12 * (Log(FRQ) - Log(440))) / Log(2) + 69) + 0.5) / 1
'     (see mToF below)              {FRQ = frequency in hertz [80-18000]}
' Thanks to xteam for the frq to MIDI math
' NOTE: 1) Doesn't work in Win95
'       2) DoCmd.beep only works for Multimedia Speakers.
 
 
Public Function mToF(mn As Long) ' Conbluevert MIDI Note to Frequency
'(440 / 32) * (2 ^ ((mn - 9) / 12)) (mn = MIDI note [0-127])
' for the sake audibility, the working range is 36 to 112
 
    mToF = (440 / 32) * (2 ^ ((mn - 9) / 12))
 
End Function
 
Public Function fToM(frq As Long) ' Convert Frequency to MIDI
 
    If frq > 0 Then
        fToM = Int(((12 * (Log(frq) - Log(440))) / Log(2) + 69) + 0.5) / 1
      Else
        fToM = 0
    End If
 
End Function
 
Public Function myRandTones() ' Generates completely random tones
Dim nI, nF
    For nI = 1 To CLng((10 - 1 + 1) * Rnd + 1)
        For nF = 1 To CLng((5 - 1 + 1) * Rnd + 1)
            Beep (Int((2400 - 220 + 1) * Rnd + 220)), CLng(((250 - 50 + 1) * Rnd + 50))
        Next nF
    Next nI
 
End Function
 
Public Function myRandTone(Optional t As Integer = 0, _
                           Optional f As Integer = 0, _
                           Optional x As Integer = 0) ' Play random notes
' Randomizes numbers for Beep tone generation
' t = number of unique tones to produce (range = 1 to 10)
' f = number of iterations (range = 1 to 5)
' x = length of tone ( range = 0 to 5; if 0, then random value is chosen within range)
' Max values: (10 notes * 5 sequence repeats) = 50 max notes for a maximum of
'              12.5 seconds in length
Dim tI As Long, fI As Long, xI As Long, tL As Long, fL As Long, xL As Long
 
    If t = 0 Then ' Sets number of repititions
        tL = CLng((10 - 1 + 1) * Rnd + 1)
      Else
        tL = t
    End If
    If f = 0 Then ' Sets number of tones/notes in sequence
        fL = CLng((5 - 1 + 1) * Rnd + 1)
      Else
        fL = f
    End If
    If x = 0 Then ' Sets length of tones/notes
        xL = CLng(((500 - 100 + 1) * Rnd + 100) / 2)
      Else
        xL = CLng((x * 100) / 2)
    End If
 
    For tI = 1 To tL
        For fI = 1 To fL
            ' (Int((2400 - 65 + 1) * Rnd + 65)) will pick a random frequency between 65 and 2400 hertz
            Beep (Int((2400 - 65 + 1) * Rnd + 65)), xL
        Next fI
    Next tI
 
End Function
 
Public Function myWarnTone() ' Three upward sweeps
Dim k As Long
 
    For I = 0 To 1 ' <- Increase this value to make it sound longer
        For k = 2600 To 3600 Step 100 ' <- Decrease this value to increase sweep time
            Beep k, 30
            Sleep 40
        Next k
    Next I
 
End Function
 
Public Function phzup() ' Upwards phazer sound
 
        For I = 2200 To 3000 Step 40 ' <- Decrease this value to make it sound longer
            Beep I, 30
            Sleep 40
        Next I
 
End Function
 
Public Function phzdn() ' Downwards phazer sound
 
        For I = 3000 To 2200 Step -40 ' <- Decrease this value to make it sound longer
            Beep I, 30
            Sleep 40
        Next I
        'This works if Band in a box is brought up
        'For I = 3000 To 1000 Step -40 ' <- Decrease this value to make it sound longer
        '    Beep I, 5
        'Next I
 
End Function
 
Public Function mySiren() ' Up & Down sweep
Dim j As Long, k As Long
 
    For I = 0 To 2 ' <- Increase this value to make it sound longer
        For j = 1500 To 2020 Step 100 ' <- Decrease this value to increase up sweep
            Beep j, 30
            Sleep 40
        Next j
        For k = 2020 To 1500 Step -100 ' <- Decrease this value to increase down sweep
            Beep k, 30
            Sleep 40
        Next k
    Next I
 
End Function
 
Public Function myScaleUp(intNumber As Integer) ' 12 Note Music Scale up
 
        Beep 262, 250   ' C  / 60
        Beep 277, 250   ' Db / 61
        If intNumber = 2 Then
            Exit Function
        End If
        Beep 294, 250   ' D  / 62
        Beep 311, 250   ' Eb / 63
        If intNumber = 4 Then
            Exit Function
        End If
        Beep 330, 250   ' E  / 64
        Beep 349, 250   ' F  / 65
        Beep 370, 250   ' Gb / 66
        Beep 392, 250   ' G  / 67
        Beep 415, 250   ' Ab / 68
        Beep 440, 250   ' A  / 69
        Beep 466, 250   ' Bb / 70
        Beep 494, 250   ' B  / 71
 
End Function
 
Public Function myScaleDown(intNumber As Integer) ' 12 Note Music Scale down
        Beep 494, 250   ' B  / 71
        Beep 466, 250   ' Bb / 70
        If intNumber = 2 Then
            Exit Function
        End If
        Beep 440, 250   ' A  / 69
        Beep 415, 250   ' Ab / 68
        If intNumber = 4 Then
            Exit Function
        End If
        Beep 392, 250   ' G  / 67
        Beep 370, 250   ' Gb / 66
        Beep 349, 250   ' F  / 65
        Beep 330, 250   ' E  / 64
        Beep 311, 250   ' Eb / 63
        Beep 294, 250   ' D  / 62
        Beep 277, 250   ' Db / 61
        Beep 262, 250   ' C  / 60
 
End Function