Example usage for android.media AudioFormat CHANNEL_IN_STEREO

List of usage examples for android.media AudioFormat CHANNEL_IN_STEREO

Introduction

In this page you can find the example usage for android.media AudioFormat CHANNEL_IN_STEREO.

Prototype

int CHANNEL_IN_STEREO

To view the source code for android.media AudioFormat CHANNEL_IN_STEREO.

Click Source Link

Usage

From source file:Main.java

public static int getInFormat(int inChannels) {
    switch (inChannels) {
    case 1:/*ww w .  ja  v a  2  s  .c  om*/
        return AudioFormat.CHANNEL_IN_MONO;
    case 2:
        return AudioFormat.CHANNEL_IN_STEREO;
    default:
        throw new IllegalArgumentException("illegal number of input channels: " + inChannels);
    }
}

From source file:Main.java

public static int outChannelMaskFromInChannelMask(int channelMask) {
    switch (channelMask) {
    case AudioFormat.CHANNEL_IN_MONO:
        return AudioFormat.CHANNEL_OUT_MONO;
    case AudioFormat.CHANNEL_IN_STEREO:
        return AudioFormat.CHANNEL_OUT_STEREO;
    default:/*from  w ww  .j av  a2 s  .c  om*/
        return AudioFormat.CHANNEL_INVALID;
    }
}

From source file:cc.echonet.coolmicapp.MainActivity.java

public void startRecording(View view) {
    if (isThreadOn) {
        stopRecording(view);/*from  w w w .j  av a 2 s.  c o  m*/

        return;
    }

    if (!checkPermission()) {
        Toast.makeText(getApplicationContext(), "Missing Permissions. Please request them in the Settings.",
                Toast.LENGTH_LONG).show();
        return;
    }

    if (Wrapper.getState() != Wrapper.WrapperInitializationStatus.WRAPPER_INTITIALIZED) {
        Toast.makeText(getApplicationContext(), "Native components not ready.", Toast.LENGTH_LONG).show();
        return;
    }

    if (!isOnline()) {
        Toast.makeText(getApplicationContext(), "Check Internet Connection !", Toast.LENGTH_LONG).show();
        return;
    }

    if (!coolmic.isConnectionSet()) {
        Toast.makeText(getApplicationContext(), "Set the connection details !", Toast.LENGTH_LONG).show();
        return;
    }

    invalidateOptionsMenu();
    isThreadOn = true;
    //screenreceiver.setThreadStatus(true);
    startService(new Intent(getBaseContext(), MyService.class));
    RedFlashLight();
    timeInMilliseconds = 0L;
    timeSwapBuff = 0L;
    start_button.startAnimation(animation);
    start_button.setBackground(trans);
    trans.startTransition(5000);
    start_button.setText(R.string.broadcasting);
    streamThread = new Thread(new Runnable() {
        @Override
        public void run() {
            if (isThreadOn) {
                try {
                    String portnum;
                    String server = coolmic.getServerName();
                    Integer port_num = 8000;

                    if (server.indexOf(":") > 0) {
                        String[] split = server.split(":");
                        server = split[0];
                        portnum = split[1];
                        port_num = Integer.parseInt(portnum);
                    }

                    Log.d("VS", server);
                    Log.d("VS", port_num.toString());
                    String username = coolmic.getUsername();
                    String password = coolmic.getPassword();
                    String mountpoint = coolmic.getMountpoint();
                    String sampleRate_string = coolmic.getSampleRate();
                    String channel_string = coolmic.getChannels();
                    String quality_string = coolmic.getQuality();
                    String title = coolmic.getTitle();
                    String artist = coolmic.getArtist();

                    Log.d("VS", String.format(
                            "Server: %s Port: %d Username: %s Password: %s Mountpoint: %s Samplerate: %s Channels: %s Quality: %s Title: %s Artist: %s",
                            server, port_num, username, password, mountpoint, sampleRate_string, channel_string,
                            quality_string, title, artist));

                    Integer buffersize = AudioRecord.getMinBufferSize(Integer.parseInt(sampleRate_string),
                            Integer.parseInt(channel_string) == 1 ? AudioFormat.CHANNEL_IN_MONO
                                    : AudioFormat.CHANNEL_IN_STEREO,
                            AudioFormat.ENCODING_PCM_16BIT);
                    Log.d("VS", "Minimum Buffer Size: " + String.valueOf(buffersize));
                    Wrapper.init(MainActivity.this, server, port_num, username, password, mountpoint,
                            "audio/ogg; codec=vorbis", Integer.parseInt(sampleRate_string),
                            Integer.parseInt(channel_string), buffersize);

                    int status = Wrapper.start();

                    Log.d("VS", "Status:" + status);

                    if (status != 0) {
                        throw new Exception("Failed to start Recording: " + String.valueOf(status));
                    }

                    strStreamFetchStatsURL = String.format("http://%s:%s@%s:%s/admin/stats.xml?mount=/%s",
                            username, password, server, port_num, mountpoint);
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("VS", "Recording Start: Exception: ", e);

                    MainActivity.this.runOnUiThread(new Runnable() {
                        public void run() {
                            stopRecording(null);

                            Toast.makeText(MainActivity.this, "Failed to start Recording. ", Toast.LENGTH_LONG)
                                    .show();
                        }
                    });
                }
            }

        }

    });
    streamThread.start();
}

From source file:com.example.sensingapp.SensingApp.java

/** Called when the activity is first created. */
@Override//from  w  w  w.  j  a va 2 s . c  o  m
public void onCreate(Bundle savedInstanceState) {
    int i;
    Location location = null;

    super.onCreate(savedInstanceState);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    try {
        Class.forName("android.os.AsyncTask");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    m_smSurScan = (SensorManager) getSystemService(SENSOR_SERVICE);

    PackageManager pm = getPackageManager();
    m_riHome = pm.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

    m_nBufferSize = AudioRecord.getMinBufferSize(m_nAudioSampleRate, AudioFormat.CHANNEL_IN_STEREO,
            AudioFormat.ENCODING_PCM_16BIT);

    m_tmCellular = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    checkSensorAvailability();

    //Get Existing Project Name and Existing User Name
    preconfigSetting();

    /* When the power button is pressed and the screen goes off, the sensors will stop work by default,
     * Here keep the CPU on to keep sensor alive and also use SCREEN_OFF notification to re-enable GPS/WiFi
     */
    PowerManager pwrManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    m_wakeLock = pwrManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);

    registerReceiver(m_ScreenOffReceiver, filter);

    show_screen1();
}

From source file:com.example.sensingapp.SensingApp.java

private void startAudioRecording() {
    m_audioRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, m_nAudioSampleRate,
            AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, m_nBufferSize);

    if (m_audioRecorder == null)
        return;/*from ww  w .  java 2  s . com*/

    int i = m_audioRecorder.getState();
    if (i == AudioRecord.STATE_INITIALIZED) {
        m_audioRecorder.startRecording();
    } else {
        return;
    }

    if (m_blnRecordSoundLevel == true || m_blnRecordSoundFile == true) {
        m_processSoundThread = new Thread(new Runnable() {
            public void run() {
                processAudioData();
            }
        }, "Audio Thread");

        m_processSoundThread.start();

        if (m_blnRecordSoundLevel == true) {
            m_soundLevelThread = new Thread(new Runnable() {
                public void run() {
                    calculateAudioSoundLevel();
                }
            }, "Sould Level Thread");

            m_soundLevelThread.start();
        }
    }

}