audiotrack

Immediate Audio Input & Output Android

与世无争的帅哥 提交于 2019-12-03 22:31:17
In my Android App, I would like to take in some audio from the mic of the smartphone and play it immediately, live, like a microphone, with no lag. I am currently thinking of using AudioRecord and AudioTrack classes (from what I have read), but I'm not quite sure how to proceed. I checked out some other questions on Stack Overflow but they don't exactly answer what I would like to do. And most are from 2012. So how can I use these classes to input and output audio simultaneously? ALSO: I had a look at the MediaRecorder API , but from what I read, that requires you to save the audio to a file,

Android:Creating Wave file using Raw PCM, the wave file does not play

依然范特西╮ 提交于 2019-12-03 21:26:03
I have created the header for the wave file, but the wave file which is created does not play. I have used this https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ as a reference to create the wave header. public void WriteWaveFileHeader() throws IOException { File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/aaa.wav"); f.createNewFile(); FileOutputStream fos = new FileOutputStream(f); long longSampleRate=44100; int channels= AudioFormat.CHANNEL_IN_MONO; long totalAudioLen=fos.getChannel().size(); long byteRate=(16 * 44100)/8; long totalDataLen

PCM Raw Bytes [] To Audio on Android

社会主义新天地 提交于 2019-12-03 18:44:10
问题 I currently have a PCM audio in the form of a byte array. The format is signed 16 bit little endian. I would like to convert this to some playable format on the Android, preferably version 3.2 or higher. Does anyone have suggestions on how this can be done? I have done some research and tried the following below, but none were successful. It would be much appreciated if anyone can suggest a better way or indicate where I have gone wrong. I have tried creating an AudioFormat with the correct

Play Audio (mp3, ogg) from sd card with AudioTrack

最后都变了- 提交于 2019-12-03 16:19:08
I want to play audio file from SD card with AudioTrack. I've tried with this code: int minBufferSize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT); int bufferSize = 512; AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM); int i = 0; byte[] s = new byte[bufferSize]; FileInputStream fin = new FileInputStream(path); DataInputStream dis = new DataInputStream(fin); at.play(); while ((i = dis.read(s, 0, bufferSize))

Android - Mixing multiple static waveforms into a single AudioTrack

拈花ヽ惹草 提交于 2019-12-03 13:36:32
问题 I am making a class that takes an array of frequencies values (i.e. 440Hz, 880Hz, 1760Hz) and plays how they would sound combined into a single AudioTrack. I am not a sound programmer, so this is difficult for me to write myself, where I believe that it is a relatively easy problem to an experienced sound programmer. Here is some of the code below in the play method: public void play() { // Get array of frequencies with their relative strengths double[][] soundData = getData(); // TODO //

Sample code for Android AudioTrack Mixing

自作多情 提交于 2019-12-03 07:54:52
问题 I have two PCM sound file in resource folder. I used inputstream and converted them into bytearray. Then I processed them by normalized and adding music1 and music2 and output to the byte array output. Finally, put the output array and feed it to the AudioTrack. Obviously, I don't hear anything and something is wrong. private void mixSound() throws IOException { InputStream in1=getResources().openRawResource(R.raw.cheerapp2); InputStream in2=getResources().openRawResource(R.raw.buzzer2); byte

Using a buffer with Android AudioTrack

六月ゝ 毕业季﹏ 提交于 2019-12-03 06:10:23
问题 I'm trying to figure how I would use a buffer with AudioTrack to effectively stream music. I know you can queue audio using the write method but once the audio is queued how do you tell how much is left vs. how much has been used/played? Sorry if this is a rudimentary question. I understand the concept of a buffer I'm just not sure how to write one, especially using AudioTrack. 回答1: AudioTrack.write() returns "number of bytes written" as an int, and you specify the number of bytes in the

AudioTrack: should I use an Asynctask, a Thread or a Handler?

社会主义新天地 提交于 2019-12-02 13:26:03
In Android: I am trying to play a wav file of size 230mb and 20 min whose properties are as below: ffmpeg -i 1.wav Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s The following is the code in android: float volchange=0.5f; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Code to set the volume change variable for the audiotrack Button volup = (Button) findViewById(R.id.volup); Button voldown = (Button) findViewById(R.id.voldown); volup.setOnClickListener(new View

Understanding AudioTrack Assertion in Android

霸气de小男生 提交于 2019-12-01 06:50:20
问题 In my Android app, I'm using the AudioTrack API to output audio bytes that I receive from a RFCOMM Bluetooth connection. The audio plays as expected and is very clear. However, the app occasionally crashes due to the following assertion in AudioTrackShared.cpp: stepCount <= mUnreleased && mUnreleased <= mFrameCount I'm not really sure of what this assertion entails, but does anyone have an idea of what could cause this issue? I can provide additional source code if needed: My setup for

AudioTrack: play() called on uninitialized AudioTrack

99封情书 提交于 2019-12-01 03:42:15
I'm experimenting with AudioTrack class. Basically, my app has to generate a sound when the user touches a specific object on screen. I've used this example as a guide. My app seems to work as it should but usually after touching the screen for about a minute it crashes: 07-02 20:40:53.459: E/AndroidRuntime(11973): FATAL EXCEPTION: Thread-10 07-02 20:40:53.459: E/AndroidRuntime(11973): java.lang.IllegalStateException: play() called on uninitialized AudioTrack. 07-02 20:40:53.459: E/AndroidRuntime(11973): at android.media.AudioTrack.play(AudioTrack.java:824) 07-02 20:40:53.459: E/AndroidRuntime