locked
How to redirect audio stream to/from the serial port? RRS feed

  • Question

  • I’m writing a program that will allow me to send SMS and call using a GSM modem.

    I‘m communicate with the modem using AT commands.

    I have a problem with “connect” sound from the modem to the speakers.

    After installing the modem is visible in the system as two ports.

    On one of them sends and receives commands.

    The second is just for voice communication.

    I can’t redirect PC audio input/output to the modem serial port. (So I can't hear callers and vice versa)

    From what I've managed to find I have to use SAPI. (ISpVoice::SetOutput)

    I have no experience in this type of applications and I don’t know where to start.

    I write a program in Visual Basic 2008

    Sorry for my poor English

    Wednesday, January 19, 2011 9:08 PM

Answers

  • I have had my doubts about this, however...it appears that reality is somewhere between my assertion that modems never do this, and your findings.

    So, I looked into AT commands for GSM modems...that is where I got those commands. I do not have a GSM modem that is not attached to a service provider, so....I am not sure that I can create a test platform.

    AAR, that is, in fact audio, but.....I am not confident that using the My.Computer.Audio device will be sufficient for this. (I have been wrong many, many times, however!) I think that you will have to buffer the audio and present it to the audio subsystem in a more "front door" manner. I would be delighted if I was wrong about that -- if we can get it working close to that snippet you showed me -- that would be super for all of us, I think.

    For your snippet to work at all, the audio coming in would have to have a header that Windows understands, plus the data. Windows can use many formats of audio, but by far the most prevalent is ADPCM. In my research, I read that GSM modems that use ADPCM are not all compatible with Windows' notion of ADPCM. I do not think that the modem is producing headers, though...it would be difficult to manage, and this is already pushing the limit of what a COM port can do at typical line speeds. (115200bps = about 11 kilobytes per second. Audio must be sampled at twice the maximum frequency, which means that 8 kilobytes per second is about the minimun acceptable rate...and that is the maximum that "normal" RS-232 can do without special line driver hardware. This is also a real-time processing activity throughout the system -- there is a lot of math going on behind the scenes, here.)

    What I would recommend is that you configure the COM port properly (You have not configured it at all in the snippet, which is making it so that it can *never* work with that code, so you have not really discovered anything...but, I'm sure you know that already ;) and it would help if you had the ability to send a short audio message from the originating phone...then, we can get it figured out...save the file and then we can proceed to the part you are wanting to get at -- the PC will have the audio available.

    I am not sure about the frame period....20 is a little nebulous (unclear, cloudy). I assume that means 20 microseconds, which would be roughly 50,000 bps, very close to 57,600...which is a standard line speed for RS-232. The hardware handshaking part has not been implemented very well when COM ports use USB...because real COM ports have more than one I/O to the computer. (USB has only one - all the rest are simulated on each end -- there is no more true hardware handshaking.)

    So, as a start, I would configure the COM port connected to the 'other' port to use no handshaking and 57,600bps speed. Some of the other setting will not matter, and others will have to be determined experimentally.

    Friday, January 21, 2011 9:33 PM

All replies

  • I doubt that you want to use SAPI...that is for Text to Speech and has little to do with processing audio.

    You cannot do what you are proposing without at least some cooperation from the modem itself. Years ago, I had a SoundBlaster audio card and a modem from Creative Labs. They provided cabling to make this connection possible, and also they had a driver and application for it, as well. However, you cannot push even digitized audio through a COM port without a lot of software support, which you do not have.

    AAR, the audio from a voice call would not enter through a COM port -- it would be available at the mic/speaker of the modem, or as a Bluetooth headset device.

    You will need to provide more information about your hardware....specifically the modem.

    Wednesday, January 19, 2011 10:08 PM
  • It's a Huawei K3765 (USB Modem). Modem is sold with Mobile Partner application, which has voice calls. There, everything works great.

    Certainly one of the ports is activated and begins to transmit data only during a voice call.  I wrote to Huawei asking for support, but I didn't get a response.

    Unfortunately I have no idea what to do next.

    Wednesday, January 19, 2011 10:23 PM
  • So, in the Mobile Partner application, the PC's microphone and speakers, or headset is used? If that is the case, you might have a path to the modem after all.

    Unfortunately, GSM modems are tied into the carrier more tightly than previous modems were. It might be possible to switch the modem into voice mode using AT commands, and the audio would be handled by the driver. Have you tried dialing a number and then sending the command to switch over after the other end has picked up? (You can use the carrier detect signal to determine when that has occurred.)

    I am not certain if I can cobble up a decent test rig for this, but...I'll try later tonight.

    Wednesday, January 19, 2011 11:00 PM
  • First, I send the command

    ATD "number";

    then, after receiving a call

    AT^DDSETEX=2

    At this point, the second port begin to appear some "noise".
    After suspending the call there is a silence on port.
    I overheard the broadcast Mobile Partner to the modem, and does almost the same as me.
    Wednesday, January 19, 2011 11:13 PM
  • Okay, I think we can get somewhere with this.....what is the modem's response to this:

    AT+VSM=?

    ...or this:

     AT#VSM=?

     

    Thursday, January 20, 2011 3:53 AM
  • Any combination of command returns:

    COMMAND NOT SUPPORT

     

    I found the command
    AT^CVOICE

    READ command is used to read the current voice mode (0-PC Voice Mode 1 - Earphone Mode), and return
    sampling rate, data bits, frame period.

    Modem response:

    ^ CVOICE: 0,8000,16,20

    Thursday, January 20, 2011 7:32 AM
  • Okay, then....it seems that the 'noise' is data -- 16-bit 8kHz audio.

    I think that you ought to connect to that second port with a serial port from your PC. From that, you can get the audio and then you can provide that to Windows. I think that you will need to use DirectSound from DirectX. I have worked with the Windows MultiMedia interface in VisualBasic, but I have not figured out all of the P/Invoke signatures, and besides...DirectSound is a more capable API.

     

    Thursday, January 20, 2011 3:59 PM
  • Don't know if I understood correctly what I found on the Internet.
    From what I've found I should use the function:

     

    My.Computer.Audio.Play (stream, AudioPlayMode.Background)
    

     

    But I can't use it (I'm just starting to program in. net and VB).
    I did something like this:

    SAudio Dim As New Microsoft.VisualBasic.Devices.Audio ()   
    Dim stream As System.IO.Stream
    Me.SerialPort1.Open ()
    stream = Me.SerialPort1.BaseStream
    sAudio.Play (stream, AudioPlayMode.Background)


       But of course it doesn't work:)
    Maybe you know whether the idea is correct or how it should look like

    Thanks for your help

    Thursday, January 20, 2011 6:33 PM
  • I have had my doubts about this, however...it appears that reality is somewhere between my assertion that modems never do this, and your findings.

    So, I looked into AT commands for GSM modems...that is where I got those commands. I do not have a GSM modem that is not attached to a service provider, so....I am not sure that I can create a test platform.

    AAR, that is, in fact audio, but.....I am not confident that using the My.Computer.Audio device will be sufficient for this. (I have been wrong many, many times, however!) I think that you will have to buffer the audio and present it to the audio subsystem in a more "front door" manner. I would be delighted if I was wrong about that -- if we can get it working close to that snippet you showed me -- that would be super for all of us, I think.

    For your snippet to work at all, the audio coming in would have to have a header that Windows understands, plus the data. Windows can use many formats of audio, but by far the most prevalent is ADPCM. In my research, I read that GSM modems that use ADPCM are not all compatible with Windows' notion of ADPCM. I do not think that the modem is producing headers, though...it would be difficult to manage, and this is already pushing the limit of what a COM port can do at typical line speeds. (115200bps = about 11 kilobytes per second. Audio must be sampled at twice the maximum frequency, which means that 8 kilobytes per second is about the minimun acceptable rate...and that is the maximum that "normal" RS-232 can do without special line driver hardware. This is also a real-time processing activity throughout the system -- there is a lot of math going on behind the scenes, here.)

    What I would recommend is that you configure the COM port properly (You have not configured it at all in the snippet, which is making it so that it can *never* work with that code, so you have not really discovered anything...but, I'm sure you know that already ;) and it would help if you had the ability to send a short audio message from the originating phone...then, we can get it figured out...save the file and then we can proceed to the part you are wanting to get at -- the PC will have the audio available.

    I am not sure about the frame period....20 is a little nebulous (unclear, cloudy). I assume that means 20 microseconds, which would be roughly 50,000 bps, very close to 57,600...which is a standard line speed for RS-232. The hardware handshaking part has not been implemented very well when COM ports use USB...because real COM ports have more than one I/O to the computer. (USB has only one - all the rest are simulated on each end -- there is no more true hardware handshaking.)

    So, as a start, I would configure the COM port connected to the 'other' port to use no handshaking and 57,600bps speed. Some of the other setting will not matter, and others will have to be determined experimentally.

    Friday, January 21, 2011 9:33 PM
  • Hi Degan85,

    I'm also stuck in the middle of this same problem, except that I am using C#.net......

    I am also using the same k3765 modem and have also seen that the mobile partner is able to communicate with the dongle with no issue.....

    Did u have any success with ur problem??

    If u succeeded pls let me knw how u were able to tell the usb dongle to use the PC spkr+mic..

     

    Thnx

    Monday, September 12, 2011 12:40 PM
  • Hi Anyone succeeded in this area? 

    Redirect audio stream to/from the serial port?

    thanks

    vav

    Friday, December 14, 2012 7:39 PM