Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 07, 2019 10:24 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Help grasping PortAudioStreamBufferedMBS internal buffering.
PostPosted: Wed Oct 06, 2010 8:01 am 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
I am trying to grasp PortAudioStreamBufferedMBS (to use it to play long soundfiles gapless) but I am confused and don't understand what I am dealing with (how it ticks inside)...

-Does it work by double buffering (the memoryblock included), so when I add the first memoryblock, it is quickly copied to an internal buffer and ready to be started playing, while ready for the next memoryblock (long before finishing playing the first)?
-Can/should I keep feeding my to-be-gapless sounddatastream through the same memoryblock?
-Is there space for more than one memoryblock from the same stream in the internal buffer?
-Will the size of the internal buffer become as large as the memoryblock automatically?

I suppose I will need to keep track of the internal buffer as I will be playing very long files. -Monitoring OutputPositionRelative_as_Double would be a way I guess. -If I keep having only one internal buffer, could I start loading a new memoryblock to it (the queue, if there is one) when it is, say, half way through playing that buffer so that new data gets there in time without gaps caused?
It also says "May point between samples". What does "may" mean?

Then:

AddAudio() as boolean.

AddAudio adds audio the queue...
-But what do I do with "as boolean"?


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Wed Oct 06, 2010 9:21 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Well, AddAudio adds samples. They are copied into a new buffer and this new buffer is added to the list of buffers.
Copying data to this buffer does not disturb playback. Just queueing the buffer does, but that is so fast, you won't ever hear it.

So you can feed the same memoryblock again and again. Watch the queue with FreeSpace property.

I think the list of buffers is 200 entries big currently. If you feed 1 MB blocks, you can have 200 MB of audio data.

If we play 48000 Hz music on a 42000 Hz device, the OutputPosition can point between two samples. It's a floating point number which can have non integer values. It moves forward in 48000/42000 steps.

I hope that answers your questions.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Sat Oct 09, 2010 12:59 pm 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
Thank you!
-Buffering is exactly the way I want it, it guess.

Taking your play audio example, I have extracted it to a minimum to get my test up and running, taking the audio from a file.
So far (took most of the day) I finally got some audio out of it (file-> binarystream-> memoryblock-> addaudio), but I am still struggeling with addaudio (the same with playaudio).

In your example you are using addaudio and then start. (Start is not mentioned under PortAudioStreamBufferedMBS in the pdf, so I nil info on that one.)
-It seems that I need to have both addaudio and start in a loop for some reason (the same with playaudio). If this loop is too quick nothing or only a part of the audio is played, if it is too long it is looping the buffer. I tried to run addaudio and the condition and move start to after the loop, testing to understand the mechanism, but then nothing happens. I also tried some delays in between, but that didn't get it up and running. It just skips the playing.
It this something I need to keep track of in some way. It seems that it is not just to fire start and a continous loop is not a good way as it will eat processor power. How am I supposed to keep the playing process going in an efficient way?
Can you shine some light on what addaudio+start and playaudio needs to operate in a good way?


This one plays for about a second on my MacMini 2,53. Why?

c=new PortAudioStreamBufferedMBS
e=c.OpenDefaultStream(2,44100)

for i=0 to 2000
if not c.AddAudio(mb, 0, 0, 15, false) then
MsgBox "Failed to play audio!"
Return
else
e=c.Start
end if
next i
------------
So does this one (play audio instead of addaudio version):
for i=0 to 2000
if c.PlayAudio(mb, 0, 0, 15, false) then
end if
next i


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Mon Oct 11, 2010 10:36 am 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
I have been reading through the MBS audio plugin pdf, but I can not get into my head why I need to keep running a loop around playaudio (same with addaudio). It doesn't make sense.

The pdf says about addaudio: -Adds audio to the queue and starts playback.
So I do that and nothing happens, unless I keep telling it to playaudio-playaudio-playaudio-playaudio-playaudio-for as long as it is playing.

-So, why do I have to keep checking the boolean response of playaudio for it to continue to play? Am I refreshing something? -If so, how often do I have to do that? What am I to do? -Help!

c=new PortAudioStreamBufferedMBS
e=c.OpenDefaultStream(2,44100)

for i=0 to 2000
if c.PlayAudio(mb, 0, 0, 15, false) then
end if
next i


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Mon Oct 11, 2010 10:59 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
you should not need to call PlayAudio. Or you found a bug. Does that happen with our samples, too?

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Mon Oct 11, 2010 12:41 pm 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
Well, your sample code (the one I extracted) has the addaudio inside a loop (which also contains a sinewave generator). It doesn't use a sample, it outputs the sinewave it just generated. I didn't find an example that loads sampled audio.

How am I supposed to use playaudio (and addaudio with its associated start)?
(start is not documented under PORTAUDIOSTREAMBUFFEREDMBS).

A Logical way from my point of view to play a stereo sound once would be:
c=new PortAudioStreamBufferedMBS
e=c.OpenDefaultStream(2,44100)
c.PlayAudio(mb, 0, 0, 15, false)

If I try that (without it running inside a contimous lopp) I get when trying to run the code: "You must use the value returned by this function c.PlayAudio(mb, 0, 0, 15, false)".
-Why do I have to use the boolean that comes out of it?


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Mon Oct 11, 2010 12:48 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
The boolean tells you whether the data was queued correctly and starting the playback worked.

You can ignore it by using the call keyword.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Mon Oct 11, 2010 1:01 pm 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
As before it doesn't output anything unless placed in a loop.
The looped version seems to be doing something during the playing time: -I placed the code in the window and the window appears on screen delayed, appearing after the sounds play time passed. It is like it is playing but not outputting. If I remove the playaudio-part, the window pops up instantly.

Completely quiet:
c=new PortAudioStreamBufferedMBS
e=c.OpenDefaultStream(2,44100)

call c.PlayAudio(mb, 0, 0, 15, false)

Replacing the above with this it plays for half a second or so (as soon as i=1000 it mutes):
c=new PortAudioStreamBufferedMBS
e=c.OpenDefaultStream(2,44100)

for i=0 to 1000
if c.PlayAudio(mb, 0, 0, 15, false) then
end if
next i


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Mon Oct 11, 2010 4:54 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Well, I modified my "Movie Sounddata" sample project and I get it to loop easily.

If you email me, I can send you a copy.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Tue Oct 12, 2010 1:06 am 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
Thanks. Done.

If loading a larger sound file the delay of the window, described above, doesn't happen (when using playaudio not inside a loop). It seems to skip right through.

I am using it on a Macmini 2.53 OS 10.6.4, but I also tried it on Ubuntu, with the same result, on the same Macmini.


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Tue Oct 12, 2010 4:01 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
You need to make "c as PortAudioStreamBufferedMBS" as property of the window or a global variable. Else on the end of the method, the object is killed and sound stops.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Help grasping PortAudioStreamBufferedMBS internal buffer
PostPosted: Tue Oct 12, 2010 6:17 am 
Offline

Joined: Tue Oct 13, 2009 4:21 am
Posts: 46
Yep. That did it.

In the mean time I found that your "movie sounddata" wasn't that helpful to solve my problem/understanding since it kept feeding the addaudio in small chunks.
But after testing that I found that if that if I ran c.PlayAudio(mb, 0, 0, 15, false) a second time with a delay in between it would play. -Once. .... -Weird!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group