Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Noise or Distortion Sound During Audio Recording Using PR #85 #254

Closed
isandeepj opened this issue Sep 22, 2023 · 3 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@isandeepj
Copy link

isandeepj commented Sep 22, 2023

Hello @hiroshihorie and team,

I have been exploring the audio recording feature introduced in Pull Request #85. I'm utilizing the Room.audioProcessingModule.capturePostProcessingDelegate for this purpose, however, I am encountering an issue where the recorded audio has a noise or distortion sound.

Here is a link to the AudioRecorderHandler implementation I am using:
AudioRecorderHandler.zip

I have checked the sample rates, bit depths, buffer sizes, and codec settings to ensure they are configured correctly, but the issue persists. I suspect it might be related to the audio processing settings or possibly a mismatch in configuration somewhere.

Could you please provide some insight or assistance on how I might resolve this? I would really appreciate any help or guidance you can provide.

Thank you for your time and consideration.

Best regards,
Sandeep

@isandeepj isandeepj added the enhancement New feature or request label Sep 22, 2023
@isandeepj isandeepj changed the title Issue with Robotic Sound During Audio Recording Using PR #85 Issue with Noise or Distortion Sound During Audio Recording Using PR #85 Sep 26, 2023
@isandeepj
Copy link
Author

@hiroshihorie can you please give your input on this!

@hiroshihorie
Copy link
Member

Hey did you figure it out ?

@isandeepj
Copy link
Author

Yes, for 32-bit floating-point audio data, the range is typically from -1.0 to 1.0. However, the audio frame sample range is not within this range, so it needs to be downscaled by a factor of 32768.

channelStride: 1
frameIndex: 0 sampleValue: -202.04233
frameIndex: 1 sampleValue: -165.478
frameIndex: 2 sampleValue: -436.00348
frameIndex: 3 sampleValue: -783.46893
frameIndex: 4 sampleValue: -753.1802
frameIndex: 5 sampleValue: -294.75992
frameIndex: 6 sampleValue: 152.50293
frameIndex: 7 sampleValue: 213.2728
frameIndex: 8 sampleValue: -2.9370422
frameIndex: 9 sampleValue: -132.95068
frameIndex: 10 sampleValue: -59.72957
frameIndex: 11 sampleValue: 9.903137
frameIndex: 12 sampleValue: -86.191154
... 
private func convertToPCMBuffer(_ audioBuffer: RTCAudioBuffer) -> AVAudioPCMBuffer? {
    // ... (rest of code)

    for channelIndex in 0..<numChannels {
        let audioBufferPointer = audioBuffer.rawBuffer(forChannel: channelIndex)

        guard let targetBufferPointer = pcmBuffer.floatChannelData?[channelIndex] else {
            print("Failed to get target buffer for channel \(channelIndex)")
            return nil
        }
        // Now normalize and copy the data
        var targetChannelPointer = targetBufferPointer
        let normalizationFactor: Float = 32768.0  // This value is used to normalize the audio sample values
        for frameIndex in 0..<numFrames {
            let sampleValue = audioBufferPointer[frameIndex]
            let normalizedSampleValue = sampleValue / normalizationFactor  // Normalizing the sample value
            targetChannelPointer[frameIndex * channelStride] = normalizedSampleValue
        }
    }

    // ... (rest of code)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants