📄 os2.c
字号:
{
MCI_MIX_BUFFER *temp = playingbuffer;
while(
(tobefilled != (temp = ((BUFFERINFO *) temp->ulUserParm)->NextBuffer)) &&
(tobefilled != (temp = ((BUFFERINFO *) temp->ulUserParm)->NextBuffer)) &&
(tobefilled != (temp = ((BUFFERINFO *) temp->ulUserParm)->NextBuffer)) )
{
DosResetEventSem(dataplayed,&resetcount);
DosWaitEventSem(dataplayed, -1);
temp = playingbuffer;
}
} else {
while(tobefilled == playingbuffer)
{
DosResetEventSem(dataplayed,&resetcount);
DosWaitEventSem(dataplayed, -1);
}
}
if (justflushed) {
justflushed = FALSE;
} else {
nomoredata = FALSE;
memcpy(tobefilled->pBuffer, buf, len);
tobefilled->ulBufferLength = len;
// ((BUFFERINFO *) tobefilled->ulUserParm)->frameNum = fr->frameNum;
/* if we're out of the water (3rd ahead buffer filled),
let's reduce our priority */
if(tobefilled == ( (BUFFERINFO *) ( (BUFFERINFO *) ((BUFFERINFO *) playingbuffer->ulUserParm)->NextBuffer->ulUserParm)->NextBuffer->ulUserParm)->NextBuffer)
DosSetPriority(PRTYS_THREAD,normalclass,normaldelta,mainthread->tib_ptib2->tib2_ultid);
tobefilled = ((BUFFERINFO *) tobefilled->ulUserParm)->NextBuffer;
}
return len;
}
static int write_os2(audio_output_t *ao,unsigned char *buf,int len)
{
if(len > audiobufsize || !playingbuffer) return -1;
if(mmp.ulBitsPerSample == 16)
ao->format = MPG123_ENC_SIGNED_16;
else if(mmp.ulBitsPerSample == 8)
ao->format = MPG123_ENC_UNSIGNED_8;
else return -1;
ao->rate = mmp.ulSamplesPerSec;
ao->channels = mmp.ulChannels;
if(buf && len)
{
ULONG rc;
int upto;
mstatp.ulItem = MCI_STATUS_POSITION;
rc = mciSendCommand( maop.usDeviceID,
MCI_STATUS,
MCI_STATUS_ITEM | MCI_WAIT,
&mstatp,
0 );
if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
{
MciError(rc);
maop.usDeviceID = 0;
return(-1);
}
/* this is hypocrite...
DART returns the value in ulReturn instead of ulValue,
also it returns in milliseconds and not MMTIME... arg */
upto = (mstatp.ulReturn-playedbuffer.ulTime) * mmp.ulSamplesPerSec / 1000;
upto *= mmp.ulChannels * (mmp.ulBitsPerSample>>3);
/* if a timing problem occurs, let's at least not crash */
if(upto > playingbuffer->ulBufferLength)
upto = playingbuffer->ulBufferLength;
if(len < upto) {
memcpy(buf,(char *) (playingbuffer->pBuffer)+upto-len, len);
} else {
memcpy(buf,(char *) playedbuffer.pBuffer+playedbuffer.ulBufferLength-(len-upto),len-upto);
memcpy(buf+(len-upto),playingbuffer->pBuffer,upto);
}
}
return 0;
}
/*
static int audio_nobuffermode(audio_output_t *ao, int setnobuffermode)
{
nobuffermode = setnobuffermode;
return TRUE;
}
int audio_trash_buffers(audio_output_t *ao)
{
int i;
justflushed = TRUE;
// Fill all device buffers with zeros
for(i = 0; i < ulMCIBuffers; i++)
memset(MixBuffers[i].pBuffer, 0, MixBuffers[i].ulBufferLength);
tobefilled = ((BUFFERINFO *) playingbuffer->ulUserParm)->NextBuffer;
nomoredata = TRUE;
return TRUE;
}
*/
int close_os2(audio_output_t *ao)
{
ULONG rc;
if(!maop.usDeviceID)
return 0;
while(!nomoredata)
{
DosResetEventSem(dataplayed,&resetcount);
DosWaitEventSem(dataplayed, -1);
}
playingbuffer = NULL;
DosCloseEventSem(dataplayed);
dataplayed = 0;
free(pBufferplayed);
rc = mciSendCommand( maop.usDeviceID,
MCI_BUFFER,
MCI_WAIT | MCI_DEALLOCATE_MEMORY,
&mbp,
0 );
if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
free(bufferinfo);
free(MixBuffers);
bufferinfo = NULL;
MixBuffers = NULL;
memset(&mbp, 0, sizeof(mbp));
rc = mciSendCommand( maop.usDeviceID,
MCI_CLOSE,
MCI_WAIT ,
&mgp,
0 );
if ( ULONG_LOWD(rc) != MCIERR_SUCCESS )
{
MciError(rc);
return(-1);
}
memset(&maop, 0, sizeof(maop));
return 0;
}
/*
* get formats for specific channel/rate parameters
*/
int get_formats_os2(audio_output_t *ao)
{
int fmts = 0;
ULONG rc;
MCI_MIXSETUP_PARMS mmptemp = {0};
mmp.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
mmp.pmixEvent = DARTEvent;
mmptemp.ulFormatMode = MCI_PLAY;
mmptemp.ulSamplesPerSec = ao->rate;
mmptemp.ulChannels = ao->channels;
mmptemp.ulFormatTag = MCI_WAVE_FORMAT_PCM;
mmptemp.ulBitsPerSample = 16;
rc = mciSendCommand( maop.usDeviceID,
MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&mmptemp,
0 );
if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
fmts = fmts | MPG123_ENC_SIGNED_16;
mmptemp.ulFormatTag = MCI_WAVE_FORMAT_PCM;
mmptemp.ulBitsPerSample = 8;
rc = mciSendCommand( maop.usDeviceID,
MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&mmptemp,
0 );
if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
fmts = fmts | MPG123_ENC_UNSIGNED_8;
mmptemp.ulFormatTag = MCI_WAVE_FORMAT_ALAW;
mmptemp.ulBitsPerSample = 8;
rc = mciSendCommand( maop.usDeviceID,
MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&mmptemp,
0 );
if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
fmts = fmts | MPG123_ENC_ALAW_8;
mmptemp.ulFormatTag = MCI_WAVE_FORMAT_MULAW;
mmptemp.ulBitsPerSample = 8;
rc = mciSendCommand( maop.usDeviceID,
MCI_MIXSETUP,
MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
&mmptemp,
0 );
if((ULONG_LOWD(rc) == MCIERR_SUCCESS) && (rc != 0x4000)) /* undocumented */
fmts = fmts | MPG123_ENC_ULAW_8;
return fmts;
}
int get_devices_os2(char *info, int deviceid)
{
char buffer[128];
MCI_SYSINFO_PARMS mip;
if(deviceid && info)
{
MCI_SYSINFO_LOGDEVICE mid;
mip.pszReturn = buffer;
mip.ulRetSize = sizeof(buffer);
mip.usDeviceType = MCI_DEVTYPE_AUDIO_AMPMIX;
mip.ulNumber = deviceid;
mciSendCommand(0,
MCI_SYSINFO,
MCI_WAIT | MCI_SYSINFO_INSTALLNAME,
&mip,
0);
mip.ulItem = MCI_SYSINFO_QUERY_DRIVER;
mip.pSysInfoParm = ∣
strcpy(mid.szInstallName,buffer);
mciSendCommand(0,
MCI_SYSINFO,
MCI_WAIT | MCI_SYSINFO_ITEM,
&mip,
0);
strcpy(info,mid.szProductInfo);
return deviceid;
} else {
int number;
mip.pszReturn = buffer;
mip.ulRetSize = sizeof(buffer);
mip.usDeviceType = MCI_DEVTYPE_AUDIO_AMPMIX;
mciSendCommand(0,
MCI_SYSINFO,
MCI_WAIT | MCI_SYSINFO_QUANTITY,
&mip,
0);
number = atoi(mip.pszReturn);
return number;
}
}
void flush_os2(audio_output_t *ao)
{
}
static int init_os2(audio_output_t* ao)
{
if (ao==NULL) return -1;
/* Set callbacks */
ao->open = open_os2;
ao->flush = flush_os2;
ao->write = write_os2;
ao->get_formats = get_formats_os2;
ao->close = close_os2;
/* Success */
return 0;
}
/*
Module information data structure
*/
mpg123_module_t mpg123_output_module_info = {
/* api_version */ MPG123_MODULE_API_VERSION,
/* name */ "os2",
/* description */ "Audio output for OS2.",
/* revision */ "$Rev:$",
/* handle */ NULL,
/* init_output */ init_os2,
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -