How can I increase number of audio streams for android? - java

I'm learning about android development. Let's say I want to be able to listen to spotify music in the background, while simultaneously listening to a spoken word podcast thru some other podcast app. Ive tried creating a Soundbuilder object and changed the maxStreams to 2 when I hit a togglebutton. However, when I run the app it makes no difference. Either spotify has the focus or the podcast app has focus.
Should I be utilizing the AudioManager class instead? To be able to eventually controll the volume of each stream independently? Also, would the phone have to be root to be able to change the maxStreams to 2?

I think You should check this example: MixingAudioInputStream.java
It's example taken from here
Check these out and try mixing both streams into single stream by Yourself - as trying to code new things is best way to learn.

Related

Forcing an NFC scan on Android

I was just wondering if it was possible to force a scan for NFC tags on Android and how to do it. I want to know if I can call something like nfc.scan() and have it return the tag info if there is any tag detected. I am kinda new to this Android thing and so far I have only seen it done with intents.
No, Android does not allow you to trigger a scan for NFC tags/devices in range.
In fact, Android continuously polls1 for tags while the screen is on (and unlocked) and there is no currently detected tag. Thus, you can register your app to be informed when a new tag is detected -> this is done through intents.
1) Most Android devices employ some energy saving mode that prevents the device from continuously polling for all kinds of tags. Instead, these devices detect tags by sending a short impulse and measuring detuning effects from inductive coupling.

How do you access data from MIDI IN stream in java?

I would like to make use of the data coming from a MIDI in device. I need to be notified when certain events occur so that I can do things like transpose certain notes on the fly or call a method or whatever you can think of.
Although I'm quite new to programming in general and to java in particular I have already been able to play a sequence with the sequencer using javax.sound.midi. I can even add a listener that tells me when certain events are played by the sequencer. Now I was hoping to be able to do something similar with the MIDI IN stream but I don't know how.
Any ideas or workarounds would be welcome because I'm quite stuck at the moment.
To record MIDI data, you have to
connect the input port's Transmitter to your Sequencer's Receiver by calling its setReceiver method,
create new Sequence/Track objects, and connect them to the Sequencer,
enable recording on your track(s), and
start recording on your Sequencer.
(see the documentation)
I finally found the solution and I'd like to clarify the question and add my solution in case it is helpful for anybody else.
The project I'm working on (which is way over my head by the way) is a midi keyboard arranger. In case you don't know what it is, it's a keyboard that plays patterns (styles) and changes the tone and the arrangement depending on the chord played. What I needed was what I think is called a dump from the midi in port so that my program can figure out what chord has been played so that it can have the sequencer respond in different ways.
So to respond my own original question to do this you need to create a new transmitter for your midi in port. Then create a new receiver to receive the data stream from the new transmitter. Finally have the receiver send the data to a PrintStream and then you can do what you want with the data stream!
Implement the send(javax.sound.midi.ShortMessage, long) method of the javax.sound.midi.Receiver interface in a class of your own and use the instances of the latter as you would with other Receiver objects.

How do I get the Arduino Nano to communicate with a phone through Java?

My goal: Make my phone control an Arduino which controls servos which will do cool animations.
How do I get to my goal: I use Java to communicate to the Arduino Nano through the yellow pins (visible on the right picture) through serial (RxD/TxD) (RS-232 protocol) which will tell the Arduino how to control the servos or motors.
Problems:
I don't know which one of the pins that does what, like which one that is GND, which one that is TxD or RxD
I don't know how to tell the phone to do things with its yellow pins (which the Arduino will read and understand to control its servos/motors)
[_] I don't know how to listen to the phone's accelerometer through Java - The thing that lets it tell what is down
[_] I don't know how to listen to the phone's light-sensor
[_] I don't know how to listen to the phone's microphone
[_] I don't know how to listen to the phone's camera
[_] = Things I'm just very curious about that I will use for future projects.
Extra information: I got NetBeans IDE 7.1.1, and I got an Arduino Nano, I got the phone shown above which is called "J10i2 Elm Sony Ericsson".
So I guess what I'm really looking for is someone who knows how to control a phone 100% through Java. Or being pointed in the right direction is also nice!
If you think that I can do this in a better/simpler/smarter way then feel free to leave a comment stating why and how it is better ;)
I would suggest one easy solution, use a REST web service (SOA arquitechture) to solve this problem i did it in my personal case and now im able to control and monitor my house :)
You could simply create a database table representation of your arduino's pins...then just create a service that receives some parameters (i.e> pin no, status -> 1/0, arduino id, etc) and saves them in the database, with your mobile app you could just use the same web service for changing the values.
Finally write down an Arduino app that keeps reading statuses from that service and database (of course using another endpoint/ method in which case you just need to pass your arduino id and it will return a response of all of the different pin status so you can read/process them from your arduino (for example since JSON library is heavy and slow on arduino im passing my return values back from the server to the arduino using simple CSV values i.e> "[pin:status,.....]" i have some code for making HTTP/GET/POST on Arduino you just need the ethernet shield , i could bring you the code if you are interested

Android Camera autofocus when user holds camera still

I'm sure most of you have used an android phone before and taken a picture. Whenever the user changes the mobile phone's position and holds it steady, the camera focusses automatically. I'm having a hard time replicating this in my app. The autofocus() method is being called only once when the application is being launched. I have been searching for a solution these past 3 days and while reading the google documentation I stumbled upon the sensor method calls (such as when the user tilts the mobile forwards or backwards). I could use this API to achieve what I need but it sounds too dirty and too complicated. I'm sure there's another way around it.
All examples on the internet which I have found only focus when the user presses the screen or a button. I have also gone through several questions on SO to hopefully find what I am looking for but I was unsuccessful. I have seen this question and that String is not compatible with my phone. For some reason the only focussing modes which I can use is fixed and auto.
I was hoping someone here would shed some light on the subject because I am at a loss.
Thankyou very much for your time.
Since API 14 you can set this parameter
http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FOCUS_MODE_CONTINUOUS_PICTURE
Yes, camera.autoFocus(callback) is a one-time function. You will need to call it in a loop to have it autofocus continuously. Preferably you would have a motion detection via accelerometer or compass to detect when camera is moved.

Audio programming, Sound Processing and DSP

I was playing with a karaoke application on iPhone and came up with following questions:
The application allowed its users to control the volume of the artist; even mute it. How is this possible?
Does adjusting artist sound/setting equalizer etc. mean performing some transformation of required frequencies? What sort of mathematics is required here(frequency domain transformations)?
The application recorded users voice input via a mic. Assuming that the sound is recorded in some format, the application was able to mix the recording with the karaoke track(with artists voice muted). How can this be done?
Did they play both the track and voice recording simultaneously? Or maybe they inserted additional frequency(channel?) in the original track, maybe replaced it?
What sort of DSP is involved here? Is this possible in Java, Objective C?
I am curious and if you have links to documents or books that can help me understand the mechanism here, please share.
Thanks.
I don't know that particular application, probably it has a voice track recorder separately.
For generic 2-channels stereo sound the easiest voice suppression can be performed assuming that artist's voice is somehow equally balanced between two channels (acoustically it appears in center). So the simplest 'DSP' would be subtract one channel from another. It does not work that well however with modern records since all instruments and voice are recorded separately and then mixed together (meaning that voice will not be necessarily in phase between two channels).
I have written two detailed blogposts on how to get a custom EQ in iOS. But i have no details about how to do the DSP yourself. If you simply want to choose between a wide range of effects and stuff, try this.
First post explains how you build libsox:
http://uberblo.gs/2011/04/iosiphoneos-equalizer-with-libsox-making-it-a-framework
The second explains how to use it:
http://uberblo.gs/2011/04/iosiphoneos-equalizer-with-libsox-doing-effects
please up the answer if it helped you! thanks!

Categories