# MBS Audio stopping

**URL:** <https://forum.xojo.com/t/mbs-audio-stopping/81763>\
**Category:** Plugins\
**Created:** [September 14, 2024, 1:13pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763 "2024-09-14T13:13:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Klingler](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_klingler/32/8198_2.png) [@Richard\_Klingler](https://forum.xojo.com/u/Richard_Klingler)\
**Post date:** [September 14, 2024, 1:13pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/1 "2024-09-14T13:13:59Z")

</div>

Okay…found some time to test the MBS Audio plugin…  
And with a little tweaking I get the sweep sine wave with the Port Audio example app.

The Callback looks like this now to generate the sweep:

```auto
Var n,c,i As Integer
Var f As Single
Var increment As Single = frequency / 7639.437

PlayWindow.FrequencyLabel.Text = Str(frequency) + " Hz"

c=FrameCount-1
for i=0 to c
  sinIndex = sinIndex + increment
  if sinIndex>2*3.1415926 then sinIndex=sinIndex-2*3.1415926
  f = sin(sinIndex) / 2
  
  outputBuffer.SingleValue(n)=f // left
  n=n+4
  outputBuffer.SingleValue(n)=f // right
  n=n+4
next

If frequency <= 20000 then frequency = frequency + 20

```

Tried to stop the audio with a simple PlayWindow.Close as there is this Close event:

```auto
dim e as integer
if s<>nil then
  e=s.Stop
  e=s.Close
end if

```

But of course the app just hangs…  
What is the correct way to stop the audio?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [September 14, 2024, 1:21pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/2 "2024-09-14T13:21:34Z")

</div>

Can you send me the test project to debug?

Your callback does have “#pragma” lines to disable background tasks?

---

<div class="post-metadata">

**Author:** ![Richard\_Klingler](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_klingler/32/8198_2.png) [@Richard\_Klingler](https://forum.xojo.com/u/Richard_Klingler)\
**Post date:** [September 14, 2024, 1:26pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/3 "2024-09-14T13:26:08Z")

</div>

Yes…those are unchanged from the PortAudio example.

[PortAudio.zip](https://forum.xojo.com/uploads/short-url/wg0sUdIrEIx4wIAY0NpGXyDHn4X.zip) (37.0 KB)

Ops…forgot the Info.plist

[info.plist.zip](https://forum.xojo.com/uploads/short-url/wzDJXWgurg6bJDWNhFFRXvcRZjj.zip) (866 Bytes)

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [September 14, 2024, 1:48pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/4 "2024-09-14T13:48:52Z")

</div>

Strange. Doesn’t happen here on macOS or Windows as far as I see.

Anyway, I see that the example does call abort or window.close from callback, which should not happen.

---

<div class="post-metadata">

**Author:** ![Richard\_Klingler](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_klingler/32/8198_2.png) [@Richard\_Klingler](https://forum.xojo.com/u/Richard_Klingler)\
**Post date:** [September 14, 2024, 1:53pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/5 "2024-09-14T13:53:10Z")

</div>

Happens on my MacStudio and Macbook Air here…

Is there a better way to stop the audio output when the sweep is through?

PS: Currently cooking sweet&sour and my girlfriend comes home soon…so a while afk (o;

---

<div class="post-metadata">

**Author:** ![Richard\_Klingler](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_klingler/32/8198_2.png) [@Richard\_Klingler](https://forum.xojo.com/u/Richard_Klingler)\
**Post date:** [September 14, 2024, 5:50pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/6 "2024-09-14T17:50:04Z")

</div>

Okay…either have to study the docs more or switch to another solution (o;

But sweet&sour was fine (o;

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [September 14, 2024, 8:29pm UTC](https://forum.xojo.com/t/mbs-audio-stopping/81763/7 "2024-09-14T20:29:20Z")

</div>

Well, if you like to have an easier live, don’t use the playback via callback, but via queue. That is easier.

See [PortAudioStreamBufferedMBS](https://www.monkeybreadsoftware.net/class-portaudiostreambufferedmbs.shtml) class with buffer.
