Audio packets not recevied by mic after sending beep sound to the another side speaker from teensy4.1

I am working on a project using Teensy 4.1. In this project, the Teensy is only in receiving mode. It receives audio from another device’s microphone (not a Teensy) in the form of RTP packets.


During the call, I send a beep tone from the Teensy to the speaker on the other side. The beep plays correctly, but after that, I stop receiving incoming RTP packets from the other side’s microphone.


On the other side, the microphone and speaker are connected together, and I am doing one-way communication. After the call is connected, I send a beep tone so the other user knows they can start speaking.


Below is the output I am getting.


When I initiate the call, I receive packets correctly:


RTP active: 1 packets/sec
RTP active: 47 packets/sec
RTP active: 50 packets/sec


After that, I send the beep tone to the other side’s speaker from the Teensy 4.1 code:


RTP TX seq=1709 ts=89106
RTP TX codec=0 seq=1710 ts=89266 len=160
RTP TX seq=1710 ts=89266
RTP TX codec=0 seq=1711 ts=89426 len=160
RTP TX seq=1711 ts=89426
RTP TX codec=0 seq=1712 ts=89586 len=160
RTP TX seq=1712 ts=89586
RTP TX codec=0 seq=1713 ts=89746 len=160
RTP TX seq=1713 ts=89746
RTP TX codec=0 seq=1714 ts=89906 len=160
RTP TX seq=1714 ts=89906
RTP TX codec=0 seq=1715 ts=90066 len=160
RTP TX seq=1715 ts=90066
RTP TX codec=0 seq=1716 ts=90226 len=160
RTP TX seq=1716 ts=90226
RTP TX codec=0 seq=1717 ts=90386 len=160
RTP TX seq=1717 ts=90386
RTP TX codec=0 seq=1718 ts=90546 len=160
RTP TX seq=1718 ts=90546


Beep finished
RTP active: 16 packets/sec


After this, I am not receiving any more incoming RTP packets.


Can anyone please help me understand how to resume receiving incoming RTP packets after playing the beep tone?


Thank you.
 
Sketch code ?? It is almost impossible to give any kind of meaningful advice without any clues about what code you are executing !!

Mark J Culross
KD5RXT
 
Thank you for the reply.

I can’t share my full code here because I’m working on a company project, but I can provide a specific function from the code where I am sending the beep sound to the speaker on the other side.

this is the function for genrate beep sound
void playBeepToIpPhone(uint16_t freqHz = 1000, uint16_t durationMs = 200) {
if (!callActive || remoteRtpPort == 0) return;
Serial.println("🔔 Playing confirmation beep to IP phone");
ipTonePlaying = true;
CodecType toneCodec = activeCodec;
const int sampleRate =
(toneCodec == CODEC_G722) ? 16000 : 8000;
const int frameMs = 20;
const int samplesPerFrame = sampleRate * frameMs / 1000;
int totalSamples = sampleRate * durationMs / 1000;
int16_t pcm[320]; // max needed for G.722
float phase = 0.0f;
float step = 2.0f * PI * freqHz / sampleRate;
bool firstPacket = true;
while (totalSamples > 0) {
int count = min(samplesPerFrame, totalSamples);
for (int i = 0; i < count; i++) {
pcm = (int16_t)(8000.0f * sinf(phase)); // amplitude
phase += step;
if (phase > 2.0f * PI) phase -= 2.0f * PI;
}
// zero-fill if short frame
for (int i = count; i < samplesPerFrame; i++)
pcm = 0;
sendPcmToneAsRtp(
pcm,
samplesPerFrame,
toneCodec,
firstPacket);
firstPacket = false;
totalSamples -= count;
// maintain RTP timing
unsigned long t0 = millis();
while (millis() - t0 < frameMs) {
// handleSipMessages(sipUdp1, "Server1");
// handleRtpAudio();
}
}
ipTonePlaying = false;
resetAudioDecoder = true;
Serial.println("✅ Beep finished");
}

I am calling this function in my code, and it is working. However, after the message “✅ Beep finished,” no audio is coming from the phone microphone.
 
When you post code can you do it between code tags using the </> button.
It preserves formatting and makes the code much more readable. I have included your code below..
I think you will agree there is a world of difference between the two.

By the way it would be SO MUCH BETTER if you could include a small program that can be run which demonstrates your program.
That would make solving your problem so much easier.
Code:
void playBeepToIpPhone(uint16_t freqHz = 1000, uint16_t durationMs = 200) {
    if (!callActive || remoteRtpPort == 0) return;
    Serial.println("🔔 Playing confirmation beep to IP phone");
    ipTonePlaying = true;
    CodecType toneCodec = activeCodec;
    const int sampleRate =
        (toneCodec == CODEC_G722) ? 16000 : 8000;
    const int frameMs = 20;
    const int samplesPerFrame = sampleRate * frameMs / 1000;
    int totalSamples = sampleRate * durationMs / 1000;
    int16_t pcm[320]; // max needed for G.722
    float phase = 0.0f;
    float step = 2.0f * PI * freqHz / sampleRate;
    bool firstPacket = true;
    while (totalSamples > 0) {
        int count = min(samplesPerFrame, totalSamples);
        for (int i = 0; i < count; i++) {
            pcm = (int16_t)(8000.0f * sinf(phase)); // amplitude
            phase += step;
            if (phase > 2.0f * PI) phase -= 2.0f * PI;
        }
        // zero-fill if short frame
        for (int i = count; i < samplesPerFrame; i++)
            pcm = 0;
        sendPcmToneAsRtp(
            pcm,
            samplesPerFrame,
            toneCodec,
            firstPacket);
        firstPacket = false;
        totalSamples -= count;
        // maintain RTP timing
        unsigned long t0 = millis();
        while (millis() - t0 < frameMs) {
            // handleSipMessages(sipUdp1, "Server1");
            // handleRtpAudio();
        }
    }
    ipTonePlaying = false;
    resetAudioDecoder = true;
    Serial.println("✅ Beep finished");
}
 
Back
Top