Skip to content

Commit 178c3de

Browse files
committed
examples: fix portaudio on Win
- Change duration to play notes for longer as 44ms duration was too small to play over stream initialisation on Win32 with MM API. - Print portaudio API and device names - Fix callback and error text dereferencing
1 parent bd40855 commit 178c3de

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

examples/sound/portaudio-sine.bas

+19-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Type PlayPayload
1313
frequency As Single
1414
End Type
1515

16-
Function PlayCallback (InputBuff as Const Any Ptr, OutputBuff as Any Ptr, _
16+
Function PlayCallback cdecl (InputBuff as Const Any Ptr, OutputBuff as Any Ptr, _
1717
FrameCount as CUlong, TimeInfo as Const PaStreamCallbackTimeInfo Ptr, _
1818
StatusFlags as PaStreamCallbackFlags, UserData as Any ptr) as Long
1919

@@ -35,14 +35,14 @@ Sub Play(Frequency as Single, Duration as Single)
3535

3636
pe = Pa_OpenDefaultStream(@stream, 0, 1, paInt32, SampleRate, SineSamples, @PlayCallback, @payload)
3737
If pe <> paNoError Then
38-
Print "Error: "; Pa_GetErrorText(pe)
38+
Print "Error: "; *Pa_GetErrorText(pe)
3939
End 1
4040
End If
4141

4242
Print "Playing "; Frequency; "Hz for "; Duration; "ms"
4343
pe = Pa_StartStream(stream)
4444
If pe <> paNoError Then
45-
Print "Error: "; Pa_GetErrorText(pe)
45+
Print "Error: "; *Pa_GetErrorText(pe)
4646
End 1
4747
End If
4848

@@ -51,13 +51,13 @@ Sub Play(Frequency as Single, Duration as Single)
5151

5252
pe = Pa_StopStream(stream)
5353
If pe <> paNoError Then
54-
Print "Error: "; Pa_GetErrorText(pe)
54+
Print "Error: "; *Pa_GetErrorText(pe)
5555
End 1
5656
End If
5757

5858
pe = Pa_CloseStream(stream)
5959
If pe <> paNoError Then
60-
Print "Error: "; Pa_GetErrorText(pe)
60+
Print "Error: "; *Pa_GetErrorText(pe)
6161
End 1
6262
End If
6363
End Sub
@@ -67,13 +67,23 @@ Print "Initialize PortAudio ("; *Pa_GetVersionText(); ")"
6767

6868
pe = Pa_Initialize()
6969
If pe <> paNoError Then
70-
Print "Error: "; Pa_GetErrorText(pe)
70+
Print "Error: "; *Pa_GetErrorText(pe)
7171
End 1
7272
End If
7373

74-
'' Play from A4 (440Hz) for 44ms until A2 (220Hz) for 22ms
75-
For i as Integer = 440 to 220 Step -10
76-
Play(i, i / 10)
74+
Dim defdevice as Integer = Pa_GetDefaultOutputDevice()
75+
If defdevice = paNoDevice Then
76+
Print "Error: no default output device"
77+
End 1
78+
End If
79+
80+
Dim devinfo as const PaDeviceInfo Ptr = Pa_GetDeviceInfo(defdevice)
81+
Dim apiinfo as const PaHostApiInfo Ptr = Pa_GetHostApiInfo(Pa_GetDefaultHostApi())
82+
Print "Using "; *apiinfo->name; " api on default output device: "; *devinfo->name
83+
84+
'' Play from A4 (440Hz) for 440ms until A3 (220Hz) for 220ms
85+
For i as Integer = 440 to 220 Step -110
86+
Play(i, i)
7787
Next
7888

7989
Print "Shutdown PortAudio"

0 commit comments

Comments
 (0)