title: getting iaxclient to send audio to/get audio from buffer instead of audio-device
body: <p>I'm trying to write a C++ program (altough python would've been fine as well in case someone knows a better (IAX/SIP) alternative) which connects to an Asterisk server.</p>
  
  <p>After connecting, it should listen for audio and process that. It should also send audio back. I'm using <a href="https://sourceforge.net/projects/iaxclient/" rel="noreferrer">https://sourceforge.net/projects/iaxclient/</a> for that (note that there are several versions (betas, regular releases, svn version) which all behave differently).</p>
  
  <p>Now if I understood the code of the library correct, then it can call a callback function with an event. One of those events is IAXC_EVENT_AUDIO. In the structure of that IAXC_EVENT_AUDIO there's a direction; incoming outgoing. And that's where I'm lost: with some versions of iaxclient I only receive the IAXC_SOURCE_REMOTE messages, with some both. And if I switch to test-mode (which should only disable the audio-device) I often receive nothing at all. When I receive both IAXC_SOURCE_LOCAL and IAXC_SOURCE_REMOTE, I tried to set the buffers of those events to random data but that doesn't reach the other end at all (I set it to RAW mode).</p>
  
  <p>As anyone any suggestions how to resolve this?</p>
  
  <p>My test-code is:</p>
  
  <pre><code>#include &lt;iaxclient.h&gt;
  #include &lt;unistd.h&gt;
  
  int iaxc_event_callback(iaxc_event e)
  {
      if (e.type == IAXC_EVENT_TEXT) {
          printf("text\n");
      }
      else if (e.type == IAXC_EVENT_LEVELS) {
          printf("level\n");
      }
      else if (e.type == IAXC_EVENT_STATE) {
          struct iaxc_ev_call_state *st = iaxc_get_event_state(&amp;e);
          printf("\tcallno %d state %d format %d remote %s(%s)\n", st-&gt;callNo, st-&gt;state, st-&gt;format,st-&gt;remote, st-&gt;remote_name);
          iaxc_key_radio(st-&gt;callNo);
      }
      else if (e.type == IAXC_EVENT_NETSTAT) {
          printf("\tcallno %d rtt %d\n", e.ev.netstats.callNo, e.ev.netstats.rtt);
      }
      else if (e.type == IAXC_EVENT_AUDIO) {
          printf("\t AUDIO!!!! %d %u %d\n", e.ev.audio.source, e.ev.audio.ts, e.ev.audio.size);
  
          for(int i=0; i&lt;e.ev.audio.size; i++)
              printf("%02x ", e.ev.audio.data[i]);
          printf("\n");
      }
      else {
          printf("type: %d\n", e.type);
      }
  
      return 1;
  }
  
  int main(int argc, char *argv[])
  {
      iaxc_set_test_mode(1);
      printf("init %d\n", iaxc_initialize(1));
  
      iaxc_set_formats(IAXC_FORMAT_SPEEX, IAXC_FORMAT_SPEEX);
  
      iaxc_set_event_callback(iaxc_event_callback);
      printf("get audio pref %d\n", iaxc_get_audio_prefs());
      //printf("set audio pref %d\n", iaxc_set_audio_prefs(IAXC_AUDIO_PREF_RECV_REMOTE_ENCODED));
      printf("set audio pref %d\n", iaxc_set_audio_prefs(IAXC_AUDIO_PREF_RECV_REMOTE_RAW | IAXC_AUDIO_PREF_RECV_LOCAL_RAW));
      printf("get audio pref %d\n", iaxc_get_audio_prefs());
  
      printf("start thread %d\n", iaxc_start_processing_thread());
  
      int id = -1;
      printf("register %d\n", id = iaxc_register("6003", "1923", "192.168.64.1"));
  
      int callNo = -1;
      printf("call %d\n", callNo = iaxc_call("6003:1923@192.168.64.1/6001"));
  
      printf("unquelch: %d\n", iaxc_unquelch(callNo));
  
      pause();
  
      printf("finish\n");
      printf("%d\n", iaxc_unregister(id));
      printf("%d\n", iaxc_stop_processing_thread());
      iaxc_shutdown();
  
      return 0;
  }
  </code></pre>