/* return: number of bytes */ int32 general_output_convert(int32 *buf, int32 count) { int32 bytes; if(!(play_mode->encoding & PE_MONO)) count *= 2; /* Stereo samples */ bytes = count; if(play_mode->encoding & PE_16BIT) { bytes *= 2; if(play_mode->encoding & PE_BYTESWAP) { if(play_mode->encoding & PE_SIGNED) s32tos16x(buf, count); else s32tou16x(buf, count); } else if(play_mode->encoding & PE_SIGNED) s32tos16(buf, count); else s32tou16(buf, count); } else if(play_mode->encoding & PE_24BIT) { bytes *= 3; if(play_mode->encoding & PE_BYTESWAP) { if(play_mode->encoding & PE_SIGNED) s32tos24x(buf, count); else s32tou24x(buf, count); } else if(play_mode->encoding & PE_SIGNED) s32tos24(buf, count); else s32tou24(buf, count); } else if(play_mode->encoding & PE_ULAW) s32toulaw(buf, count); else if(play_mode->encoding & PE_ALAW) s32toalaw(buf, count); else if(play_mode->encoding & PE_SIGNED) s32tos8(buf, count); else s32tou8(buf, count); return bytes; }
static void output_data(int32 *buf, int32 count) { if (!(dpm.encoding & PE_MONO)) count*=2; /* Stereo samples */ if (dpm.encoding & PE_16BIT) { /* Convert data to signed 16-bit PCM */ s32tos16(buf, count); /* Write the data out. Linux likes to give an EINTR if you suspend a program while waiting on a write, so we may need to retry. */ while ((-1==write(dpm.fd, buf, count * 2)) && errno==EINTR) ; } else { /* Convert to 8-bit unsigned and write out. */ s32tou8(buf, count); while ((-1==write(dpm.fd, buf, count)) && errno==EINTR) ; } }
static void output_data(int32 *buf, int32 count) { int ocount; if (!(dpm.encoding & PE_MONO)) count*=2; /* Stereo samples */ ocount = count; if (ocount) { if (dpm.encoding & PE_16BIT) { /* Convert data to signed 16-bit PCM */ s32tos16(buf, count); ocount *= 2; } else { /* Convert to 8-bit unsigned and write out. */ s32tou8(buf, count); } } b_out(dpm.fd, (int *)buf, ocount); }