Skip to content

Conversation

@thekhalifa
Copy link
Contributor

PortAudio already has a FB header, this adds an example usage to play a sine wave from a buffer.

PortAudio already has a FB header, this adds an example
usage to play a sine wave from a buffer.
frequency As Single
End Type

Function PlayCallback (InputBuff as Const Any Ptr, OutputBuff as Any Ptr, _
Copy link
Member

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.


pe = Pa_OpenDefaultStream(@stream, 0, 1, paInt32, SampleRate, SineSamples, @PlayCallback, @payload)
If pe <> paNoError Then
Print "Error: "; Pa_GetErrorText(pe)
Copy link
Member

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)

@jayrm
Copy link
Member

jayrm commented Mar 3, 2025

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
@thekhalifa
Copy link
Contributor Author

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.

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.

@jayrm
Copy link
Member

jayrm commented Mar 15, 2025

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.

@jayrm jayrm merged commit d64649a into freebasic:master Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants