Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Telefonwählprogramm mit Soundkarte
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
tessar
n00b
n00b


Joined: 28 Aug 2004
Posts: 4

PostPosted: Sat Aug 28, 2004 10:47 pm    Post subject: Telefonwählprogramm mit Soundkarte Reply with quote

Hallo!

Ich habe viel im Internet gesucht, um ein Programm zu finden, dass vom KDE Adressbuch benutzt werden kann, um eine Telefonnummer zu wählen ... nix zu finden! Da hab ich mich mal rangesetzt und ein kleines C-Programm geschrieben, das eine Zahlenfolge als Töne über die Soundkarte ausgibt. In den Einstellungen vom Adressbuch einfach in der Script-Einbindung das Programm eintragen, z.B. dialer %N , und fertig. Dann nur noch Telefonhörer abnehmen, in die nähe der Lautsprecher halten und auf die Telefonnummer des Kontaktes klicken. Dann ertönt das uns so bekannte Wählgeräusch und schon klingelts bei dem Kontakt.
Oder einfach nur starten mit $ dialer 1234567890 oder so...
OK, das Programm kann man noch optimieren, aber es geht zumindest schon mal. Also wer lust hat ...

Programm : dialer.c (Achtung, mit gcc dialer.c -lm übersetzen)

--------------------------------------------------------------------------------------
#include <sys/soundcard.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
const int BuffSize = 4*1024;
const char AudioDeviceName[] = "/dev/dsp" ;
const int AudioFormat = AFMT_S16_NE;
const double lof[4] = {697.0 , 770.0 , 852.0 , 941.0};
const double hif[3] = {1209.0 , 1336.0 , 1477.0};
typedef signed short TpAudioFormat;

int main( int argc, char* argv[] )
{
int fdAudio;
TpAudioFormat Buffer[BuffSize];
int i,k;
int len;
int nFormat;
int nChannels;
int nSamplingRate;
audio_buf_info info;
char z;
double x,t;
double h,f1,f2;
div_t q;
if (argc!=2) exit (-1);
if( (fdAudio = open(AudioDeviceName, O_WRONLY, 0)) == -1 )
{
perror( AudioDeviceName );
exit(-1);
}
// Setze Audio-Format: 16Bit signed integer, host endian
nFormat = AudioFormat;
if( ioctl(fdAudio, SNDCTL_DSP_SETFMT, &nFormat) == -1 )
{
perror("SNDCTL_DSP_SETFMT");
exit(-2);
}
if( nFormat != AudioFormat)
{
perror("Versuchen Sie ein anderes AudioFormat");
exit(-3);
}
// Setze Mono: 1 channel
nChannels = 1;
if( ioctl(fdAudio, SNDCTL_DSP_CHANNELS, &nChannels) == -1 )
{
perror("SNDCTL_DSP_SETFMT");
exit(-4);
}
if( nChannels != 1)
{
perror("Das Device unterützt kein Mono-Mode.");
exit(-5);
}
// Setze Mono: 1 channel
nSamplingRate = 44100;
if( ioctl(fdAudio, SNDCTL_DSP_SPEED, &nSamplingRate) == -1 )
{
perror("Sampling Rate");
exit(-6);
}
if( ioctl(fdAudio, SNDCTL_DSP_GETBLKSIZE, &len) == -1 )
{
perror("SNDCTL_DSP_GETBLKSIZE");
exit(-6);
}
if( ioctl(fdAudio, SNDCTL_DSP_GETOSPACE, &info) == -1 )
{
perror("SNDCTL_DSP_GETBLKSIZE");
exit(-6);
}
//Einlesen der einzelnen Ziffern der übergebenen Nummer
for (k=0;k<strlen(argv[1]);k++)
{
z=argv[1][k];
t=0;
if (atoi(&z) == 0) t=10;
if (z == '*') t=9;
if (z == '#') t=11;
if (t == 0 && atoi(&z)<10) t=atoi(&z)-1;
else
{
if (t == 0) exit(-5);
}
//Auswahl der 2 Frequenzen für die jeweillige Ziffer
q=div(t,3);
f1=lof[q.quot];
f2=hif[q.rem];

h = 1.0 / nSamplingRate;
//erst Pause ausgeben
for( i=1; i<BuffSize; i++)
{
Buffer[i] = (TpAudioFormat) 0;
}
if( (len = write(fdAudio, Buffer, 2*BuffSize)) == -1)
{
perror("Audio-Ausgabe gescheitert.");
exit(-2);
}
//berechnung und überlagerung der 2 Frequenzen
for( i=1; i<BuffSize; i++)
{
x=sin(2*M_PI*i*f1*h)+sin(2*M_PI*i*f2*h);

Buffer[i] = (TpAudioFormat)( x * 6000.0 );
}
//Ausgabe des Resultates
if( (len = write(fdAudio, Buffer, 2*BuffSize)) == -1)
{
perror("Audio-Ausgabe gescheitert.");
exit(-2);
}
}
return 0;
}
--------------------------------------------------------------------------------------

Vielleicht noch was zur Theorie dahinter:
Bei jedem Telefon im Tonwahlverfahren wird jede Ziffer der Tastatur durch 2 überlagerte Frequenzen nach einer bestimmten Matrix kodiert. Es reicht also diese 2 speziellen Frequenzen für die jeweilige Taste zu überlagern und durch das Mikrofon im Telefonhörer zu geben und schon wird diese Ziffer gewählt.

was meint ihr dazu?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum