File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -384,6 +384,21 @@ final class ManagedAudioRecorderContext : RecoderContextRenderer {
384384 buffer. mDataByteSize*= 3
385385 }
386386
387+ if ( sampleRate== 24000 ) {
388+ let initialBuffer = malloc ( Int ( buffer. mDataByteSize+ 1 ) ) ;
389+ memcpy ( initialBuffer, buffer. mData, Int ( buffer. mDataByteSize) ) ;
390+ buffer. mData= realloc ( buffer. mData, Int ( buffer. mDataByteSize*2) )
391+ let values = initialBuffer!. assumingMemoryBound ( to: Int16 . self)
392+ let resampled = buffer. mData!. assumingMemoryBound ( to: Int16 . self)
393+ values [ Int ( buffer. mDataByteSize/ 2 ) ] = values [ Int ( buffer. mDataByteSize/ 2 ) - 1 ]
394+ for i : Int in 0 ..< Int ( buffer. mDataByteSize/ 2 ) {
395+ resampled [ i*2] = values [ i]
396+ resampled [ i*2+ 1 ] = values [ i] / 2 + values[ i+ 1 ] / 2
397+ }
398+ free ( initialBuffer)
399+ buffer. mDataByteSize*= 2
400+ }
401+
387402 defer {
388403 free ( buffer. mData)
389404 }
You can’t perform that action at this time.
0 commit comments