I need to send text to server, get wav streaming data (Base64 form and locally converting to byteArray), save and play the files. As retrofit cannot process larger than around 5 million characters I am splitting the text into pieces and getting the several wav streaming data. Now my target is to save the fetched multiple wav data into one file and play further.
But the problem is when I am concatenating the stream data(byteArray), the files playing the first one only. I googled and searched in SO for solutions but it is not working at all. what could be the reason(could be for header issue and I tried skipping first 44 length from 2nd one).
this is how tried
if (count == 0)
allByteArray += clipData
else
allByteArray += clipData.copyOfRange(44,clipData.size)
count += 1
return until all arrayByte
val output = FileOutputStream(file,true)
output.write(allByteArray)
output.close()
I solved the issue.
I have just updated the file size in header(sum of all files size replaced to index 40-43)
I am using JCODEC to create a video of my screen activities. I don’t want to use android NDK as I want to do it in JAVA. I am running a for loop to encode images using SequenceEncoder. The problem is the loop is taking too long to run and log cat gives messages of GC_FOR_ALLOC freed. For even 5 iterations the loop takes many seconds. So I am unable to take proper video of my activities. I tried to make changes in the code but its not helping. Please help me with this. Suggest other options if available. Thanks in advance.
File file = new File(Environment.getExternalStorageDirectory()+"/a.mp4");
SequenceEncoder encoder = new SequenceEncoder(file);
mview.setDrawingCacheEnabled(true);
// only 5 frames in total
for (int i = 1; i <= 5; i++) {
// getting bitmap from drawable path
mview.postInvalidate();
encoder.encodeNativeFrame(this.fromBitmap(mview.getDrawingCache()));
}
encoder.finish();
I have followed this example to convert raw audio data coming from AudioRecord to mp3, and it happened successfully, if I store this data in a file the mp3 file and play with music player then it is audible.
Now my question is instead of storing mp3 data to a file i need to play it with AudioTrack, the data is coming from the Red5 media server as live stream, but the problem is AudioTrack can only play PCM data, so i can only hear noise from my data.
Now i am using JLayer to my require task.
My code is as follows.
int readresult = recorder.read(audioData, 0, recorderBufSize);
int encResult = SimpleLame.encode(audioData,audioData, readresult, mp3buffer);
and this mp3buffer data is sent to other user by Red5 stream.
data received at other user is in form of stream, so for playing it the code is
Bitstream bitstream = new Bitstream(data.read());
Decoder decoder = new Decoder();
Header frameHeader = bitstream.readFrame();
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(frameHeader, bitstream);
short[] pcm = output.getBuffer();
player.write(pcm, 0, pcm.length);
But my code freezes at bitstream.readFrame after 2-3 seconds, also no sound is produced before that.
Any guess what will be the problem? Any suggestion is appreciated.
Note: I don't need to store the mp3 data, so i cant use MediaPlayer, as it requires a file or filedescriptor.
just a tip, but try to
output.close();
bitstream.closeFrame();
after yours write code. I'm processing MP3 same as you do, but I'm closing buffers after usage and I have no problem.
Second tip - do it in Thread or any other Background process. As you mentioned these deaf 2 seconds, media player may wait until you process whole stream because you are loading it in same thread.
Try both tips (and you should anyway). In first, problem could be in internal buffers; In second you probably fulfill Media's input buffer and you locked app (same thread, full buffer cannot receive your input and code to play it and release same buffer is not invoked because writing locks it...)
Also, if you don't doing it now, check for 'frameHeader == null' due to file end.
Good luck.
You need to loop through the frames like this:
While (frameHeader = bitstream.readFrame()){
SampleBuffer output = (SampleBuffer) decoder.decodeFrame(frameHeader, bitstream);
short[] pcm = output.getBuffer();
player.write(pcm, 0, pcm.length);
bitstream.close();
}
And make sure you are not running them on main thread.(This is probably the reason of freezing.)
I'd like to capture the outgoing audio from a game and record it into an audio file as it's played. Is this possible within the framework in OpenSL? Like by connecting the OutputMix to an AudioRecorder, or something?
You could register a callback to the queue and obtain the output buffer before / after it is enqueued into the buffer queue for output. You could have a wavBuffer (a short array the length of the buffer size) that is written into on each enqueueing of a new buffer. The contents of this buffer are then written to a file.
outBuffer = p->outputBuffer[p->currentOutputBuffer]; // obtain float buffer
for ( int i = 0; i < bufferSize; ++i )
wavBuffer = ( short ) outBuffer[ i ] * 32768; // convert float to short
// now append contents of wavBuffer into a file
The basic OpenSL setup for the queue callback is explained in some detail on this page
And a very basic means of creating a WAV file in C++ can be found here note that you must have a pretty definitive idea of the actual size of the total WAV file as it's part of its header.
I have an android application that records AUDIO in raw format
how can i extract a sample of the recording?
for example if the raw file has 3 minutes of audio recorded, i would like to extract 20 seconds of the contents from an arbitrary start position
is this possible?
If the file contains interleaved PCM data with no header and you know the properties of the audio data (sample rate, number of channels, etc) the problem can be solved with basic math:
The number of bytes of audio data per second is sampleRate * bytesPerSample * numChannels.
The starting offset in bytes would be then be bytesPerSecond * offsetInSeconds, and the size of the chunk to read (in bytes) would be bytesPerSecond * lengthInSeconds.