Need a really simple library for playing sounds and music? Try TinySound.

That seems a little odd, though I guess a call to gc() is just supposed to be a suggestion. How are you computing your memory usage? Are you subtracting free memory from total memory?

No I have been just using task manager. Which is not the most accurate. I checked to see if gc was being called and it is. I also think that ogg files seem to use more ram then .wav

What should it be around with 3 sound files all around a minute long?

Ah, I see. That will give you a rough idea of how much memory has been allocated to the JVM, but not necessarily how much is actually in use. If you want to determine how much memory the JVM is using, try this little snippet:


double mbInUse = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000000.0;

Well, after they’re loaded into memory and converted, that would be 3 minutes of 16-bit, 44.1 kHz stereo, linear PCM. That means there are 4 bytes per frame (2 bytes for each channel), and 7,938,000 total frames (44.1 kHz * 180 sec). That comes to a total of 31,752,000 bytes, or 31.752 MB. Of course, that’s if the data actually stays in memory as is default in TinySound. With the streaming code, the memory used should be equivalent to however much the streams have buffered in memory at any one time (which is probably something like 8 kB each).

hmmm…I guess meh program is why more efficient then I thought. 10m-60m That is if that snippet gives it back in megabytes. :wink:

I have a lot of GC going around I think because I am not using object pooling with my particle system. I don’t know if that would give a speed boost if I did but it would really cut down on GC.

So to bench mark you library a little I have to I can switch between pauls library and yours as my back-end when it comes to managing sound. Right now his loads faster (and of course can to all that 3d mumbo jumbo) almost instant but the quality memory usage are almost the exact same. Your library right now I think is the best option for getting sound into a game or app with next to no hassle. I ran into a munch of walls getting pauls to work mainly because he does not really explain how to set everything up outside of the code.

Edit:
Time for tiny sound to load/stream 3 sound files that add up to 1675kb using .ogg compression. 3600-3700ms (due to tiny having to copy files into temp folder)
Time for paulscode to load/stream same files. 0ms. (Due to pauls streaming files from current location…i think)

Tiny needs a larger heap then pauls but after words memory usage is about the same.

Time to setup tiny with no experience 5-10 minutes including dl time.
Time to setup pauls with no experience 30-75 minutes including dl time.

With experience they would be about the same. Pauls requires I little more management in code but gives more features.

Right now I like both a lot but due to the smallness of tiny I am leaning that way more until I need to make something that requires the robustness of pauls. tiny sound with everything is like 200-300kbs pauls goes into the megs because it requires natives and if you are using his you should be using LWJGL or JOGL (idk if that is the right name).

Requested features from Tiny:
Global volume. Right now I just loop through all loaded sounds and set the volume but a global would be nice.
Because the Music lets you loop sounds where the regular Sound does not I only use music because I want to loop not music files at times. Could you add looping to regular sounds? or make only one sound type that does it all? Idk just suggestion.

This is very helpful! I used this as my first attempt at adding music and sound to anything, and it works very well. I haven’t added sound yet (just music at this time), but I did set up a music player that plays a random song in the list, waits until it’s done, then plays a random new one from the list. Thank you!

If anyone wants to know what you can do with this here is an example game I have made where all sound is done with Tiny.

http://www.java-gaming.org/index.php/topic,26972.msg239429.html#msg239429

I am rather impressed. Loading could be a little faster but it works with almost no effort.

Awesome work! I used your library on my game. It was very easy to understand and use. Exactly what I was looking for.

Wow, thanks guys. I haven’t been on in a while, so I hadn’t yet seen these posts. I really appreciate the comments.

Edit:
StrumpyStrust, that is super cool. I really like your particle effects.

Sorry I took so long to respond. I’ve been busy with research and another project that I’ve been working on for a friend. The global volume is such a good idea, I just added it tonight and you can find it on the same branch that I’ve been working on for streaming sounds. It doesn’t change the volume of all the Sounds and Musics, but instead acts as a global multiplier to the individual volume settings.
I’ve considered adding the ability to specify a fixed number of times to loop a sound when you call the play method. The reason I didn’t add continuous looping to Sounds in the first place is because I intended for them to be played in potentially overlapping fashion. In order to control the looping of a particular playing instance, you would need a reference to it for each call to play(). Would the ability to have a particular playing instance loop for a fixed number of times suit your needs?

Any chance we’ll see panning functionality in the future of TinySound?

I suppose that’s a possibility if I can find a good resource for the math involved, or if I can figure it out for myself.

Woot global sound and ty for the complement.

Another thing I ran into while adding sound to the game was having more then one song. I wanted it so when a song ended the next one would start. But you had no methods that would tell me if a sound has ended its playing. The one method called I think playing() always return true if the sound had been played even if it hit the end.

(Reply to above post)

You can make your own system for that, considering you can calculate minutes:seconds (that is mainly shown when looking at the length of a song) to milliseconds. Here is the code of the system that I made. There are 6 songs, and I just wrote down the millisecond length of all of the songs. Could it be simpler? Yes, if TinySound let us know when the song ended, but it’s still pretty simple to make your own system to playing a new song every time the previous one ends. By the way, TestMusic[] has 6 elements and it is a Music variable.


	public void startLoadingSound(){
		int song = rand.nextInt(6);
		System.out.println(song);
		TestMusic[song].play(false);
		delay(song);
	}
	private void delay(int song){
        Long delay = getDelayTime(song);
        Timer timer = new Timer();
        timer.schedule(new TimerTask(){
        	public void run(){
                addSong(rand.nextInt(6));
        	}
        }, delay);
	}
	private Long getDelayTime(int song){
		Long time = 0L;
		if(song == 0)time = 82000L;
		if(song == 1)time = 298000L;
		if(song == 2)time = 313000L;
		if(song == 3)time = 265000L;
		if(song == 4)time = 271000L;
		if(song == 5)time = 102000L;
		return time;
	}
	private void addSong(int song){
		System.out.println(song);
		TestMusic[song].play(false);
		delay(song);
	}

Yup. I was going to code something like that next but decided not to. Sure you can do everything Tiny does yourself but that would defeat the purpose of a library. I am just saying it would be a nice feature to add.

I apologize for disappearing again for so long. You make a good point, so I’ve added a done() method to the Music interface which will tell you when the Music has finished. I’ve also fixed Music to stop “playing” when it’s finished, as you mentioned the issue with playing() always returning true if you haven’t called stop(). Note that you will have to call rewind() to set a Music back to the beginning. All of these changes are on the streams_and_redesign branch. Again, sorry for disappearing. I’ve had a lot on my plate.

The second you make a panning-system, this will become my main sound-library, and though shall get much praise in my credits :smiley:
Oh, and the ability to enable random pitching within a specific range. I’d love that!

Well, I didn’t add random pitching, but I did add panning and it can be found on the streams_and_redesign branch (I’ll eventually merge it to the trunk). Give it a go and see what you think. I’m not entirely sure how panning is normally implemented, but you can set a pan value in the range [-1.0,1.0]. 0.0 plays normally, whereas a negative or positive value shifts a proportional amount of one channel to the opposite. More specifically, a value of -0.25 will shift 25% of the right channel to the left channel. Note that panning to the left doesn’t change the gain on the original left channel audio at all. It only affects how much of the right channel is shifted. The analogous situation goes for panning right.

That’s perfect! Just what I needed!

Yo, kuusisto!

You can and should (I think) post you library on this wiki:

I didn’t learn until maybe a week ago that anyone can edit these wiki screens. Then, it took me until now to remember I had asked about this in terms of your sound library.

Riven has a list of rules posted on the thread to abide by before posting your library. But I think yours qualifies, now that there are several people using it.

On the game I used this library, I credited with your name. If you have a website with this library hosted, I would like to know so I can add a link on my citation.

Thanks.