Hello everyone.
I had problems running multiple instances of the Tone Detection Unit to detect Call Progress Tones (here, a North America dial tone).
I created 16 instances of the TDU, and enabled the CPT detector on only 4 channels, namely the ports 5, 6, 7 and 8. When I injected a dial tone into port 5 from the TDM side, I received a tdu_send_out for this port (as expected) with the right information. The problem was that, most of the time, I also received the same event on port 6 and 7, which were completely silent. When I stop the dial tone, it kept sending events on port 7, on and off. The behavior was completely erratic.
To make sure I wasn't injecting wrong data into the functions tduSendIn and tduReceiveIn, I captured the data and confirmed that the dial tone was only present in tduSendIn of port 5... The others being completely silent, no cross-talk, nothing.
I found a way to go around the problem and it most probably shows a bug in the library.
First of all, I made a simple test: Each time that tduSendIn and tduReceiveIn is called, I cleared the volatile scratch buffer with zeroes. This buffer is the second one, requested by tduGetSizes, which has a size of 1024 bytes, an alignment of 1024, and the volatile bit set. My understanding is that this buffer was not meant to store context data between calls, but only temporary data during calls. But, by clearing it before each call, the TDU STOPS reporting any events!!!
So, facing this problem, I assumed that this buffer could not be volatile, and I allocated a distinct and unique scratch buffer to each TDU instance. But it didn't work.
Then, I looked into the tduContext structure instance, and saw that each time tduNew is called, three members of tduContext received an address which falls into the scratch buffer. The three members are: work_buf, local_buf and magnitudes. But since I now have a different scratch buffer for each TDU instance, I had to "swap" the three members of tduContext, so that they fall into the specific scratch buffer, before each call to tduSendIn and tduReceiveIn. Now it works!!!
So my guess is that the TDU stores data into the scratch buffer between calls, and it shouldn't.
Did anyone face a similar problem?
Regards,
Jean Denis Boyer