we present information about computer news and price information and specs samsung, huawei, Tecno Price products, Specifications & Features and more information about software

Sabtu, 28 Maret 2015

Play an audio sample grabbed using JavaCV

Play an audio sample grabbed using JavaCV - do you know that every day there are new gadgets that are created with new advantages to simplify your life, on the blog Computers News we will discuss about the latest gadgets and gadgets that have long ranging from speck and price, now we will discuss about Play an audio sample grabbed using JavaCV we have collected a lot of news to make this article to be really useful for you, please see.

Articles : Play an audio sample grabbed using JavaCV
full Link : Play an audio sample grabbed using JavaCV

You can also see our article on:


Play an audio sample grabbed using JavaCV

UPDATED 11/05/2015
Hy friends,its been 1 and half years,posting here.Sorry for this much long delay because of my studies and increasing my memory.My memory is now advanced friends.Here it is after a long time iam gonna give the most frustrating problem developers facing off.

Here it is,iam running a marathon for weeks to find a solution for this problem.First of all i asked to the Javacv groups, to find a solution.


ATLAST,

Here i have found my way to the destination with just a keyword provided by Samuel Audet(JavaCV Project Member).

PCM_FLOAT.

What is the way to play the raw float from javacv to android?Here it is i have created a class.Take it on for free.

package com.shihabsoft.castanythingtopc;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
public class AndroidAudioDevice
{
AudioTrack track;
short[] buffer = new short[1024];
public AndroidAudioDevice(int sampleRate,int channels)
{  
      int minSize =AudioTrack.getMinBufferSize(sampleRate, channels==1?AudioFormat.CHANNEL_CONFIGURATION_MONO:AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT );      
      track = new AudioTrack( AudioManager.STREAM_MUSIC, sampleRate, channels==1?AudioFormat.CHANNEL_CONFIGURATION_MONO:AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT,minSize, AudioTrack.MODE_STREAM);      track.play();          
}
  
public void writeSamples(float[] samples)
{  
    fillBuffer( samples );
    track.write( buffer, 0, samples.length );  
}
private void fillBuffer( float[] samples )  
{  
   if( buffer.length < samples.length )  
     buffer = new short[samples.length];
 
   for( int i = 0; i < samples.length; i++ )  
     buffer[i] = (short)(samples[i] * Short.MAX_VALUE);
}
}

How to use my class.


AndroidAudioDevice aaD=new AndroidAudioDevice(sampleRate Hz,numberOfChannels);
aaD.writeSamples(floatArray);

But iam not so cruel :) ,to leave you after crossing half-quarter of the sea.Here it is i have created the code from top to end ie,Frame to float array.Feel free to use it.

final java.nio.Buffer[] samples=vFrame.samples;
//Getting the samples from the Frame from grabFrame()
float[] smpls;
if(aaD.track.getChannelCount()==1)
//For using with mono track
{
    Buffer b=samples[0];
    fb = (FloatBuffer)b;
    fb.rewind();
    smpls=new float[fb.capacity()];
    fb.get(smpls);
}
else if(aaD.track.getChannelCount()==2)
//For using with stereo track
{
    FloatBuffer b1=(FloatBuffer) samples[0];
    FloatBuffer b2=(FloatBuffer) samples[1];
    smpls=new float[b1.capacity()+b2.capacity()];
    for(int i=0;i<b1.capacity();i++)
       {
         smpls[2*i]=b1.get(i);  smpls[2*i+1]=b2.get(i);
       }
}
aaD.writeSamples(smpls);

Don't ever put the sampleRate and audioChannels manually,Just grab that both from FFmpegFrameRecorder.

Because incase the video have a sample rate of 44kHz and you are initializing the audio track with 8000Hz,the audio will be so distored you may never hear a voice.So be carefull on those two params.

Let me know if you guys are inneed of more details.
For soon i will post a new Sample Application in the JavaCV project.


Asked by Sam.



article titled Play an audio sample grabbed using JavaCV has been completed in the discussion

hopefully information about Play an audio sample grabbed using JavaCV can provide benefits for you in determining the gadget to suit your needs so much easier in living everyday life.

you just read the article entitled Play an audio sample grabbed using JavaCV if you feel this information is useful for you and want to bookmark it or want to share it please use link https://nandncomputers.blogspot.com/2015/03/play-audio-sample-grabbed-using-javacv.html.

Tag :
Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : Play an audio sample grabbed using JavaCV

0 komentar:

Posting Komentar