#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 */
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)
{
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)
{
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++;
}
{
*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++;
}
}
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++;
}
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++;
}
int p_record_skip; /* skip bytes before writing the sample */
unsigned long p_record_length; /* size of what's written so far */
- unsigned char p_record_buffer[RECORD_BUFFER_LENGTH];
+ unsigned short p_record_buffer[RECORD_BUFFER_LENGTH];
unsigned long p_record_buffer_readp;
unsigned long p_record_buffer_writep;
int p_record_buffer_dir; /* current direction in buffer */