Skip to content

Commit

Permalink
Resample recording with sample rate 24kHZ (airpods)
Browse files Browse the repository at this point in the history
  • Loading branch information
dm3ch committed Jun 4, 2022
1 parent 96bf9d7 commit 2765252
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Telegram-Mac/AudioRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ final class ManagedAudioRecorderContext : RecoderContextRenderer {
buffer.mDataByteSize*=3
}

if(sampleRate==24000){
let initialBuffer=malloc(Int(buffer.mDataByteSize+1));
memcpy(initialBuffer, buffer.mData, Int(buffer.mDataByteSize));
buffer.mData=realloc(buffer.mData, Int(buffer.mDataByteSize*2))
let values = initialBuffer!.assumingMemoryBound(to: Int16.self)
let resampled = buffer.mData!.assumingMemoryBound(to: Int16.self)
values[Int(buffer.mDataByteSize/2)]=values[Int(buffer.mDataByteSize/2)-1]
for i: Int in 0 ..< Int(buffer.mDataByteSize/2) {
resampled[i*2]=values[i]
resampled[i*2+1]=values[i]/2+values[i+1]/2
}
free(initialBuffer)
buffer.mDataByteSize*=2
}

defer {
free(buffer.mData)
}
Expand Down

0 comments on commit 2765252

Please sign in to comment.