-
Notifications
You must be signed in to change notification settings - Fork 155
examples: Add portaudio sine wave example #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PortAudio already has a FB header, this adds an example usage to play a sine wave from a buffer.
examples/sound/portaudio-sine.bas
Outdated
| frequency As Single | ||
| End Type | ||
|
|
||
| Function PlayCallback (InputBuff as Const Any Ptr, OutputBuff as Any Ptr, _ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On windows, the calling the convention will default to stdcall but the portaudio.bi API expects cdecl
This callback function should be defined with cdecl calling convention as in Function PlayCallback cdecl ( ... for portability to windows.
examples/sound/portaudio-sine.bas
Outdated
|
|
||
| pe = Pa_OpenDefaultStream(@stream, 0, 1, paInt32, SampleRate, SineSamples, @PlayCallback, @payload) | ||
| If pe <> paNoError Then | ||
| Print "Error: "; Pa_GetErrorText(pe) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pa_GetErrorText(pe) here and a few other locations below are missing the dereference * to print the pointed to string. i.e. *Pa_GetErrorText(pe)
|
I tried this example on windows after hacking together a static library compiled from sources from https://github.com/PortAudio/portaudio This example worked for me on windows 32 bit. I didn't try 64-bit. Only issue I had with the example itself is that it worked on 48000Hz samplerate, but not 44100Hz. Don't know if that issue is windows thing or a hardware thing or I missed something building the library. |
- 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
Fished out a Win32 vm and I think it was a latency issue where the stream was stopped before it started playing. The callback wasn't called at all when testing portaudio with the Win MM API (I couldn't compile it with WASAPI or DX). So now it's 3 notes that play for longer and prints out the API name. Sounds a bit clippy on Windows, but should be good enough as an API example. The original sequence was meant as the game over sound, but the buffer playback needs to be more clever to keep the stream open. |
|
Thank-you for the fix ups and the extra testing. I agree is good enough for a start point and should not be too difficult for users to play test on various windows versions and hardware to find what works with error messages shown. Thanks. |
PortAudio already has a FB header, this adds an example usage to play a sine wave from a buffer.