Malii
Malii

Reputation: 448

Appending .aac files in Java/Android

I'm fairly new to working with audio files in Java and fairly new to Android (I know some basics).

I have two .aac files recorded using MediaRecorder and I needed to merge the two after a recording has taken place. I figured I'd attempt it in Java first and then move it over to Android since a lot looks pretty similar?

I was wondering what is the best way to achieve this? So far I've converted the .aac files to byte arrays and merging these however this only produces the first file (from the first byte array) with a bigger file size and no extra audio.

I thought perhaps this is due to audio headers? Should I find a way to target these bytes and remove them from the second (if so is there a documentation explaining where the header is?)

Alternatively I've also read about using .wavs and instead of using MediaRecorder use AudioRecord, create two PCM's, concatenate and then convert to .wav? Would I be able to then convert that .wav to .aac?

What is the fastest way of implementing this? Does anyone have any extra documentation that could help?

Upvotes: 1

Views: 893

Answers (1)

Malii
Malii

Reputation: 448

Thanks to Gabe, sending me down the right course.

In the end I ditched working with .aac's and attempting to remove headers. I used AudioRecord to record .pcm files, then concatenated these and saved as a .wav.

I did struggle with the sound sounding fast forwarded and distorted and initially thought it was down to the sample rate, it turns out I was converting between short to byte which was losing information, thus speeding up and the reason for the distortion.

Hope this helps someone, I might end up adding some .aac encoding library to reduce the size.

Some links I found helpful on my journey.

https://github.com/newventuresoftware/WaveformControl

Android AudioRecord example

How to convert .pcm file to .wav or .mp3?

http://www.topherlee.com/software/pcm-tut-wavformat.html

Upvotes: 1

Related Questions