Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Preloading Sound Files
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Mogball




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: 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).
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
choltfo




PostPosted: 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?
Zren




PostPosted: 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



TuringMusicTests.zip
 Description:

Download
 Filename:  TuringMusicTests.zip
 Filesize:  15.65 KB
 Downloaded:  72 Time(s)

Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: