Merge branch 'master' of ssh://jolly@www.mISDN.org/var/git/lcr
[lcr.git] / port.cpp
index 02d8dc3..a44cebe 100644 (file)
--- a/port.cpp
+++ b/port.cpp
@@ -45,14 +45,6 @@ Functions:
    
 */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
 #include "main.h"
 
 #define SHORT_MIN -32768
@@ -215,10 +207,10 @@ Port::Port(int type, char *portname, struct port_settings *settings)
 Port::~Port(void)
 {
        class Port *temp, **tempp;
-       struct message *message;
+       struct lcr_msg *message;
 
        if (p_record)
-               close_record(0);
+               close_record(0, 0);
 
        classuse--;
 
@@ -448,7 +440,7 @@ void Port::set_vbox_tone(char *dir, char *name)
 void Port::set_vbox_play(char *name, int offset)
 {
        signed long size;
-       struct message *message;
+       struct lcr_msg *message;
 
        /* use ser_box_tone() */
        set_vbox_tone("", name);
@@ -562,7 +554,7 @@ read_more:
                if (((p_tone_size-p_tone_left)/8000) != (p_tone_size-tone_left_before)/8000)
                {
 //printf("\nsize=%d left=%d\n\n",p_tone_size,p_tone_left);
-                       struct message *message;
+                       struct lcr_msg *message;
                        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_COUNTER);
                        message->param.counter.current = (p_tone_size-p_tone_left)/8000;
                        message->param.counter.max = -1;
@@ -597,7 +589,7 @@ read_more:
 try_loop:
        if (p_tone_eof && ACTIVE_EPOINT(p_epointlist))
        {
-               struct message *message;
+               struct lcr_msg *message;
                message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_EOF);
                message_put(message);
        }
@@ -651,7 +643,7 @@ int Port::handler(void)
  * this is called by the message_epoint inherited by child classes
  * therefor a return=1 means: stop, no more processing
  */
-//extern struct message *dddebug;
+//extern struct lcr_msg *dddebug;
 int Port::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
 {
        /* check if we got audio data from one remote port */
@@ -788,10 +780,9 @@ int Port::open_record(int type, int vbox, int skip, char *extension, int anon_ig
 /*
  * close the recoding file, put header in front and rename
  */
-void Port::close_record(int beep)
+void Port::close_record(int beep, int mute)
 {
-       static signed long beep_mono[] = {-10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000, -10000, 10000};
-       static unsigned char beep_8bit[] = {48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208, 48, 208};
+       static signed short beep_mono[256];
        unsigned long size, wsize;
        struct fmt fmt;
        char filename[512], indexname[512];
@@ -849,41 +840,31 @@ void Port::close_record(int beep)
                i++;
        }
 
+       /* mute */
+       if (mute && p_record_type==CODEC_MONO)
+       {
+               i = p_record_length;
+               if (i > mute)
+                       i = mute;       
+               fseek(p_record, -(i<<1), SEEK_END);
+               p_record_length -= (i<<1);
+       }
        /* add beep to the end of recording */
-       if (beep)
-       switch(p_record_type)
+       if (beep && p_record_type==CODEC_MONO)
        {
-               case CODEC_MONO:
                i = 0;
-               while(i < beep)
+               while(i < 256)
                {
-                       fwrite(beep_mono, sizeof(beep_mono), 1, p_record);
-                       i += sizeof(beep_mono);
-                       p_record_length += sizeof(beep_mono);
-               }
-               break;
-               case CODEC_8BIT:
-               i = 0;
-               while(i < beep)
-               {
-                       fwrite(beep_8bit, sizeof(beep_8bit), 1, p_record);
-                       i += sizeof(beep_8bit);
-                       p_record_length += sizeof(beep_8bit);
+                       beep_mono[i] = (signed short)(sin((double)i / 5.688888888889 * 2.0 * 3.1415927) * 2000.0);
+                       i++;
                }
-               break;
-#if 0
-               case CODEC_LAW:
                i = 0;
                while(i < beep)
                {
-                       fwrite(beep_law, sizeof(beep_law), 1, p_record);
-                       i += sizeof(beep_law);
-                       p_record_length += sizeof(beep_law);
+                       fwrite(beep_mono, sizeof(beep_mono), 1, p_record);
+                       i += sizeof(beep_mono);
+                       p_record_length += sizeof(beep_mono);
                }
-               break;
-#endif
-               default:
-               PERROR("codec %d not supported for beep adding\n", p_record_type);
        }
 
        /* complete header */