Does Goertzel algorithm works over analog signal? - rtp

My SIP phone is getting a tone(ringback) in regular rtp packet in PCMU payload (not using the rfc 2833 supported payload formats). To detect if tone or speech is present in rtp data Goertzel algorithm should be used. I am new to this domain and not able to understand how to provide input from received rtp packet to Goertzel algo? or does this algo takes analog signal as input?

Decode the PCMU to signed 16-bit linear PCM and pass each packet to the Goertzel algorithm.
Depending on the library you are using you may need to convert to unsigned or perhaps even float, but signed 16-bit is most likely.
Standard code to convert to signed 16-bit linear PCM can be found here.

Related

Converting PCM-ALAW data to an audio file using ffmpeg

In my project, I processed the received RTP packets with the payload, and extracted all the payload to a separate buffer. This payload is - PCM ALAW (Type 8). How do I implement a class that will take as arguments - the file name and a buffer with raw data to create an audio file. Exactly what steps do I have to go through in order to encode raw data into an audio file? As an example, I used this example.
That sounds way too complex. "PCM ALAW" is a bit misleading, but it's pretty clear that G.711 aLaw encoding is meant. That's a trivial "compression" which maps each 16 bits PCM sample to an 8 bits value. So a trivial lookup fixes that.
There's even a Free implementation of the aLaw encoding available. Just convert each sample to 16 bits PCM, stuff a standard Microsoft WAVE header in front of it, and call the result .WAV.
You'll need to fill in a few WAV headers based on the RTP type 8. Chiefly, that's "Mono, 8000 Hz, 16 bits per sample". One small problem with the header is that you can only write the full header once you know how many samples you have. You could update the header whenever you receive a RTP packet, but that's a bit I/O intensive. It might be nicer to do that once per 10 packets or so.

Avcodec : generate OPUS header for a stream

I'm using OPUS with avcodec to encode sounds and stream it using my own protocol.
It works with the MP2 codec so far but when I'm switching to OPUS, I have this issue :
[opus # 1b06d040] Error parsing the packet header.
I suppose that unlike MP2, I need to generate a header for my OPUS encoded data stream but I don't know how.
Can someone explain me how to do that? Thanks.
This error comes from ff_opus_parse_packet() failing, which handles the raw opus packet header, what the specification calls the 'TOC' (for table-of-contents) byte and optional subframe lengths. It means libavcodec couldn't find the packet duration where it expected.
So probably your custom protocol is corrupting the data, returning the wrong data length, or you're otherwise not splitting the opus packet out of your framing layer correctly.
You don't need to invent your own protocol if you don't want to. There are two established designs: Opus over RTP for interactive use (like live chat where latency matters) is documented in RFC 7587. For HTTP streaming, file storage for recording, playback and other applications like that use the Ogg container, documented here. There are implementations of both of these in libavformat. See rtpenc.c, oggenc.c and oggparseopus.c if you're curious about the details.

FFMPEG TS Null packet transmission

I am trying to transmit TS packets using Ethernet. I am using C++ and ffmpeg libraries. At the moment I can send a hevc encoded ts stream via Ethernet successfully. But the output data rate varies. I want to maintain a constant(approximately) data rate..
I am using "av_interleaved_write_frame()" to transmit the TS packets.
I know this can be achieved using NULL packet transmission. Can anyone tell me how to do this using ffmpeg?
Thank you.
What you are trying to achieve is called Constant BitRate: you should set minrate, maxrate and bitrate to the same value to get it.
cf similar questions for more detailed examples:
https://superuser.com/a/314355/329216
How to force Constant Bit Rate using FFMPEG
And interesting external links:
https://support.octoshape.com/entries/25126002-Encoding-best-practices-using-ffmpeg

Resample PCM network stream to 8000Hz 8-bit mono via libsndfile sf_open_virtual function

My goal is to take a PCM stream in Node.js that is, even for example, 44100Hz 16 bit stereo, and then resample it to 8000 Hz 8 bit mono to then be encoded into Opus and then streamed.
My thought was to try making bindings for libsndfile in C++ and using sf_open_virtual function for resampling on the stream. However:
How can I reply to its callback function requesting a certain amount
of data (found here:
http://www.mega-nerd.com/libsndfile/api.html#open_virtual) if my
program is still receiving data from the network? Do I just let it
hang in a loop until the loop detects that the buffer is a certain
percent full?
Since the PCM data is going to be headerless, how can
I specify the format type for libsndfile to expect?
Or am I over-complicating things totally?

Convert between different wave formats (WAVEFORMATEX)

I'm writing a real-time audio application that runs a stream in exclusive mode. In order to properly present data to the device, it needs to arrive in a format that isn't of my own choosing. All of my audio processing is done with floating point samples before being sent to the device, and the device's wave format might not be (and probably isn't) set to WAVE_FORMAT_IEEE_FLOAT - for example, it might be WAVE_FORMAT_EXTENSIBLE or WAVE_FORMAT_PCM.
Is there an API that makes it easy to convert between one wave format (floating point) and another (the device's format)?
Use an Audio Compression Manager (ACM) conversion stream:
Converting Data from One Format to Another
If you cannot create a single stream from your format to the device's format, you will have to create two streams - one from your format to WAVE_FORMAT_PCM, and the other from WAVE_FORMAT_PCM to the device's format (all streams/devices have to support conversions to/from PCM).