'-------------------------------------------------------------------------------
Option Explicit

' This program demonstrates the PlaySound command. PlaySound uses sound
' data read from a file on the PC host computer, then downloaded into
' EEPROM and converted into a block data object.

Private SoundConstant As New ByteVectorData   ' Read-only.
Private SoundGraduated As New ByteVectorData  ' Read-only.
'-------------------------------------------------------------------------------
Public Sub Main()

    Const OutputPin As Byte = 17
    Dim Note As Integer
    Dim Length As New UnsignedInteger
    Dim SampleRate As New UnsignedInteger
    Dim RepeatCount As New UnsignedInteger
    Dim File As Integer
    Dim Address As New UnsignedInteger

    Debug.Print 
    Debug.Print "Demonstration of PlaySound with block data objects"

    Call Delay(0.5)

    Call SoundGraduated.Source("SoundGraduated.txt")
    Call SoundConstant.Source("SoundConstant.txt")

    Length = 1000      ' Bytes
    RepeatCount = 2

    For File = 1 To 2
    
        SampleRate = 1000  ' Hz
    
        If (File = 1) Then
            Address = CuInt(SoundConstant.DataAddress)
            Debug.Print
            Debug.Print "  File SoundConstant.dat:"
        Else
            Address = CuInt(SoundGraduated.DataAddress)
            Debug.Print
            Debug.Print "  File SoundGraduated.dat:"
        End If
    
        For Note = 1 To 3
    
            Debug.Print "    Sample rate = "; CStr(SampleRate); " Hz"
    
            Call Delay(0.2)
    
            Call PlaySound( _
                OutputPin, _
                Address, _
                Length, _
                SampleRate, _
                RepeatCount)
    
            SampleRate = SampleRate * 2  ' Increase by octave.
    
            Call Delay(0.5)
        Next
    Next

End Sub
'-------------------------------------------------------------------------------
