2011-01-24 8 views
9

Lo sto testando su un Samsung Galaxy S i9000.Perché AudioRecord.getMinBufferSize restituisce ERROR_BAD_VALUE (-2)?

int sampleRate = 44100; 
int bufferSize = AudioRecord.getMinBufferSize(sampleRate, 
    AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_8BIT); 

Esso restituisce -2 ERROR_BAD_VALUE.

La frequenza di campionamento nativa è 44100Hz, come restituito da

AudioTrack.getNativeOutputSampleRate (AudioManager.STREAM_SYSTEM).

Ho provato a fissare sampleRate a 1000, 8000, 22100 e 44100. Inoltre ho provato a cambiare AudioFormat.CHANNEL_IN_MONO-AudioFormat.CHANNEL_CONFIGURATION_MONO. Ho anche provato STEREO (sia IN_STEREO e CONFIGURATION_STEREO). Ho anche provato la codifica a 16 bit invece di 8 bit.

Update: il mio manifesto ha AUDIO_RECORD come il permesso.

Continuo a ricevere -2 di conseguenza. Perché sta succedendo?

+0

Ciao, ha fatto questo mai ottenere risolto, o qualsiasi intuizioni? Grazie. –

risposta

17

dal file di origine piattaforma AudioRecord.java:

static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) { 
    ... 
    // PCM_8BIT is not supported at the moment 
    if (audioFormat != AudioFormat.ENCODING_PCM_16BIT) { 
     loge("getMinBufferSize(): Invalid audio format."); 
     return AudioRecord.ERROR_BAD_VALUE; 
    } 
    ... 
} 

Sembra che la vostra scelta è a 16 bit o niente. : \

+1

+1. Ha detto che ha provato anche a 16 bit, quindi l'unico altro posto in quel metodo in cui può essere restituito ERROR_BAD_VALUE in getMinBufferSize è la riga 472-475. – McStretch

+0

Grazie per le informazioni. McStretch è corretto, ho anche provato ENCODING_PCM_16BIT. – Tom

+0

Ciò significa che native_get_min_buff_size (sampleRateInHz, channelCount, audioFormat) restituisce 0. Come può accadere? – Tom

0

In emulatore sarà sempre tornare -2. Con lo stesso codice andrà bene sul cellulare reale.

+0

sorry folk restituisce -2 anche sul dispositivo reale – IronBlossom

Problemi correlati