Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions Sources/CSFBAudioEngine/Decoders/SFBMPEGDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ - (BOOL)openReturningError:(NSError **)error {

_processingFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
sampleRate:rate
interleaved:NO
interleaved:YES
channelLayout:channelLayout];

size_t bufferSizeBytes = mpg123_outblock(_mpg123);
Expand Down Expand Up @@ -435,22 +435,8 @@ - (BOOL)decodeIntoBuffer:(AVAudioPCMBuffer *)buffer frameLength:(AVAudioFrameCou
return NO;
}

// Deinterleave the samples
AVAudioFrameCount framesDecoded =
(AVAudioFrameCount)(bytesDecoded / (sizeof(float) * _buffer.format.channelCount));

float *const *floatChannelData = _buffer.floatChannelData;
AVAudioChannelCount channelCount = _buffer.format.channelCount;
for (AVAudioChannelCount channel = 0; channel < channelCount; ++channel) {
const float *input = (float *)audioData + channel;
float *output = floatChannelData[channel];
for (AVAudioFrameCount frame = 0; frame < framesDecoded; ++frame) {
*output++ = *input;
input += channelCount;
}
}

_buffer.frameLength = framesDecoded;
memcpy(_buffer.audioBufferList->mBuffers[0].mData, audioData, bytesDecoded);
_buffer.frameLength = (AVAudioFrameCount)(bytesDecoded / (_buffer.stride * sizeof(float)));
}

_framePosition += framesProcessed;
Expand Down
15 changes: 2 additions & 13 deletions Sources/CSFBAudioEngine/Decoders/SFBMusepackDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ - (BOOL)openReturningError:(NSError **)error {

_processingFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32
sampleRate:streaminfo.sample_freq
interleaved:NO
interleaved:YES
channelLayout:channelLayout];

// Set up the source format
Expand Down Expand Up @@ -324,18 +324,7 @@ - (BOOL)decodeIntoBuffer:(AVAudioPCMBuffer *)buffer frameLength:(AVAudioFrameCou
AVAudioChannelCount channelCount = _buffer.format.channelCount;
vDSP_vclip((float *)frame.buffer, 1, &minValue, &maxValue, (float *)frame.buffer, 1,
frame.samples * channelCount);

// Deinterleave the normalized samples
float *const *floatChannelData = _buffer.floatChannelData;
for (AVAudioChannelCount channel = 0; channel < channelCount; ++channel) {
const float *input = (float *)frame.buffer + channel;
float *output = floatChannelData[channel] + _buffer.frameLength;
for (uint32_t sample = 0; sample < frame.samples; ++sample) {
*output++ = *input;
input += channelCount;
}
}

memcpy(_buffer.audioBufferList->mBuffers[0].mData, frame.buffer, frame.samples * channelCount * sizeof(float));
_buffer.frameLength = frame.samples;
#endif /* MPC_FIXED_POINT */
}
Expand Down