try the following code: private void rawToWave(final File rawFile, final File waveFile) throws IOException { byte[] rawData = new byte[(int) rawFile.length()]; DataInputStream input = null; try { input = new DataInputStream(new FileInputStream(rawFile)); input.read(rawData); } finally { if (input != null) { input.close(); } } DataOutputStream output = null; try {...
AudioTrack uses raw PCM samples to play sounds. The PCM samples are played in the following order (the first sample is played by the left speaker and the second sample is played by the right speaker): LRLRLRLRLR So you have to modify your samples array that you pass to AudioTrack....
android,codec,pcm,audiorecord,audiotrack
Ok guys, finally I resolved for myself the problem encoding/decoding audio. It's been a annoying task during the last week. The main problem of my code was the encoding was well done but the decoding wasn't so I was working around it and modify these class with the help of...
Stick to ENCODING_PCM_16BIT instead of ENCODING_PCM_8BIT (as stated in the documentation, it's not guaranteed to be supported by devices). Adjust your volume to maximum (1.0f or use getMaxVolume()) on left and right channel, instead of 0.1f (which is really low amplitude). Increase your buffer from 4410 (which is only 100ms...
android,audio-streaming,audiorecord,android-audiorecord,audiotrack
Ok solved, it's all about the sample rate and the buffer size.
android,android-5.0-lollipop,audiotrack
This unanswered question led me to a solution. If you call AudioTrack#stop() on Lollipop, even in conjunction with the methods that actually work, playback will not stop! You must use a condition like this: if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mPowerTone.pause(); mPowerTone.flush(); } else { mPowerTone.stop(); } Keep up the good work,...
if you are extending CursorAdapter, you can get the Cursor at position through the first argument of onListItemClick Cursor cursor = (Cursor) list.getItemAtPosition(position); item = cursor.getString(cursor. getColumnIndex(MediaStore. MediaColumns.DATA)); Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show(); ...
It looks like you're filling the entire samples buffer with the sine wave - if the bufferSize is not a multiple of the frequency you're generating then you're going to be partially through a wave when the next sample starts playing - that might be what's causing the pops. You...
android,audio-recording,android-audiomanager,android-audiorecord,audiotrack
It is a simple fix but might be an Android issue, please refer to my fix below if (track != null && track.getState() != AudioTrack.STATE_UNINITIALIZED) { if (track.getPlayState() != AudioTrack.PLAYSTATE_STOPPED) { try{ track.stop(); }catch (IllegalStateException e) { e.printStackTrace(); } } track.release(); am.setMode(AudioManager.MODE_NORMAL); //track.release(); //track = null; } and OnCreate private...
Most likely, the tap sound got a AUDIO_OUTPUT_FLAG_FAST in order to use low-latency playback if possible, but the AudioTrack class considered the track settings to be incompatible with the low-latency audio output, so the flag got removed and the track got treated as if the flag hadn't been set to...
android,timer,frequency,audiotrack
Thanks Boggartfly but I found a much simpler solution. I can simply loop the audiotrack object. I used the following code. audioTrack.setLoopPoints(0, generatedSnd.length/4, -1); The start frame is zero. The end frame is length/4 for 16bit PCM. The negative 1 here means loop infinite times. ...
android,audio,mediacodec,audiotrack,mediaextractor
As far as I read your code, you only try to dequeue output buffers once every time you manage to queue one input buffer. Keep in mind that the decoder runs asynchronously, and has got a limited number of input and output buffers. Even if the decoder does decode your...
You need to detect the end of audio track play of audio A. To do this you need to first get the audio length of audio A and set the audio track notification marker as follows audioTrack.setNotificationMarkerPosition(audioLength); Then implement the playback position update listener, and when the marker is reached...