Example usage for android.media AudioTrack getNativeOutputSampleRate

List of usage examples for android.media AudioTrack getNativeOutputSampleRate

Introduction

In this page you can find the example usage for android.media AudioTrack getNativeOutputSampleRate.

Prototype

static public int getNativeOutputSampleRate(int streamType) 

Source Link

Document

Returns the output sample rate in Hz for the specified stream type.

Usage

From source file:com.xperia64.timidityae.Globals.java

public static void reloadSettings(Activity c, AssetManager assets) {

    prefs = PreferenceManager.getDefaultSharedPreferences(c);
    firstRun = prefs.getBoolean("tplusFirstRun", true);
    theme = Integer.parseInt(prefs.getString("fbTheme", "1"));
    showHiddenFiles = prefs.getBoolean("hiddenSwitch", false);
    defaultFolder = prefs.getString("defaultPath", Environment.getExternalStorageDirectory().getAbsolutePath());
    dataFolder = prefs.getString("dataDir", Environment.getExternalStorageDirectory() + "/TimidityAE/");
    manConfig = prefs.getBoolean("manualConfig", false);
    JNIHandler.currsamp = defSamp = Integer.parseInt(prefs.getString("tplusResamp", "0"));
    mono = Integer.parseInt(prefs.getString("sdlChanValue", "2"));
    sixteen = true;//prefs.getString("tplusBits", "16").equals("16");
    aRate = Integer.parseInt(prefs.getString("tplusRate",
            Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM))));
    buff = Integer.parseInt(prefs.getString("tplusBuff", "192000"));
    showVideos = prefs.getBoolean("videoSwitch", true);
    shouldLolNag = prefs.getBoolean("shouldLolNag", true);
    keepWav = prefs.getBoolean("keepPartialWav", false);
    useDefaultBack = prefs.getBoolean("useDefBack", false);
    compressCfg = prefs.getBoolean("compressCfg", true);
    reShuffle = prefs.getBoolean("reShuffle", false);
    freeInsts = prefs.getBoolean("tplusUnload", true);
    preserveSilence = prefs.getBoolean("tplusSilKey", true);
    if (!onlyNative)
        nativeMidi = prefs.getBoolean("nativeMidiSwitch", false);
    else/*w w w . j a  v  a 2 s .c o  m*/
        nativeMidi = true;

}

From source file:com.xperia64.timidityae.Globals.java

public static boolean initialize(final Activity a) {
    if (firstRun) {
        final File rootStorage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/TimidityAE/");
        if (!rootStorage.exists()) {
            rootStorage.mkdir();//from ww w.j  a va 2  s . c om
        }
        File playlistDir = new File(rootStorage.getAbsolutePath() + "/playlists/");
        if (!playlistDir.exists()) {
            playlistDir.mkdir();
        }
        File tcfgDir = new File(rootStorage.getAbsolutePath() + "/timidity/");
        if (!tcfgDir.exists()) {
            tcfgDir.mkdir();
        }
        File sfDir = new File(rootStorage.getAbsolutePath() + "/soundfonts/");
        if (!sfDir.exists()) {
            sfDir.mkdir();
        }
        updateBuffers(updateRates());
        aRate = Integer.parseInt(prefs.getString("tplusRate",
                Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM))));
        buff = Integer.parseInt(prefs.getString("tplusBuff", "192000")); // This is usually a safe number, but should probably do a test or something
        migrateFrom1X(rootStorage);
        final Editor eee = prefs.edit();
        firstRun = false;
        eee.putBoolean("tplusFirstRun", false);
        eee.putString("dataDir", Environment.getExternalStorageDirectory().getAbsolutePath() + "/TimidityAE/");
        if (new File(dataFolder + "/timidity/timidity.cfg").exists()) {
            if (manConfig = !cfgIsAuto(dataFolder + "/timidity/timidity.cfg")) {
                eee.putBoolean("manConfig", true);
            } else {
                eee.putBoolean("manConfig", false);
                ArrayList<String> soundfonts = new ArrayList<String>();
                FileInputStream fstream = null;
                try {
                    fstream = new FileInputStream(dataFolder + "/timidity/timidity.cfg");
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                // Get the object of DataInputStream
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                //Read File Line By Line
                try {
                    br.readLine(); // skip first line
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String line;
                try {
                    while ((line = br.readLine()) != null) {
                        if (line.indexOf("soundfont \"") >= 0 && line.lastIndexOf('"') >= 0) {
                            try {
                                String st = line.substring(line.indexOf("soundfont \"") + 11,
                                        line.lastIndexOf('"'));
                                soundfonts.add(st);
                            } catch (ArrayIndexOutOfBoundsException e1) {
                                e1.printStackTrace();
                            }

                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    eee.putString("tplusSoundfonts", ObjectSerializer.serialize(soundfonts));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            eee.commit();
            return true;
        } else {
            // Should probably check if 8rock11e exists no matter what
            eee.putBoolean("manConfig", false);

            AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {

                ProgressDialog pd;

                @Override
                protected void onPreExecute() {
                    pd = new ProgressDialog(a);
                    pd.setTitle(a.getResources().getString(R.string.extract));
                    pd.setMessage(a.getResources().getString(R.string.extract_sum));
                    pd.setCancelable(false);
                    pd.setIndeterminate(true);
                    pd.show();
                }

                @Override
                protected Void doInBackground(Void... arg0) {

                    if (extract8Rock(a) != 777) {
                        Toast.makeText(a, "Could not extrct default soundfont", Toast.LENGTH_SHORT).show();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                    if (pd != null)
                        pd.dismiss();
                    ArrayList<String> tmpConfig = new ArrayList<String>();
                    tmpConfig.add(rootStorage.getAbsolutePath() + "/soundfonts/8Rock11e.sf2");
                    try {
                        eee.putString("tplusSoundfonts", ObjectSerializer.serialize(tmpConfig));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    eee.commit();
                    writeCfg(a, rootStorage.getAbsolutePath() + "/timidity/timidity.cfg", tmpConfig);
                    ((TimidityActivity) a).initCallback();
                }

            };
            task.execute((Void[]) null);
            return false;
        }

    } else {
        return true;
    }
}

From source file:com.xperia64.timidityae.Globals.java

public static int[] updateRates() {
    if (prefs != null) {
        int[] values = Globals.validRates(prefs.getString("sdlChanValue", "2").equals("2"),
                /*prefs.getString("tplusBits", "16").equals("16")*/true);
        CharSequence[] hz = new CharSequence[values.length];
        CharSequence[] hzItems = new CharSequence[values.length];
        boolean validRate = false;
        for (int i = 0; i < values.length; i++) {
            hz[i] = Integer.toString(values[i]) + "Hz";
            hzItems[i] = Integer.toString(values[i]);
            if (prefs
                    .getString("tplusRate",
                            Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM)))
                    .equals(hzItems[i])) {
                validRate = true;/* w  ww.j a  v a  2s. c  o  m*/
                break;
            }
        }

        if (!validRate)
            prefs.edit()
                    .putString("tplusRate",
                            Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM)))
                    .commit();

        return values;
    }
    return null;
}

From source file:com.xperia64.timidityae.Globals.java

public static boolean updateBuffers(int[] rata) {
    if (rata != null) {
        SparseIntArray buffMap = Globals.validBuffers(rata, prefs.getString("sdlChanValue", "2").equals("2"),
                true/*prefs.getString("tplusBits", "16").equals("16")*/);
        int realMin = buffMap.get(Integer.parseInt(prefs.getString("tplusRate",
                Integer.toString(AudioTrack.getNativeOutputSampleRate(AudioTrack.MODE_STREAM)))));
        if (buff < realMin) {
            prefs.edit().putString("tplusBuff", Integer.toString(buff = realMin)).commit();
            return false;
        }//  w  w w  .j av a2 s .  c om
    }
    return true;
}