I'm trying to write a little background program that stops music playing Winamp when another program plays sounds. The part about the accessing Winamp through Java is already solved now I need a way to detect which program plays the currently played sound (probably I want to allow some programs to play their sound without stopping my music). Although I'm doing this in Java (+ the winapi) everything in any language would help.
[edit] as I just got the first downvote on my first question here is some more detail: I already figured out how to use the winapi (but I don't know it) and capture things like volume levels and stuff. What still makes trouble is the mentioned detection of the origin of a sound that is played and aslo which program plays sounds. Is there anything in the winapi that could help me to do this?[/edit]
As Deanna mentioned, you can enumerate audio playback sessions just like Volume Mixer application (started from system tray icon) does and obtain per-session meters indicating session status.
You can find a C++ application that does it in this answer: Peak meters for individual programs on Windows 7. The meters are per-session and an audio-enabled application might have one or more sessions in it, but eventually as long as you enumerate them, you can figure out if there is any active playback there.
I believe the Windows Core Audio API in Vista+ allows you to get the VU levels for each application (After all, the mixer shows it). This should allow you to turn down one application when another is playing, etc.
Related
After extensive searches I can't find any information on how to detect the microphone sound level input in mac OSX using either Applescript or Java.
The purpose of this is to write an automatic volume adjust script based on the sound level detected by the built in microphone.
I know that commercial solutions exist but I'm interested simply as an exercise.
Just in case people think I'm posting on here just to make a statement I'm informed that I should add something to which a question mark can be added or people won't understand that it's a question.
I am after some example code in either java or applescript to show how to detect the microphone input sound level. Can anyone help with this?
set currentVolume to output volume of (get volume settings)
This is from a MacScripter thread that will probably answer some more of your questions on this project as well.
Hey so I was using Spotify yesterday and I noticed while an ad was playing that any time I mute my volume or drop the volume to zero, spotify pauses the ad and doesn't resume until you turn the volume back up. I started thinking about that and got curious, how exactly does that work? Could I theoretically make a java program that prints "false" every time I hit the mute button on my laptop? What are the topics to look up if I was interested in learning more about this? Would this have to do with assembly at all?
I've never done something like that, but after a quick research on the web, I guess it can be achieved via the The AudioSystem Class. You can find a tutorial here.
I'm writing an accompaniment application that continuously needs to play specific notes (or even chords). I have a thread running that figures out which note I need to play, but I have no idea where to begin regarding the actual playback. I know I can create an audiotrack and write a sine wave to it, but for this project a simple tone won't cut it. So I'm guessing I either need to use MIDI (can android do that?) or to somehow take a sample and change its pitch on the fly, but I don't know if that's even possible.
All I can say is to check out pitch-shifting (which you seem to have heard of) and soundpool (which would require some recording of your own) and these 2 links:
Audio Playback Rate in Android
Programmatically increase the pitch of an array of audio samples
the second link seems to have more info.
I have made a few simple apps on android, and thought it was time for something a bit more complex. So, i thought I'd try something that's already out there, but build it from scratch.
The idea is to create an app that allows user to play piano by pressing virtual keys on the display. But I'm not sure how to go about synthesizing the sound of each note, is it best to have copies of of each note stored on file, or is there a more dynamic way of synthesising notes and chords on the fly.
I have worked with C++ so NDK stuff is also okay.
Thanks for any help.
Sound playback (handing off buffers) pretty much has to be done from the Android java apis
Synthesis could be done in native or java, whichever it preferred.
Short (uncompressed) samples could be played back repeatedly, but you probably also want an attack transient. Perhaps you could have an attack, a sustain, and release, repeating the sustain as long as the key is down. Ideally each sample should be an integral number of periods of its fundamental component long so that you don't get a transient when you change between the attack to sustain or sustain to decay.
I'm sure you can find code somewhere for an FM or other synthesizer... this you might well want to implement in a native library that hands off buffers to java code to pass to the audio apis.
What is too bad is that android already has an internal midi synthesizer, but apparently lacks a dynamic interface to it, so it can only play midi files.
By far the easiest solution would be to record the sound of each note on the piano and play it back when the key is pressed. Many professional virtual piano instruments work this way, recording every note on the piano being played at multiple velocities. Obviously this can take many gigabytes of disk space, but for a mobile phone app, you might get away with a single MP3 recording of each note in an octave.
Actually algorithmically synthesizing the sound of a piano is very difficult to do, and until fairly recently, very few have done it convincingly (pianoteq is one of the best current implementations).
I want to alert the user in a Swing application of certain events with an old fashioned PC Speaker beep (NOT the soundcard), since not on every PC there is a soundcard with an attached speaker, or volume might be turned to zero, or a headphone might be connected... How can I do this?
UPDATE:
java.awt.Toolkit.getDefaultToolkit().beep() seems usually to generate a sound on the soundcard. It only uses the speaker if there is no active soundcard.
To print an ASCII value 7 works only if the application is launched in a terminal, which at least a Swing app usually isn't.
So the question is still open.
Toolkit.getDefaultToolkit().beep();
Try this:
java.awt.Toolkit.getDefaultToolkit().beep();
It worked for me, although I'm not sure whether this was the PC Speaker beep or some OS-generated beep.
I read somewhere that you need to use a C/C++ dll and connect it with JNI, to make that work,.. link is offline
Ok I found what you're looking for
http://pyx4j.com/pyx4j-native/index.html
he pyx4j-native project is a collection of java wrappers for windows functions like time and beep. Now only works on windows.
NativeThreadDump - Send CtrlBreak Event to current process
Beep - Make a sound using PC speaker
FileUtil - Access and modify file creation time. Used in com.pyx4j.log.RollingFileAppender
NativeTimer - System high-resolution performance counter used before Java 5
Other than the beep sound you can try
JFugue.
JFugue is an open-source Java API for programming music without the complexities of MIDI.
ASCII value 7 is a beep. So just print that character.
{
If (whatever you named the file) = true
Then
Process.Start ("C:\Windows\Media\{whatever you named the file})
}
I use that in C#. It's late for me the code is not exactly accurate before people bash this post. Put a write directory to name a folder and declare it the default location. Move the sound of your choice to this folder and it will play the audio tone. Set the timer in Java to loop the sound every 2 seconds to get the persons attention. Hope this helps as I'm learning my self!