summaryrefslogtreecommitdiffstats
path: root/port.cpp
diff options
context:
space:
mode:
authorSuper User2007-09-25 12:50:21 +0200
committerSuper User2007-09-25 12:50:21 +0200
commit5b8989b12eda80feb7c419fe966430d1aad37319 (patch)
tree83a314e5e06226005c222c494848330613657682 /port.cpp
parentadded port# to log-file (diff)
downloadlcr-5b8989b12eda80feb7c419fe966430d1aad37319.tar.gz
lcr-5b8989b12eda80feb7c419fe966430d1aad37319.tar.xz
lcr-5b8989b12eda80feb7c419fe966430d1aad37319.zip
audio recording fix by Xuan
Diffstat (limited to 'port.cpp')
-rw-r--r--port.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/port.cpp b/port.cpp
index 0fdfd39..a10a6f0 100644
--- a/port.cpp
+++ b/port.cpp
@@ -57,6 +57,9 @@ Functions:
#include <errno.h>
#include "main.h"
+#define SHORT_MIN -32768
+#define SHORT_MAX 32767
+
class Port *port_first = NULL;
unsigned long port_serial = 1; /* must be 1, because 0== no port */
@@ -1043,6 +1046,8 @@ void Port::record(unsigned char *data, int length, int dir_fromup)
free = ((p_record_buffer_readp - p_record_buffer_writep - 1) & RECORD_BUFFER_MASK);
+//PDEBUG(DEBUG_PORT, "record(data,%d,%d): free=%d, p_record_buffer_dir=%d, p_record_buffer_readp=%d, p_record_buffer_writep=%d.\n", length, dir_fromup, free, p_record_buffer_dir, p_record_buffer_readp, p_record_buffer_writep);
+
/* the buffer stores the same data stream */
if (dir_fromup == p_record_buffer_dir)
{
@@ -1140,6 +1145,8 @@ void Port::record(unsigned char *data, int length, int dir_fromup)
ii = (p_record_buffer_writep - p_record_buffer_readp) & RECORD_BUFFER_MASK;
if (length < ii)
ii = length;
+//PDEBUG(DEBUG_PORT, "record(data,%d,%d): free=%d, p_record_buffer_dir=%d, p_record_buffer_readp=%d, p_record_buffer_writep=%d: mixing %d bytes.\n", length, dir_fromup, free, p_record_buffer_dir, p_record_buffer_readp, p_record_buffer_writep, ii);
+
/* write data mixed with the buffer */
switch(p_record_type)
{
@@ -1151,10 +1158,8 @@ void Port::record(unsigned char *data, int length, int dir_fromup)
sample = p_record_buffer[p_record_buffer_readp]
+ audio_law_to_s32[*data++];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
- if (sample < 32767)
- sample = -32767;
- if (sample > 32768)
- sample = 32768;
+ if (sample < SHORT_MIN) sample = SHORT_MIN;
+ if (sample > SHORT_MAX) sample = SHORT_MAX;
*s++ = sample;
i++;
}
@@ -1180,6 +1185,7 @@ void Port::record(unsigned char *data, int length, int dir_fromup)
{
*s++ = p_record_buffer[p_record_buffer_readp];
*s++ = audio_law_to_s32[*data++];
+ p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
i++;
}
}
@@ -1194,10 +1200,8 @@ void Port::record(unsigned char *data, int length, int dir_fromup)
sample = p_record_buffer[p_record_buffer_readp]
+ audio_law_to_s32[*data++];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
- if (sample < 32767)
- sample = -32767;
- if (sample > 32768)
- sample = 32768;
+ if (sample < SHORT_MIN) sample = SHORT_MIN;
+ if (sample > SHORT_MAX) sample = SHORT_MAX;
*d++ = (sample+0x8000) >> 8;
i++;
}
@@ -1212,10 +1216,8 @@ void Port::record(unsigned char *data, int length, int dir_fromup)
sample = p_record_buffer[p_record_buffer_readp]
+ audio_law_to_s32[*data++];
p_record_buffer_readp = (p_record_buffer_readp + 1) & RECORD_BUFFER_MASK;
- if (sample < 32767)
- sample = -32767;
- if (sample > 32768)
- sample = 32768;
+ if (sample < SHORT_MIN) sample = SHORT_MIN;
+ if (sample > SHORT_MAX) sample = SHORT_MAX;
*d++ = audio_s16_to_law[sample & 0xffff];
i++;
}