Using another sound card with the JavaSound Synthesizer - java

Could I use my M-AUDIO Fast Track Ultra as the audio interface in a Java MIDI plugin I'm writing? That virtual driver ASIO4ALL could be a nice way to go as well.
I will code a Live Performance MIDI Modifier, to enhance a keyboardist's level of control and complexity of MIDI-controlled effects. I've already begun a small proof-of-concept app that will get me going, but even when testing Oracle's own demo of the JavaSound API I notice some delay between the mouse input commands and the sound going. Whether this is caused by the way this app is constructed, I'll still find out, but I want to be sure I can deliver almost zero latency (20ms, as I get in my live performance host software). Have you guys found out anything relevant?

The only portable way to get a synthesizer is MidiSystem.getSynthesizer(), which gives you nothing but the default synthesizer, which outputs to some default audio device.
You would have to change the default audio output device of the JVM or of the OS.
The synthesizer has a fixed latency, which you can obtain with Synthesizer.getLatency().
The audio device will add its own latency.

Related

Verifying an audio stream is actually played and heard

I'm broadcasting an audio stream (predefined playlists not live) through an HTTP server. I'm wondering are there any cheap solutions (in terms of computational complexity) which I can confirm my stream is actually played and heard. This means a reasonable amount of audio output is broadcasted from device which resembles mostly that stream.
For a simple scenario: assume there is an Android device & app, which is responsible for connecting to the server and playing the stream. Same Android app will be used to capture microphone input and compare it with the stream. Testing environment is outdoor scene with low-to-moderate background noise.
I did some studying with FFT and audio analysis in the college but I'd rather not reinvent the wheel so I'm seeking reliable and cheap libraries for this matter (mainly Android but Java libraries are welcome too).
As a side note, I started out with getting volume levels from the device, but this turned out to be insufficient since user can just plug in a turned off speaker to the device.
You might think the amount of work required to accomplish such a feature might not be feasible. But keep in mind that this feature I'm working on is between the "content generator" and "broadcaster", NOT "broadcaster" vs. "listener". So all I'm trying to do is making sure the broadcaster is holding his end of the contract.

Getting another Java Program's Sound

I'm writing a video recording program, and it's going quite well. I can record mic as well as video from the screen. However, I would also like to be able to obtain sounds from another Java program and then sync them with the video. Basically, record the audio as it is played by the other program.
Is there a way to accomplish this? I'm pretty new with sound, and have read a bit up on it. I think I need to set up a mixer, but I'm not sure if I can actually obtain sound from another Java program that way.
This is not possible with java sound, not because of any particular problem with java sound, but because not all audio APIs that java builds on support this feature. (Core audio on the mac for example, and ASIO on windows. Not sure about ALSA on linux, but I don't think it supports this either).
If you are on windows and want to write JNI/JNA code you can use PortAudio which supports this on one of the audio APIs (sorry I can't recall which one).

A viable alternative to MIDI?

I'm working on a musical application that relies entirely on MIDI. I want this app to be around for quite awhile, into the next many OS editions, etc. (given normal upkeep and updates, etc.)
But since Microsoft, Java/Google/Android and others are showing signs of dropping MIDI support entirely from their APIs (at least the way I see it) maybe there is a movement to kill MIDI off...?
Anyway, I'm looking for a viable alternative to MIDI with its easy real-time interactivity. I hope to stay with MIDI but if the writing is on the wall I'd rather know now than wait. If MIDI weren't available, what would you do?
But since Microsoft, Java/Google/Android and others are showing signs of dropping MIDI support entirely from their APIs (at least the way I see it) maybe there is a movement to kill MIDI off...?
Where did you get this idea? MIDI isn't going anywhere, as it's so simple and universal. If you build an app using MIDI, it's definitely not in danger of becoming obsolete for that reason.

Multichannel USB recording with Java Sound API?

I'm trying to record/process some audio from three usb microphones with Java Sound on Snow Leopard (but can switch to Windows if it fixes things). Problem is, when I try to use the mixer that corresponds to the usb mic, Java Sound tells me that the line isn't supported. Specifically, it says this...
Available mixers:
Java Sound Audio Engine
USBMIC Serial# 041270067
Built-in Input Built-in Microphone
Soundflower (2ch)
Soundflower (16ch)
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException:
Line unsupported: interface
TargetDataLine supporting format
PCM_SIGNED 96000.0 Hz, 8 bit, stereo,
2 bytes/frame,
...when I ask it to select the USBMIC mixer:
Mixer mixer = AudioSystem.
getMixer(mixerInfo[1]);
I have tried matching the audio format to the exact specifications of the microphones (16-bit, 44100Hz, stereo) and it didn't make any difference.
The problem is cropping up here:
final TargetDataLine line = (TargetDataLine)
mixer.getLine(info);
It would seem that the mixer and the TargetDataLine don't like each other. Is there some way to get these two to 'match' and get along?
The microphones that I'm using are admittedly a bit strange. They were made to be used in a karaoke video game called SingStar. The mics themselves have standard mono line-in connectors that plug into a little hub (two to a hub) that converts them into a single male usb connector. Strangeness aside, though, they seem to work perfectly fine with Audacity as separate channels, so multichannel recording with them is clearly possible, just maybe not in Java.
I've also considered using a program like Soundflower that shares audio between different programs. However, I'm not sure this will work as I can't see how to make the USB mics inputs to Soundflower and then pipe them into a Java. A quick experiment showed me that I could record audio in Audacity from the mics, pipe it out through Soundflower, and then process in my Java program. Still, what I would like to do is have it all happen in real time in Java.
Anybody familiar with this kind of problem?
I think that a simple way to do this would be using Soundflower and Soundflowerbed.
I can't see how to make the USB mics inputs to Soundflower and then pipe them into a Java.
It sounds like you have Soundflower installed already. Soundflowerbed is found in the same disk image as Soundflower and is a menubar application. It lets you route sound between applications which don't have controls built in for selecting sound devices. Install that from the disk image and click it to run.
All of the following will be using my Echo Audiofire 4 but in principle should work on any audio device.
Using Soundflowerbed
Open Soundflower and tick the audio device you want to use under Soundflower (16ch). As I'm a new user I can't post images but they are linked below. If I get the bounty then I will edit the post to include the images inline.
From here you would use Soundflower (16ch) as your audio input device in Java sound.
Creating an aggregate audio device
An alternative way to solve this if that didn't work is to create an aggregate device. Open Applications > Utilities > Audio Midi Setup and click the plus sign to create a new aggregate device.
Tick the device that you want to aggregate. You only want your USBMIC (As I'm a new SO user I can only post two images per answer so the next two are linked here).
The key part which may be giving you trouble is the clock on the device. If you select the Mac as the clock source then that may be more stable.
If this still doesn't work then you could try adding the Mac built-in audio to the aggregate device and making it the master clock by right clicking on the device you want to be the master.
Other options
Finally, I haven't used this before but Pulse Audio (Google it, I can't insert more links in this post) might be a possible solution for mixing your audio streams together. It looks quite heavyweight though.
According to my research, especially threads like this, the microphone you are using is most likely causing the problem. The thread states that the microphone is even a problem when it comes to switching games, so I am guessing that it will be a problem when switching platforms, too.
My suggestion is - if you have not tried this already - to use a different microphone! Most microphones I have messed around with have special chip controllers that convert data into the data compatible for the game system. Being that you are using this on an operating system for the computer, you are probably getting some very odd effects that you wouldn't get on a game system like Playstation or others.
Hopefully this helps! Happy coding!
The AudioFormat doesn't match the TargetDataLine's supported format. I don't know if that was a typo or not but the Exception thrown says the TargetDataLine supports 8 bit audio and right below that you said you're using a 16 bit AudioFormat. It also supports up to 2 bytes per frame, how quickly and in what size chunks are you trying to read the data? Sorry if that doesn't help but I thought I'd point that out in case it was overlooked.

java sound without hardware device

Anyone know if it is possible to write an app that uses the Java Sound API on a system that doesn't actually have a hardware sound device?
I have some code I've written based on the API that manipulates some audio and plays the result but I am now trying to run this in a server environment, where the audio will be recorded to a file instead of played to line out.
The server I'm running on has no sound card, and I seem to be running into roadblocks with Java Sound not being able to allocate any lines if there is not a Mixer that supports it. (And with no hardware devices I'm getting no Mixers.)
Any info would be much appreciated -
thanks.
For linux you can use OSS Virtual Mixer, which will give you virtual sound channels.
On windows there are a few sound drivers that do this, one is Virtual Audio Cable, which, while not free, is about the cost of a sound card so it shouldn't be a hardship.
If neither of those work for you, it'll probably be easier to make your own Java sound library and replace the built in functionality than it would be to implement a sound card for your OS.
-Adam
All java needs are the drivers for a sound card. The JVM relies on the OS to handle direct hardware management, all JVM needs is a way to tell the OS that it wants a sound played (thus the driver).

Categories