Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Pew Pew Pew! Sound synthesis  (Read 8627 times)
0 Members and 1 Guest are viewing this topic.
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Posted 2008-01-23 21:55:12 »

I started out trying to make a straight port of the excellent SFXR, but quickly got tired of picking through opaquely-named variables, and so made my own sound synthesis doodad instead.

Behold!


Download the jar here.

A rundown of what does what:
The black panels control the value of some variable over time. Left click on them to add a point, right click to remove the closest point, and the points are draggable too. The top 4 panels should be self-explanatory, the fifth shows the effect of the vibrato on the final sound frequency, the final two control the delightfully-named flange effect.
Used to great effect by Hendrix and Procol Harum, flanging overlays the signal with a delayed version of itself, creating some weird effects.
The delay panel controls how delayed the overlay is, while the alpha panel controls how much of the delayed signal is added.

The "Signal" combobox controls the waveform of the sound, the "Vibrato" combobox controls the waveform of the vibrato that's added to the base frequency, length controls the duration of the sound, in seconds.
"Export" saves the sound as a wav, "Play" plays the sound, and "Save" saves the data needed to recreate the sound if you want to generate it at runtime, like so:

1  
2  
TerrainSound ts = new TerrainSound( getClass().getClassLoader().getResourceAsStream( mySoundFilename ) );
ByteBuffer littleEndian16BitPCMData = ts.generate( 44100 );


All the code is available here.

If you're hardcore and want to define the sound in code, you can do that too:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
SoundSpec ss = new SoundSpec();

ss.volumeEnvelope = new Variable() {
   public float getValue( float time )
   {
      return the volume at that time;
   }
};
ss.waveform = new Waveform( ) {
   public float valueForPhase( float phase )
   {
      return the value at this point in a wave, eg sin( 2*PI*phase);
   }      
};
ss.waveform.frequency = new Variable( ) {
   public float getValue( float time )
   {
      return the frequency at that time;
   }
};
ss.length = foo;
ss.postProcess = new PostProcess( ) {
   public void process( ShortBuffer data, int sampleRate )
   {
      postprocesses are optional, but feel free to monkey with the data samples how you like
   }
};
     
ByteBuffer littleEndian16bitPCMData = ss.generate( 44100 );


Enjoy!
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2008-01-23 23:20:37 »

Awesomeness! /me saves next to SFXR  Grin

Any chance of adding some random and mutate buttons? They were the best features of SFXR for a non-sound-inclined person like me.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline jojoh

JGO Knight


Medals: 5
Projects: 7


games4j.com


« Reply #2 - Posted 2008-01-23 23:21:14 »

Wow that is just soo brilliant!   Cool

Both great to be able to create some own sounds and I guess that is also makes it possible to compress sounds heavily (if you generate at runtime) for web based stuff or anywhere that size really matters. Especially if one wants some pac-man style sounds. Could you share some presets of different types if you have some? I am specifically looking for vehicle sounds that would be possible change revs in realtime or something that can be pregenerated that one can then slide between in realtime. An accelerating car for example. Is that what one can do with the code example? (Haven't tried it yet)

Sfxr also has the autogenerate certain types of sounds and mutate and randomize which was really great for me since I don't quite know what I am doing, but, can then start with a good idea and then mutate or try and error til it is good enough. Load would also be useful.

Thanks for sharing!


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #3 - Posted 2008-01-24 00:36:55 »

Usability stuff like load/random/mutate/presets/space to play will probably appear tomorrow, unless I know what's good for me and I work on my thesis instead (depressingly unlikely Undecided ).

File sizes if you're generating at runtime are tiny - 36 bytes + 8 bytes for every point you define versus tens of kilobytes for the generated pcm data. They could certainly be reduced more, but is it worth it? I'll leave it to the 4K-ers.

As to vehicle sounds: nothing presents itself off the top of my head, but I'd start by looking at low frequency noise, or perhaps a low hum with a noise vibrato.
Offline brackeen

Junior Member





« Reply #4 - Posted 2008-01-24 02:38:27 »

This is awesome! I'd like to second the idea of adding 'random' and 'mutate' buttons and also some presets Smiley

The code looks good, too. I'll definitely be keeping an eye on this.
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #5 - Posted 2008-01-24 17:56:09 »

Alrighty then, that's random/mutate/presets/loading added. Again, get the jar here.

I'm currently torn over whether to implement incremental sound generation. On one hand it's going to be a minor pain in the bum to do, on the other hand it would be nice not to have the delay when you click "play"...
Maybe later...
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 75
Projects: 15


★★★★★


« Reply #6 - Posted 2008-01-24 18:01:00 »

this is very cool, amazingly useful for indie games.
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #7 - Posted 2008-01-24 20:31:33 »

heh, this brings me back to my Amstrad CPC664 days and passing random values thru its 3 channel sound generator until i found something that sounded good and used it for a simple crappy games! (well i was about 9-10 at the time Smiley )

good work!
Offline darkprophet

Senior Member




Go Go Gadget Arms


« Reply #8 - Posted 2008-01-24 20:43:04 »

The explosion sounds *exactly* like the explosion from MGS1 on the PSX with the grenades....

Legend!

DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline brackeen

Junior Member





« Reply #9 - Posted 2008-01-25 03:34:39 »

Brilliant. The new version works on Mac OS X Java 5, too. Cheers!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #10 - Posted 2008-01-25 07:13:42 »

Brilliant. The new version works on Mac OS X Java 5, too. Cheers!

Good stuff! I was mildly worried about endian issues there. I had a bash at incremental generation, but it was difficult to apply postprocesses correctly and the SourceDataLine didn't seem to want to cooperate, so I rolled back the changes.

On to actually writing a game now I suppose...
Offline CommanderKeith
« Reply #11 - Posted 2008-01-28 08:32:21 »

Cool program, it's really quite funny!

Thanks for making it so easy to export stuff into a wav file  Smiley

PS: what's your thesis about (80's sound effects?!)

Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #12 - Posted 2008-01-28 09:23:31 »

I wish. It's on location algorithms for wireless sensor networks.
After four years, and now deep in a writing-up deathmarch, I'm desperate for diversions. Hence the recent burst of activity here as I finally get round to writing some gaming stuff: the sound generation, the texture packer and the font rendering. Coming next - a stupidly over-specified game of asteroids.
Offline CommanderKeith
« Reply #13 - Posted 2008-01-28 14:31:42 »

Hehe, well it's said that if you want something done, give it to a busy person  Tongue

I was the same when I was doing my honours thesis last year, I would just sit in the computer labs and stuff around in these forums, mostly watching what other people were looking at and checking it out... pretty sad but sometimes pretty interesting seeing the funny old things that people used to have heated discussions about!  I'd also lament how many cool things I could do if only I didn't have to do my thesis. At least you're actually making the cool things!

Apologies for the thread hijack, but is the 'location algorithms for wireless sensor networks' about finding people who are on their mobile phone?  Sounds cool enough.  My fun-packed thesis was 'The price and volume effects of off-market share buy backs in Australia'  Cry Sad

Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #14 - Posted 2008-01-28 18:57:47 »

Apologies for the thread hijack, but is the 'location algorithms for wireless sensor networks' about finding people who are on their mobile phone?

Similar, but much, much harder. In the particular flavour of WSN that I've been looking at, the nodes are very small (and so completely crap from a capability and reliability point of view), potentially mobile, and extremely numerous. I also can't rely on any infrastructure like cellphone masts, gps satellites or compute servers.
So it's all error-tolerant distributed algorithms, each node working out its location with respect to its neighbours, emergent behaviour, that kind of thing.
Offline kaoD

Senior Newbie





« Reply #15 - Posted 2010-08-20 15:04:39 »

I'm sorry for the bump, but SoundGen is exactly what I was looking for. Awesome stuff, I hope you're still around here! I love sound synthesis, so you made me want to set up a multi-instrument enviroment for my applet game Smiley

I want to buffer some random output for little sounds effects (like coin, powerup...) and pre-generate a tune. What would be better in each case, keeping ByteBuffers or Clips cached? I mean, the little wait time when clicking play in your app is caused by SoundSpec generation or in the Clip player? Is Clip much bigger in memory?
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #16 - Posted 2010-08-20 17:00:04 »

Howdy

The time for generation depends on the duration of the sound as you would expect, and it's always a good idea to avoid work when you can, so I would keep hold of the generated buffers.
I don't have enough experience with the javasound APIs to say much about clip objects, but I would be surprised if they were much more than a wrapper on top of the buffer.
Does anyone else know? Are Clip objects a limited resource like OpenAL sources?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (22 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!