Audio Noise Issue

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

ShilpiR_beesys

  • Posts: 11
  • Joined: Mon Apr 22, 2019 7:15 am
  • Real Name: Shilpi Rustagi

Audio Noise Issue

PostThu Aug 29, 2019 10:53 am

Hi....

I am using DeckLink Quad2 card and Blackmagic DeckLink SDK 10.11.4.. Do I have any way to know that the live video I am capturing using ATEM switcher does have an audio or not.. actually the issue is when I am capturing the live through ATEM switcher there is some noise coming from the live iff the live is not having any audio and the noise is constantly increasing... PFA the pcm that is created on capturing audio packet from function VideoInputFrameArrived
Code: Select all
HRESULT    DeckLinkDevice::VideoInputFrameArrived (/* in */ IDeckLinkVideoInputFrame* videoFrame, /* in */ IDeckLinkAudioInputPacket* audioPacket)
{

   if (audioPacket)
   {
      long lSampleCount = 0;
      lSampleCount = audioPacket->GetSampleFrameCount();
      _audioSamplesPerframe = bmdAudioSampleType16bitInteger * 2 * lSampleCount;
      BYTE* pBYTE = NULL;
      audioPacket->GetBytes((LPVOID*)&pBYTE)
      if (m_pFileIn == NULL)
      {
         fopen_s(&m_pFileIn, "D:\\AudioIn.pcm", "wb+");
      }
      if (m_pFileIn)
      {
         fwrite(pBYTE, sizeof(BYTE), _audioSamplesPerframe, m_pFileIn);
      }
      int n = 0;
   }
}
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 212
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Audio Noise Issue

PostMon Sep 02, 2019 3:34 am

Hi Shilpi,

Thanks for providing your code sample, I can see 2 potential issues:
  • Assuming that you have enabled audio input with 2 channels, your calculation for _audioSamplesPerframe is actually the bit length (as bmdAudioSampleType16bitInteger = 16), whereas the call to fwrite is expecting byte count
  • I would avoid performing any file writes within the context of VideoInputFrameArrived callback, This operation has potential to delay subsequent VideoInputFrameArrived callback and if continual callback delay, this would eventually lead to drop frames. Increment the reference to IDeckLinkAudioInputPacket, store in a queue and handle in a different thread context. Refer to the FileCapture sample for example of how to do this (Desktop Video SDK 11.3).

Regards
Cameron
Offline

ShilpiR_beesys

  • Posts: 11
  • Joined: Mon Apr 22, 2019 7:15 am
  • Real Name: Shilpi Rustagi

Re: Audio Noise Issue

PostThu Sep 19, 2019 1:27 pm

Hi Cameron,

I wrote the following code now... I pushed the Audio Buffer in a queue in the function VideoInputFrameArrived() and then accessed the queue in another function and wrote the byte buffer in a PCM file.. then also I am getting the noise and it is only in the case when I take more than 1 input (without audio) from ATEM 2 M/E Production Studio 4k and the output is also from the same ... If I take the output from another Switcher then i cannot hear any noise.. Please help

Code: Select all
HRESULT    DeckLinkDevice::VideoInputFrameArrived (/* in */ IDeckLinkVideoInputFrame* videoFrame, /* in */ IDeckLinkAudioInputPacket* audioPacket)
{
   if (audioPacket)
   {
      long lSampleCount = 0;
      lSampleCount = audioPacket->GetSampleFrameCount();
      _audioSamplesPerframe =  (bmdAudioSampleType16bitInteger/8) * 16 * lSampleCount;
      BYTE* pBYTE = NULL;
      audioPacket->GetBytes((LPVOID*)&pBYTE);
      _cs.Lock();
      _AudioByteBuffQueue.push(pBYTE);
      _cs.UnLock();
   }
}
Init()
{
hr = m_deckLinkInput->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, 16);
}

Offline

Cameron Nichols

Blackmagic Design

  • Posts: 212
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Audio Noise Issue

PostTue Sep 24, 2019 8:09 am

Hi Shilpi,

Thanks for your code sample. I do see a potential issue, let me explain:
  • On entry to VideoInputFrameArrived callback, you have IDeckLinkAudioInputPacket pointer, this is a COM object with reference count of 1
  • Inside callback you access audio buffer and add to queue
  • On exit of callback, the IDeckLinkAudioInputPacket pointer is released and object is destroyed.
  • Later when you read audio buffer from queue, buffer is invalid
A better solution would be to add IDeckLinkAudioInputPacket to queue (similar to FileCapture SDK sample), remembering to call AddRef to keep the interface object valid after callback. Remember to pair AddRef() with a call to Release() when the IDeckLinkAudioInputPacket object is no longer required to avoid memory leak. Better yet, you can use com_ptr.h (eg from QuadPreview SDK sample), or ATL CComPtr (if developing with Visual Studio) to manage the interface reference counts for you.

Regards
Cameron

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 4 guests