Preloading Sound Files
Author |
Message |
Mogball
|
Posted: Mon Jan 13, 2014 7:14 pm Post subject: Preloading Sound Files |
|
|
What is it you are trying to achieve?
To preload sound files into Turing and then use them later in a program/
What is the problem you are having?
Unable to find a method of doing so.
Describe what you have tried to solve this problem
Searching through the Turing Documentation, searching the Internet, consulting seniors and teachers, and investigating the Turing predefined Music module.
Looking into the predefined module, it seems a procedure to achieve this is "not yet implemented" - it is called Music.PreLoad (filePath). However, a senior classmate tells me that he was, at one point, able to achieve this sort of thing with help from a different teacher, yet he is unable to recall that method.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I am using a process to play a sound effect, for example, an explosion, throughout a game.
Turing: |
process effectSound (effectFileName : string)
Music.PlayFile (effectFileName )
end effectSound
.. .
effectSound ("boom.mp3")
|
Please specify what version of Turing you are using
4.1
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dreadnought
|
Posted: Mon Jan 13, 2014 9:27 pm Post subject: Re: Preloading Sound Files |
|
|
I've tried using Music.PreLoad but I'm not convinced that it actually does anything...
You could try using WAV files for your sound effects since they are basically not encoded.
The only way I can imagine that you could "preload" would be to play the file and stop it immediately at the start of you program (this might load the file into memory which would speed up future access to it).
|
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Tue Jan 14, 2014 1:00 am Post subject: Re: Preloading Sound Files |
|
|
Mogball @ Mon Jan 13, 2014 7:14 pm wrote:
Describe what you have tried to solve this problem
Searching through the Turing Documentation, searching the Internet, consulting seniors and teachers, and investigating the Turing predefined Music module.
It's refreshing to see a honest attempt at solving the problem, but...
Mogball @ Mon Jan 13, 2014 7:14 pm wrote: What is it you are trying to achieve?
To preload sound files into Turing and then use them later in a program/
That's not exactly your actual problem. This is your approach to solve a problem. Why are you trying to preload sound files? Perhaps the current approach is too slow? Other languages/frameworks would indeed suggest preloading game assets, for quicker access.
Is your example
code: |
effectSound ("boom.mp3")
|
really too slow?
There are a number of things to try:
- make sure you don't have unexpected delay somewhere else in the code
- minimize the use of process, it could be that some other code is scheduled to run first
- perhaps Music.PlayFileReturn is faster than Music.PlayFile inside of process? I don't know the implementation of the former, but worth testing out
- try a smaller file size and/or different encoding/format
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
choltfo
|
Posted: Mon May 12, 2014 1:43 pm Post subject: RE:Preloading Sound Files |
|
|
I must say, the Music.PlayFile("BLAH.mp3") is horrendously slow. When I try to play, say, a gunshot, there is a lagspike.
Worse, but only somewhat related, playing a background MIDI file slows it to an unplayable rate. Any ideas?
|
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Mon May 12, 2014 6:11 pm Post subject: RE:Preloading Sound Files |
|
|
Use WAVs. Music.PreLoad does jack shit using Turing 4.1.1
Turing: |
proc runMP3
Music.PlayFile (mp3Filename )
end runMP3
proc testMP3
testit (runMP3, timesPerTest, "mp3")
end testMP3
proc testPreloadMP3
Music.PreLoad (mp3Filename )
testit (runMP3, timesPerTest, "preload mp3")
end testPreloadMP3
|
code: |
---
Closed and reopened Turing
---
preload mp3 #1: 454
preload mp3 #2: 440
preload mp3 #3: 487
preload mp3 #4: 399
preload mp3 #5: 378
preload mp3 #6: 378
preload mp3 #7: 404
preload mp3 #8: 373
preload mp3 #9: 376
preload mp3 #10: 375
---
Closed and reopened Turing
---
wav #1: 274
wav #2: 267
wav #3: 260
wav #4: 259
wav #5: 261
wav #6: 267
wav #7: 279
wav #8: 260
wav #9: 260
wav #10: 278
|
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
TuringMusicTests.zip |
Filesize: |
15.65 KB |
Downloaded: |
74 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|
|