CODE SNIPPET - PROCESSING AN AUDIO FRAME // get the codec context AVCodecContext *codecCtx = _audioStream->codec; // source variables int64_t sourceChannelLayout = AV_CH_LAYOUT_STEREO; int sourceSampleRate = 44100; enum AVSampleFormat sourceSampleFormat = AV_SAMPLE_FMT_FLT; int sourceNumberOfChannels = av_get_channel_layout_nb_channels(sourceChannelLayout); int sourceLineSize = 0; int sourceNumberOfSamples = (int)sampleBuffer.numberOfSamples; uint8_t *sourceData = NULL; // destination variables int64_t destinationChannelLayout = AV_CH_LAYOUT_STEREO; int destinationSampleRate = 44100; enum AVSampleFormat destinationSampleFormat = _outputSampleFormat; int destinationNumberOfChannels = av_get_channel_layout_nb_channels(destinationChannelLayout); int destinationLineSize = 0; int destinationNumberOfSamples = (int)av_rescale_rnd(sourceNumberOfSamples, destinationSampleRate, sourceSampleRate, AV_ROUND_UP); uint8_t *destinationData = NULL; // resample the audio to convert to a format that FFmpeg can use // allocate a resampler context static struct SwrContext *resamplerCtx; resamplerCtx = swr_alloc_set_opts(NULL, destinationChannelLayout, destinationSampleFormat, destinationSampleRate, sourceChannelLayout, sourceSampleFormat, sourceSampleRate, 0, NULL); if (resamplerCtx == NULL) { // handle error } // allocate the source samples buffer int returnVal = av_samples_alloc(&sourceData, &sourceLineSize, sourceNumberOfChannels, sourceNumberOfSamples, sourceSampleFormat, 1); if (returnVal < 0) { // handle error } // allocate the destination samples buffer returnVal = av_samples_alloc(&destinationData, &destinationLineSize, destinationNumberOfChannels, destinationNumberOfSamples, destinationSampleFormat, 1); if (returnVal < 0) { // handle error } // fill the source samples buffer returnVal = av_samples_fill_arrays(&sourceData, &sourceLineSize, sampleBuffer.bytesForAllSamples, sourceNumberOfChannels, sourceNumberOfSamples, sourceSampleFormat, 1); if (returnVal < 0) { // handle error } // convert to destination format returnVal = swr_convert(resamplerCtx, &destinationData, destinationNumberOfSamples, (const uint8_t **)&sourceData, sourceNumberOfSamples); *** The above line crashes with an EXC_ARITHMETIC error, generally the result of divide by 0