Wednesday, March 14, 2012

AV Sync, Mixing two audio tracks in android

1. AV sync is undetectable if sound is rendered -100ms to +25 ms to video
- Sound Delayed
+ Sound advanced


2.How android audio flinger is mixing two or more tracks in mixer thread ?

 [How to mix two or more audio streams/tracks together ?]

If you want to mix streams A & B, you simply sum the corresponding samples: A1+B1=C1, A2+C2=B2... An+Bn=Cn...
Of course, both streams must have the same sample rate (and with integer formats, both must have the same bit-depth) before you sum.

    With integer formats you have to scale the input streams before summing (i.e. divide by 2), or you need to allow for
larger numbers (more bits) in the output stream. Even with 32-bit floating point, you'll normally want to scale before or after mixing to avoid clipping.
(The 32-bit data won't clip, but you can clip the DAC output.)

And frequently with audio mixing, you'll want to scale the input levels because you don't always want a 1:1 mix... You may want one signal to be louder in the mix.  Audio flinger is mixing one or more tracks as mentioned above.

 

From:http://www.hydrogenaudio.org/forums/index.php?showtopic=79430

 

Sunday, March 11, 2012

How localplayback errors are notified from C++ to java mediaplayer/ mediarecorder layer/Application in android ?

How localplayback errors are notified from C++ to java mediaplayer/ mediarecorder layer/Application in android ?


Java layer will have

MediaPlayer
{
  public static void postEventFromNative() { Notifies Error or Information events to Application thru InfoListener or ErrorListener }

};

JNI:
=====

JNIMediaPlayerListener/ JNIMediaRecorderListener is passed to underlying c++ mediaplayer or mediarecorder [libmedia] object.

whenver C++ mediaplayer or media recorder encounters errors it will call JNIMediaPlayerListener's notify () fn.

JNIMediaPlayerListener's notify/JNIMediaRecorderListener's notify is implemented in JNI.


void JNIMediaPlayerListener/JNIMediaRecorderListener::notify(int msg, int ext1, int ext2, const Parcel *obj)

{
   
    fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
                                               "(Ljava/lang/Object;IIILjava/lang/Object;)V");
  env->CallStaticVoidMethod(mClass, fields.post_event, mObject,
                msg, ext1, ext2, NULL); //This will call the postEventFromNative() fn in Java...
 
}