Playing a computed waveform

Hi,

Is there a way in which a computed waveform, e.g., a sinusoid, can be played by a Xojo app?

I shall be grateful for any information pertaining to the above,

Strange

What OS? I’ve been doing this with declares on the mac but I can’t be sure how safe it is. You might have to go for a plugin.

Will - I’d be interested to see how you did that.

I’m running OS X 10.10.2.

Strange

It’s currently in flux. I asked about the problem here with a link to an example but I’ve improved/cleaned it much in the last couple days. It seems to be working OK if all tests of the Ptr are of the form “if Integer(theAQ) = 0 then”. I asked this on the NUG too and got a couple responses I need to investigate.

Out of couriosity, what is what you want to play? A note? (I mean, the frequency of the sinusoidal function?)

Just trying to understand what you are doing and learn something new, also today. :slight_smile:

Thanks

Julen

[quote=168015:@Strange Ross]Hi,

Is there a way in which a computed waveform, e.g., a sinusoid, can be played by a Xojo app?

I shall be grateful for any information pertaining to the above,

Strange[/quote]

There is nothing in Xojo permitting you to directly generate a waweform an play it.
These are the options:

Sound class permits you to play a sound file. So for example you can first save generated sounds on disk and then play.
NotePlayer class is a MIDI notes generator

Other than that, you can use the MBS plugin which include a PortAudio plugin permitting this and much more.
Or you can wrap methods from the PortAudio library directly (http://www.portaudio.com). Not reccomended.

Hi Julen I,

I want to perform some psycho-acoustic experiments in which a subject will compare the loudnesses of two different trains of Gaussian pulses.

And Massimo Valle,

Thanks for your information, which was very helpful.

Strange

[quote=168213:@Strange Ross]Hi Julen I,

I want to perform some psycho-acoustic experiments in which a subject will compare the loudnesses of two different trains of Gaussian pulses.[/quote]

Then you definitely need PortAudio.

I think our PortAudio example plays already a sinus sound :slight_smile:

Whats a sinus sound?

it generates a tone by sampling a sinus curve.

What’s wrong with that? Why not recommended?

Callbacks on threads can cause problems in Xojo as the framework is not reentrant.
For that I put a lot of work into my plugin to get things working well.

Thanks Christian. So you’re saying no callbacks in Xojo are safe? I ask because i’ve used OS callbacks in places without problem so far. But other places there were problems :stuck_out_tongue:

you’ll run into crashes sooner or later.

The only safe callbacks are those which happen on the main thread, I believe.

Hmm, the callbacks I use are on the main thread and I don’t use new Threads very often so I guess that’s why they’ve been stable. I’ve used ObjC Runtime built objects implemented with Xojo methods (which MacOSLib does) and they seem to be fine. If the restriction is it has to be the main thread I can live with that.

I’ve successfully implemented callbacks without incurring in crashes (until now) and in past I also wrapped some part of PortAudio, but it’s a dirty work. That’s why my advice.
The MBS version is much better I believe.

it’s simple for playing sound: You get a callback about 100 times a second on a non Xojo thread and it is quite likely you do something in your callback which may crash like object locking.