Cannot create AudioTrack with larger audio output latency.

by AndroidJimmy » Fri, 27 Feb 2009 15:03:46 GMT


Sponsored Links
 I meet a problem about creating AudioTrack failed with larger audio
output latency.
It fails in AudioTrack::set(), blocked by codes below:

    if (frameCount < minFrameCount) {
      LOGE("Invalid buffer size: minFrameCount %d, frameCount %d",
minFrameCount, frameCount);
      return BAD_VALUE;
    }

I think this code is for guaranteeing there are enough buffer and
sample in AudioTrack to wait for audio output consuming the output
data.

In MediaPlayerService::AudioOutput::open(),  AudioTrack is created by
codes below:

    new AudioTrack(mStreamType, sampleRate, format, channelCount,
frameCount*bufferCount);

framecount is determined by frameCount = (sampleRate*afFrameCount)/
afSampleRate; In most situation, sampleRate is usually 44100,
bufferCount is hard-code in PV(4) and SONIVOX_PLAYER/VORBIS_PLAYER
(DEFAULT_AUDIOSINK_BUFFERCOUNT 4).

So if there is a larger output latency, PV/SONIVOX_PLAYER/
VORBIS_PLAYER may not create an AudioTrack with enough bufferCount.
These may happen when output is a larger latency network device, such
as BlueTooth, etc.

Is there a way to prevent from creating AudioTrack fail under this
situation?
Thanks.
--~--~---------~--~----~------------~-------~--~----~



Cannot create AudioTrack with larger audio output latency.

by Dave Sparks » Sat, 28 Feb 2009 03:15:30 GMT


 There are a bunch of patches coming related to this in Cupcake. The
app can either ask for the default latency or it can ask for the
latency and request something bigger.



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. launching settings from my app

Hi there,
Has anybody got the right intent to open sound settings?  I find that
this line of code:
     startActivity(new Intent
(android.provider.Settings.ACTION_SETTINGS));
works great, while this line, which should open exactly the Settings
panel I need to show, does not work at all and my application force
closes.
     startActivity(new Intent
(android.provider.Settings.ACTION_SOUND_SETTINGS));
I also find that the ACTION_DISPLAY_SETTINGS works on the emulator and
then does not work on the Hero device.  Does anyone have a suggestion
of how to open the sound settings?

I am using a try/catch block and an error toast to defensively code my
app not to crash this way.  Thanks in advance for any help you might
offer.

Regards,
Beth

-- 

2. Database Errors

I been working on this code dealing with my database for days i can
figure out whats wrong.

Heres my code:
package com.helpihelpyou;


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.net.Uri;
import android.provider.Contacts.People;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;


public class HelpiDB {

    private static class HelpiDBHelper extends SQLiteOpenHelper {
        Context ctx;

        public HelpiDBHelper(Context context, String name, CursorFactory
factory, int version) {
            super(context, name, factory, version);
            this.ctx = context;
        }

        /*
         * Called when no database exists in disk and the helper class needs
to
         * create one.
         */
        @Override
        public void onCreate(SQLiteDatabase db) {
            try {
                db.execSQL(DATABASE_CREATE);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                // Form an array specifying which columns to return.
                String[] projection = new String[] { People._ID, People.NAME,
People.NUMBER,

                };

                // Get the base URI for the People table in the Contacts content
                // provider.
                Uri contacts = People.CONTENT_URI;

                // Make the query. To get the data

                Cursor c = ctx.getContentResolver().query(contacts, projection,
null, null,
                                                          null);

                int numRows = c.getCount();
                c.isFirst();
                c.moveToFirst();

                for (int i = 0; i < numRows; ++i) {
                    Row row = new Row();
                    row._id = c.getLong(0);
                    row.name = c.getString(1);
                    row.number = c.getString(2);
                    ContentValues initialValues = new ContentValues();
                    initialValues.put("name", row.name);
                    initialValues.put("number", row.number);
                    Boolean check = false;
                    initialValues.put("check", check.toString());

                    db.insertOrThrow(DATABASE_TABLE, null, initialValues);
                    c.moveToNext();
                }
            } catch (SQLiteException e) {
                e.printStackTrace();
            }
        }

        /*
         * Upgrade the existing database to conform to the new version
Multiple
         * previous versions can be handled by comparing _oldVersion and
         * _newVersion values.
         *
         * The simplest case is to drop the old table and create a new one
         */

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
            onCreate(db);
        }

    }

    public static final int CHECK_COLUMN = 3;

    public static final String KEY_CHECK = "check";
    // The index (key) column name for use in where clauses.
    public static final String KEY_ID = "_id";

    // The name and column index of each column in your database.
    public static final String KEY_NAME = "name";

    public static final String KEY_NUMBER = "number";

    public static final int NAME_COLUMN = 1;
    public static final int NUMBER_COLUMN = 2;

    private static final String DATABASE_CREATE = "create table "
                                                  + "HELPITABLE"
                                                  + " (_id integer primary key 
autoincrement, "
                                                  + "name text not null, "
                                                  + "number text not null, "
                                                  + "check text not null" + 
");";

    private static final String DATABASE_NAME = "HELPIDB";
    private static String DATABASE_PATH = "/data/data/com.helpihelpyou/
databases/";

    private static final String DATABASE_TABLE = "HELPITABLE";

    private static final int DATABASE_VERSION = 1;

    private final Context ctx;

    private SQLiteDatabase db;

    private final HelpiDBHelper dbHelper;

    public HelpiDB(Context context) {
        this.ctx = context;
        ctx.deleteDatabase(DATABASE_NAME);
        dbHelper = new HelpiDBHelper(context, DATABASE_NAME, null,
DATABASE_VERSION);

    }

    public boolean checkDataBase() {

        SQLiteDatabase checkDB = null;

        try {
            String myPath = DATABASE_PATH + DATABASE_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READONLY);

        } catch (SQLiteException e) {

            // database does't exist yet.

        }

        if (checkDB != null) {

            checkDB.close();

        }

        return checkDB != null ? true : false;
    }

    public void close() {
        if (db != null) {
            db.close();
        }

    }

    public void create() throws SQLiteException {
        boolean dbExist = checkDataBase();
        if (dbExist) {
            // If db exist do nothing
        } else {
            db = ctx.openOrCreateDatabase(DATABASE_NAME, 0, null);
            db.execSQL(DATABASE_CREATE);
            db = ctx.openOrCreateDatabase(DATABASE_NAME, 0, null);

            // Form an array specifying which columns to return.
            String[] projection = new String[] { People._ID, People.NAME,
People.NUMBER,

            };

            // Get the base URI for the People table in the Contacts content
            // provider.
            Uri contacts = People.CONTENT_URI;

            // Make the query. To get the data

            Cursor c = ctx.getContentResolver().query(contacts, projection,
null, null, null);

            int numRows = c.getCount();
            c.isFirst();
            c.moveToFirst();

            for (int i = 0; i < numRows; ++i) {
                Row row = new Row();
                row._id = c.getLong(0);
                row.name = c.getString(1);
                row.number = c.getString(2);
                createRow(row.name, row.number, false);
                c.moveToNext();
            }
        }
    }

    public void createRow(String name, String number, Boolean check) {
        ContentValues initialValues = new ContentValues();
        initialValues.put("name", name);
        initialValues.put("number", number);
        initialValues.put("check", check.toString());

        db.insertOrThrow(DATABASE_TABLE, null, initialValues);

    }

    public void deleteRow(long rowId) {
        db.delete(DATABASE_TABLE, "_id=" + rowId, null);
    }

    public List<Row> fetchAllRows() {
        ArrayList<Row> ret = new ArrayList<Row>();
        try {
            Cursor c = db.query(DATABASE_TABLE, new String[] { "_id", "name",
"number",
                                                              "email", "owner" 
}, null, null,
                                null, null, null);
            int numRows = c.getCount();
            c.isFirst();
            c.moveToFirst();
            for (int i = 0; i < numRows; ++i) {
                Row row = new Row();
                row._id = c.getLong(0);
                row.name = c.getString(1);
                row.number = c.getString(2);
                ret.add(row);
                c.moveToNext();
            }
        } catch (SQLException e) {
            Log.e("Exception on query", e.toString());
        }
        return ret;
    }

    public Cursor GetAllRows() {
        try {
            return db.query(DATABASE_TABLE, new String[] { "_id", "name",
"number", "check" },
                            null, null, null, null, null);
        } catch (SQLException e) {
            Log.i("Error on query", e.toString());
            return null;
        }

    }

    public HelpiDB open() throws SQLiteException {
        db = dbHelper.getWritableDatabase();
        return this;

    }

    public void updateRow(long rowId, String name, String number,
Boolean check) {
        ContentValues args = new ContentValues();
        args.put("name", name);
        args.put("number", number);
        args.put("check", check.toString());
        db.update(DATABASE_TABLE, args, "_id=" + rowId, null);
    }

}



I keep getting this error
11-03 17:54:37.302: WARN/System.err(1027):
android.database.sqlite.SQLiteException: near "check": syntax error: ,
while compiling: INSERT INTO HELPITABLE(check, number, name) VALUES
(?, ?, ?);

11-03 17:54:37.452: ERROR/AndroidRuntime(1027): Caused by:
java.lang.NullPointerException
11-03 17:54:37.452: ERROR/AndroidRuntime(1027):     at
com.helpihelpyou.InsertActivity.onCreate(InsertActivity.java:60)
 the error is on this line:

-- 

3. Timepicker appearances, the disabled state is ugly

4. ProgressDialog went back to the first view called it when dismiss()

5. Trouble with getting proximity alerts

6. Device orientation - mapping device Y to screen Y

7. Android NDK Socket programming