Reading the AudioTrack official documentation, I noticed I can write an array of float then read it in a streaming or a buffer mode:
public int write (float[] audioData, int offsetInFloats, int sizeInFloats, int writeMode) Added in API level 21
Writes the audio data to the audio sink for playback (streaming mode), or copies audio data for later playback (static buffer mode). In static buffer mode, copies the data to the buffer starting at offset 0, and the write mode is ignored. In streaming mode, the blocking behavior will depend on the write mode.
I tried using it in my code like this:
....
float[]raw2=bytesToFloats(read(f2));
int convhandle= FFTProcessor.createFastConvolutionContext(raw1.length, raw1, im1);
long t1=System.currentTimeMillis();
FFTProcessor.performFastConvolution(convhandle, raw2, im2);
long t2=System.currentTimeMillis()-t1;
int minSize=audio.getMinBufferSize(22050, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_8BIT);
audio = new AudioTrack(AudioManager.STREAM_MUSIC,22050, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_8BIT, minSize ,AudioTrack.MODE_STREAM);
audio.write(raw2, 0, raw2.length, WRITE_NON_BLOCKING);
audio.play();
......
But I get this error at the write() method:
The method write(byte[], int, int) in the type AudioTrack is not applicable for the arguments (float[], int, int, int)
I updated my sdk, and checked the manifest file, android:targetSdkVersion="21" />
but still dont know what's wrong.
minSdkVersion? - StenSoftminSdkVersionunless you decorate the class/method with@TargetApi. Note that using that call on lower API will crash your application. - StenSoft