• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Is there a way to produce sound with Java?

 
Saloon Keeper
Posts: 10929
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Ranch Hand
Posts: 249
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: 249
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: 249
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
Saloon Keeper
Posts: 10929
87
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

 
Saloon Keeper
Posts: 15727
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: 249
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: 79956
396
  • 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
Saloon Keeper
Posts: 15727
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
Saloon Keeper
Posts: 15727
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.
 
His brain is the size of a cherry pit! About the size of this ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic