'------------------------------------------------------------------------------- ' File: music.bas ' Description: subroutines to play music through a piezo or small speaker ' Author: Dennis Draheim ' Created: 7/17/2000 ' Support Files: PiezoNoteFreqs.txt, a file of note frequencies ' columns are octaves, rows are notes within each octave, ' natural notes only, starting with C '------------------------------------------------------------------------------- Option Explicit Public NoteFrequencies As New SingleTableData '------------------------------------------------------------------------------- Sub InitNotes() Call NoteFrequencies.Source("PiezoNoteFreqs.txt") End Sub '------------------------------------------------------------------------------- Sub PlayNote( _ ByVal Pin As Byte, _ ByVal Octave As Integer, _ ByVal Note As Integer, _ ByVal Duration As Integer) ' ' Play the specified note in the specified octave for the specified duration, ' on the specified pin ' Dim Frequency As Integer Frequency = CInt(NoteFrequencies(Octave, Note)) ' Call PutI(Frequency) ' Call NewLine Call FreqOut(Pin, Frequency, Frequency + 4, Duration) End Sub '------------------------------------------------------------------------------- Sub TestNotes(ByVal Pin As Byte) ' ' Play through all the notes ' Dim Octave As Integer, Note As Integer For Octave = 1 to 4 For Note = 1 to 8 Call PlayNote(Pin, Octave, Note, 100) Next Next End Sub '-------------------------------------------------------------------------------