PortAudio MBS

Hi Christian,

I want to use a slightly changed run method that you have in your example (PortAudio)

I want to present two sinus sonds with a given duration with a pause between them. After playing a sinus sound I got always something like a stopping “click” in the sound. The sinus sound does not end with silence it ends with something like a “click” or “crack”. Is there a possibility to prevent this (or why does this happens?).

At the moment I use XOJO Version 2016 1.1 on my Mac but I also want to use the sinus sound presentation on Windows OS.

This is my currently code:

    dim e as integer
    
    p=new PortAudioMBS
    
    s1=new MyPortAudioGenerateStreamMBS
    
    for i as integer = 0 to aSinusPitch.Ubound
      tones.pitch = aSinusPitch(i) // e.g. 1000 Hz
      tones.duration = aDuration(i) // e.g. 0.3 seconds
      tones.pauseBetween = aPauseBetween(i) // e.g. 0.5 seconds
      
     // tones.paFloat32 ==>      const paFloat32 = 1
     // tones.rate ==> 48000 
      e=s1.OpenDefaultStream(0,2,tones.paFloat32, tones.rate, 0, 0)
      
      System.DebugLog( "OpenDefaultStream: "+str(e) )
      if e=0 then
        e=s1.Start
        SetSoundMuteMBS( false )
        System.DebugLog( "Start: "+str(e) )
        e=s1.IsStreamActive
        System.DebugLog( "Active: "+str(e) )
        s1.UseSafeThreading=false
        SleepMBS(aDuration(i))
        SetSoundMuteMBS( true )
        SetSoundVolumeMBS(0)
        e=s1.Stop
        e=s1.Close
        SleepMBS(aPauseBetween(i))
  
      else
        System.DebugLog( "Host Error: "+str(s1.HostError) )
      end if

    next i
    

Any help is appreciated. Thank you.
Thomas

Does your sound wave in the memoryblock end with Null values?

I have inserted a System.DebugLog() in the Callback of MyPortAudioGenerateStreamMBS.
As far as I see there are no zero values at the end of the sound:

f = 0.1564467
f = 0.0000124
f = -0.1564222
f = -0.3090052
f = -0.4539795

Best wishes
Thomas

Christian,

do you mean that I have to stop with f= 0.0000? So that I do not have a click/crack?

If so, how can I implement this? Or is there another way around?

What about 25 ms ramps at the beginning and end of a 300 ms sinus sound? What will be a good implementation of a fade in/fase out sinus (25 ms) wave?

Any help is appreciated. Thank you.
Thomas

I have no real idea where your click is coming from.
But if you output sound and suddenly stop, that could cause a click sound.

You could just end when your last wave comes back to zero.