Playing Longer Audio: Streaming
If we have a longer audio file, like one that contains a full-length song, we may want to load our file via the LoadToStream action. The LoadToStream action allows our audio file to be loaded in "chunks,"as they are needed instead of all at once. This is more efficient and allows the file to start playing more quickly than if it must wait for the entire audio file to be loaded, especially for longer sounds, like songs. In order to stream our Audio object, we will need a loop that keeps the Audio object streaming as long as it is playing. An example of this follows:
// this line creates our Audio object we will be using to stream
// this line loads a "chunk"of the data from the file "LongSong.ogg"to our Audio object
// this line plays the first "chunk"of the data that was loaded from the file
// this loop will continuously check if the whole song has been played
repeat while streamingAudio:IsPlaying()
// this gets the next "chunk"of data to play
A Quorum File object can also be used instead of a text file path when calling the LoadToStream action.
If we are playing sound as part of a game using the Quorum Game Engine, the proper place to put the Stream() call is inside the Update action, which is called every frame in the Main Game Loop. This will ensure that the next "chunk"of sound will be loaded at every opportunity. An example of streaming in the game engine follows:
class Main is Game
action Update(number seconds)
//since this action is in the main game loop and called every frame it should not be inside another loop.
In the next tutorial, we will discuss Digital Signal Processing, which describes signals and samples in Quorum..