Guru Challenge (Waveform Audio Files) 
Author Message
 Guru Challenge (Waveform Audio Files)

I want to create my own wave files of different frequencies and volume
levels.  I'm at the point where I can create a PCM wavefile byte by byte
for all of the standard PCM formats (1M8, 1M16, 1S8, ... 2S16) and play
them using low level playback.
        Now that I have the data, does anyone know how to save it as a wave file?

Thanks in advance

Pete Osborne


Function WaveOut()
Dim ReturnCode As Long

   ' Open the wave device.
   ReturnCode = waveOutOpen(hWaveOut, WAVE_MAPPER, PCMWaveFmtRecord, 0&,
0&, 0&)
   If ReturnCode = 0 Then
      ' Prepare the wave output header.
      ReturnCode = waveOutPrepareHeader(hWaveOut, WaveHeader,
      If ReturnCode = 0 Then
         ' Write the wave data to the output device.
         ReturnCode = waveOutWrite(hWaveOut, WaveHeader, Len(WaveHeader))
         ' Wait until finished playing.
         If ReturnCode = 0 Then
            Do Until (WaveHeader.dwFlags And WHDR_DONE)
         End If
         ' Unprepare the wave output header.
         ReturnCode = waveOutUnprepareHeader(hWaveOut, WaveHeader,
         If ReturnCode <> 0 Then
            MsgBox "Unable to Unprepare Wave Header", MB_ICONSTOP, "Wave
         End If
         WaveHeader.dwFlags = 0
         ' Close the wave device.
         ReturnCode = waveOutClose(hWaveOut)
         If ReturnCode <> 0 Then
            MsgBox "Unable to Close Wave Device", MB_ICONSTOP, "Wave Error"
         End If
         ' Couldn't prepare the header, so close the device.
         MsgBox "Unable to Prepare Wave Header", 0, "Wave Error"
         ReturnCode = waveOutClose(hWaveOut)
         If ReturnCode <> 0 Then
             MsgBox "Unable to Close Wave Device", MB_ICONSTOP, "Wave
         End If
      End If
      ' Couldn't open the device so do nothing.
      MsgBox "Unable to Open Wave Device", MB_ICONSTOP, "Wave Error"
   End If
End Function

Function CreateFrequency(BitsPeakToPeak As Integer, TimeInSeconds As
Frequency As Integer)
' Function to create a certain frequency for a given
' period of time at a given amplitude
'Note this is for 2S16
Dim NewBufferLength As Long
Dim Position As Long
Dim Sample As Long
'Reserve enough room to hold all of the WAVE Data
NewBufferLength = 4 * CLng(CLng(TimeInSeconds) *
ReDim Preserve WaveBuffer(NewBufferLength + 3)
For Position = 0 To (NewBufferLength) Step 4
    Sample = BitsPeakToPeak * Sin(2 * Pi * Position / 4 * Frequency /

    'Limit the Amplitude of the signal
    Sample = MaxLong(MinLong(Sample, 32767), -32768)
    If Sample < 0 Then
        Sample = 65535 + Sample
    End If
    'Store the upper eight bits of sound data in the second byte of buffer
    WaveBuffer(Position + 1) = Sample \ 256
    WaveBuffer(Position + 3) = WaveBuffer(Position + 1)
    'Store the lower eight bits of sound data in the first byte of buffer
    WaveBuffer(Position) = Sample Mod 256
    WaveBuffer(Position + 2) = WaveBuffer(Position)
Next Position
'Returns the pointer to the wave data
WaveHeader.lpData = lparraycpy(WaveBuffer(0), WaveBuffer(0))
'Returns the length of the wave data
WaveHeader.dwBufferLength = NewBufferLength + 3
'No Flags Required
WaveHeader.dwFlags = 0&
WaveHeader.dwLoops = 0&
End Function

Fri, 22 Sep 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Guru Challenge (Wav Audio Files)

2. Saving Waveform audio using the WavIn API commands ?

3. Waveform Audio API - Can't Record

4. Audio Waveform API Call?

5. Saving Waveform audio using the WavIn API commands ?

6. Challenging Challenging Challenging Challenging Challenging...all because of rpt files...!

7. Win APIs to play mpg video files, mp3 audio files and audio cds

8. --> I challenge you VB guru!<--

9. Challenge to VB 3.0 / Access 2.0 guru: Creating new field of type Counter

10. A challenge for all the would-be gurus out there

11. A challenge for you VB gurus: Creating an independent copy of an object

12. Has anyone written...? CHALLENGE TO GURUs


Powered by phpBB® Forum Software