• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Is there a way to produce sound with Java?

 
Ranch Hand
Posts: 253
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:What is an example of command line arguments that you're using?
Edit: sorry I missed your comment at the end.


java Synth 96 6 0 127 6500
 
Kevin Simonson
Ranch Hand
Posts: 253
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:What is "rsltn" ?


Resolution. I guess I should have spelled it out.
 
Kevin Simonson
Ranch Hand
Posts: 253
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kevin Simonson wrote:

Carey Brown wrote:What is an example of command line arguments that you're using?
Edit: sorry I missed your comment at the end.


java Synth 96 6 0 127 6500


Although I think what I'm going to go with for my game is probably:

java Synth 96 7 0 127 5500
 
Carey Brown
Bartender
Posts: 11115
88
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might consider dropping the last command line argument and changing your sleep() call to

 
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, you shouldn't be using Thread.sleep() at all. If you want to block the current thread until the track has finished playing, you should use locks and conditions and add a meta event listener to the sequencer.
 
Kevin Simonson
Ranch Hand
Posts: 253
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Actually, you shouldn't be using Thread.sleep() at all. If you want to block the current thread until the track has finished playing, you should use locks and conditions and add a meta event listener to the sequencer.


Stephan, can you tell me where I can go to find out how to "use locks and conditions" and adding "a meta event listener to the sequencer"? Are those things new to Java 8 or Java 9? I'm mostly familiar with Java 6 and 7, and I don't remember anything about locks, conditions, or meta event listeners.
 
Marshal
Posts: 80775
489
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Threads and locks go back to Java1.0.0. Try the Java™ Tutorials. Don't know about meta‑listeners.
 
Stephan van Hulst
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The high-level concurrency library was added in Java 5. The classes I'm referring to specifically are java.util.concurrent.locks.ReentrantLock and java.util.concurrent.locks.Condition. You can create a class that is responsible for playing a sequence and blocking until it's done:
 
Stephan van Hulst
Bartender
Posts: 15741
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, let's say that you expanded your application and you want to start playing your melody in the background when something happens and you want to continue doing things in the mean time, but when the application has finished, you want it to wait until the melody has finished playing. You would then use an ExecutorService to play your melody. Add this method to the SequencePlayer:

As long as the threads in the executor service are not daemons, any melodies that started playing will continue playing when the executor service is shut down. That will give you very gracious termination of your application.

Note that I haven't tested this code or that in the previous post. There may be some mistakes I haven't thought of.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic