Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Since I've given up on JavaSound...  (Read 1271 times)
0 Members and 1 Guest are viewing this topic.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Posted 2005-05-31 06:49:38 »

...I'm trying to convert my work to OpenAL. So far I've implemented an OpenAL version of Clip, which was fairly simple and works great (almost no latency anymore!).
Now I'm trying to find a way to implement streaming, for realtime audio generation. For example my arcade emulator needs this, but also my audio synthesis library I'm working on.
I basically need an equivalent to this (code coming from my arcade emulator in an update() method which is called every frame):
1  
sourceDataLine.write(soundChip.getData(), 0, WRITE_BUF_SIZE * 2);


Very easy to do in JavaSound, but since JavaSound behaves very differently in every other version, it proved to be unusable. I've done enough tinkering with the sound code and now it doesn't seem to work again on java5 so I'm finally scrapping JavaSound in favour of OpenAL.

I've looked on the internet, but found almost nothing about this, just an overcomplicated technique was discussed somewhere but without any code samples.

Has anybody already done this already and even have a code sample?

Yes I know, I'm a lazy bum  Grin

Offline tom
« Reply #1 - Posted 2005-05-31 09:36:39 »

OggPlayer uses OpenAL to stream ogg files. You can look at its source and the OpenAL documentation on openal.org to figure how to do it.

Basicly you must set up a queue of 2 or more buffers. OpenAL lets you know when a buffer is finished playing. You then unqueue the buffer, fill it with your data and add it at the end of the queue.

Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2005-05-31 13:55:32 »

Fantastic, thanks Tom!  Cheesy

Do you know if there are any constraints in the size of the buffers? No power of 2 or anything? I'm asking because I'm thinking about 2 buffers, exactly the size needed for one frame (so usually 1/60th second of 44.1khz sound), so that I can queue a new buffer every frame.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2005-05-31 14:30:01 »

There is no restrictions on the size of the buffers as far as I can tell.

You need to use more than 2 buffers if you intend to queue a new buffer every frame. It is unlikely that you can manage to synchronize the buffer swaps exactly with the display. You also need to guard yourself against pauses caused by the GC or other background processes.

Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (108 views)
2017-09-30 02:57:34

theagentd (135 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (240 views)
2017-08-02 12:19:43

cybrmynd (238 views)
2017-08-02 12:18:09

Sralse (252 views)
2017-07-25 17:13:48

Archive (864 views)
2017-04-27 17:45:51

buddyBro (1007 views)
2017-04-05 03:38:00

CopyableCougar4 (1566 views)
2017-03-24 15:39:42

theagentd (1373 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!