Post by JM "Poole" Melanson on Mar 7, 2020 1:42:31 GMT 1
I wanted to be able to load a wave file into an array and play it via the WaveOut API functions because attempts to produce sound effects using MCI or Playsound statements introduced delays or other glitches. This also goes well with my desire to know how things work " under the hood".
I found a VB5 example and tweaked the Data types (mainly changed Integer to Int16) and voilà!
I also needed to change VB5's CopyMemory to Gfa's MemCpy and change VB5's way to load any file into an array because it:(Get #1, , <array_name>) is not implemented in GFA.:
' This does not work in GFA BASIC 32...
Open App.Path & "\test1.wav" For Binary As #1
ReDim WavSound(LOF(1) - 1)
Get #1, , WavSound
I used this instead:
Open Short_File_Name$ for Binary As # 1
' Set the size of the array to the LOF(#1)-1 (length of file opened in channel #1)
ReDim WavSound(LOF(# 1))
Local i% = 0
' Store the next byte
WavSound(i) = Inp(# 1)
' Exit the loop before incrementing the index
Exit If EOF(# 1)
' Increment the index
i += 1
Close # 1
Version 3. I added a few more buttons and cleaned up the code.
Version 4. I added file selection dialog. When play back rate is changed, the position is not reported accurately.
I noticed the minimum playback rate is 50% of original. I did not expect that.
Version 5. I added a few slider to control master volume and pan left and right that uses an elliptical response curve for each ear.
Demo WaveOut Player V5.G32 (44.79 KB)
The source example in VB5:
WavePlayerWithSineWaveDisplay.zip (497.51 KB)
P.S.: You don't need VB to take a look at the code. Just append the .txt file extension to the filenames and open with Notepad.