How to convert the audio data to CMSampleBufferRef? - audio

I will to recoding audio to a video file by using AVAssetWriterInput, and the audio data is store in memory with byte array format.how can I do it?
I frind the CMAudioSampleBufferCreateWithPacketDescriptions function meet my request, any one has the sample to use it,by using byte array audio data?

Related

Why the stereo mp3 file lost a channel when converted from mp4 with ffmpeg?

I am following this tutorial https://hackernoon.com/audio-handling-basics-how-to-process-audio-files-using-python-cli-jo283u3y, and when I extract the data from the mp3 file, it is only an one dimensional array, while the data from wav file is 2D. I converted them from the same mp4 file with ffmpeg.
# read WAV file using scipy.io.wavfile
fs_wav, data_wav = wavfile.read("data/music_8k.wav")
# read MP3 file using pydub
audiofile = AudioSegment.from_file("data/music_8k.mp3")
data_mp3 = np.array(audiofile.get_array_of_samples())
fs_mp3 = audiofile.frame_rate
print(data_wav.shape) #(9835520, 2)
print(fs_wav) #44100
print(data_mp3.shape) #(19671040,)
print(fs_mp3) #44100
When I check the info of the mp3 file it says Stereo, but does the fact that data_mp3 is only one dimensional array mean it is actually mono? Did it lose one channel during converting? And how should I reshape the data if I want to confirm these two files have identical signal?
but does the fact that data_mp3 is only one dimensional array mean it is actually mono?
No.
And how should I reshape the data if I want to confirm these two files have identical signal?
Decode it back to a wav

what is audio PCM's frame sync word to identify the beginning position

As title; for some compressed format such as EAC3, AC3 frame starts as a sync word.
So what's PCM (raw audio)'s sync word? How to identify the beginning of a PCM frame?
I met a problem where audio is concatenated by several audio segments and each of them has different frame size. I need to identify the start position.
Thanks in advance.
There is no such concept as a frame in PCM. The concept of a frame is to indicate points of random access. In PCM every single sample is a point of random access, hence start indicators are not required, and there are no standard frame size. It all up to you.
A PCM frame is different from the frames you're describing, in that a frame is just a single sample on all channels. That is, if I'm recording 16-bit stereo PCM audio, each frame is 4 bytes (32 bits) long.
There is no sync word, nor frame header in raw PCM. It's just a stream of data. You need to know the bit depth, channel count, and current offset if you want to sync to it. (Or, you need to do some simple heuristics. For example, apply several different formats and offsets to a small chunk of data and see which one has the least variance/randomness from sample to sample.)

Increasing volume (power) of an companded A-law or U-law data without decoding

I have an 8Khz 8bit companded audio buffer with A-law or U-law. I want to increase the volume or power of this data so that it is more audible. I want to do this without decoding it to raw PCM data.
In case of raw data i can just multiple the data with integer number and increase the audio power. But if i do the same thing with A-law audio then it just gets distorted (which i was expecting as it is companded).
Is it possible to manipulate the a-law/u-law data directly to increase its volume or the only way is to decode and the increase volume and encode it back.

How to find AAC-LC (non-ADTS) audio packet length

I have AAC-LC audio stream coming directly from audio encoder.
Its a raw stream, No ADTS headers, no container data as I want to stream encoded audio directly as it arrives.(before file gets saved).
I want to determine the frame boundaries/frame lengths/packets lengths in incoming encoded raw AAC stream. (AAC has variable packet lengths.)
Can I search for any fixed frame headers/patterns so that I can determine frame boundaries?
Is it possible with AAC?
Thanks in advance for your valuable inputs.
If you are taking AAC encoded data directly from encoder then it's up to encoder to send frame by frame. It should not send "packets", but single frames. Otherwise I don't see a way you can parse for frames.
I'd first check if it really sends more than one frame at a time?
If yes, then one solution would be to tell encoder to send ADTS header, then parse info from ADTS, and finally strip down ADTS from the frame and stream it as raw.
Does that help?

How to get bit rate of audio file in Blackberry/j2me

I want to retrive the bit rate of an audio file for the purpose of spliting a raw byte information of an audio file at a particular second of complete length of file.Can any one suggest the way to get the bit rate for an audio file in Blackberry or j2me?

Resources