mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-01 00:15:14 +01:00
rewrite ogg code. better?
This commit is contained in:
parent
383acdaf01
commit
2bf1663248
@ -67,9 +67,9 @@ static int ogg_thread_running = 0;
|
||||
|
||||
static void ogg_add_callback(int voice)
|
||||
{
|
||||
if (ogg_thread_running <= 0)
|
||||
if (!ogg_thread_running)
|
||||
{
|
||||
SND_StopVoice(0);
|
||||
ASND_StopVoice(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ static void ogg_add_callback(int voice)
|
||||
|
||||
if (private_ogg.pcm_indx >= READ_SAMPLES)
|
||||
{
|
||||
if (SND_AddVoice(0,
|
||||
if (ASND_AddVoice(0,
|
||||
(void *) private_ogg.pcmout[private_ogg.pcmout_pos],
|
||||
private_ogg.pcm_indx << 1) == 0)
|
||||
{
|
||||
@ -101,14 +101,14 @@ static void ogg_add_callback(int voice)
|
||||
static void * ogg_player_thread(private_data_ogg * priv)
|
||||
{
|
||||
int first_time = 1;
|
||||
long ret;
|
||||
|
||||
ogg_thread_running = 0;
|
||||
//init
|
||||
LWP_InitQueue(&oggplayer_queue);
|
||||
|
||||
priv[0].vi = ov_info(&priv[0].vf, -1);
|
||||
|
||||
SND_Pause(0);
|
||||
ASND_Pause(0);
|
||||
|
||||
priv[0].pcm_indx = 0;
|
||||
priv[0].pcmout_pos = 0;
|
||||
@ -120,20 +120,16 @@ static void * ogg_player_thread(private_data_ogg * priv)
|
||||
|
||||
while (!priv[0].eof)
|
||||
{
|
||||
long ret;
|
||||
if (ogg_thread_running <= 0)
|
||||
if (!ogg_thread_running)
|
||||
break;
|
||||
|
||||
if (priv[0].flag)
|
||||
LWP_ThreadSleep(oggplayer_queue); // wait only when i have samples to send
|
||||
|
||||
if (ogg_thread_running <= 0)
|
||||
break;
|
||||
|
||||
if (priv[0].flag == 0) // wait to all samples are sended
|
||||
{
|
||||
if (SND_TestPointer(0, priv[0].pcmout[priv[0].pcmout_pos])
|
||||
&& SND_StatusVoice(0) != SND_UNUSED)
|
||||
if (ASND_TestPointer(0, priv[0].pcmout[priv[0].pcmout_pos])
|
||||
&& ASND_StatusVoice(0) != SND_UNUSED)
|
||||
{
|
||||
priv[0].flag |= 64;
|
||||
continue;
|
||||
@ -188,12 +184,12 @@ static void * ogg_player_thread(private_data_ogg * priv)
|
||||
|
||||
if (priv[0].flag == 1)
|
||||
{
|
||||
if (SND_StatusVoice(0) == SND_UNUSED || first_time)
|
||||
if (ASND_StatusVoice(0) == SND_UNUSED || first_time)
|
||||
{
|
||||
first_time = 0;
|
||||
if (priv[0].vi->channels == 2)
|
||||
{
|
||||
SND_SetVoice(0, VOICE_STEREO_16BIT, priv[0].vi->rate, 0,
|
||||
ASND_SetVoice(0, VOICE_STEREO_16BIT, priv[0].vi->rate, 0,
|
||||
(void *) priv[0].pcmout[priv[0].pcmout_pos],
|
||||
priv[0].pcm_indx << 1, priv[0].volume,
|
||||
priv[0].volume, ogg_add_callback);
|
||||
@ -203,7 +199,7 @@ static void * ogg_player_thread(private_data_ogg * priv)
|
||||
}
|
||||
else
|
||||
{
|
||||
SND_SetVoice(0, VOICE_MONO_16BIT, priv[0].vi->rate, 0,
|
||||
ASND_SetVoice(0, VOICE_MONO_16BIT, priv[0].vi->rate, 0,
|
||||
(void *) priv[0].pcmout[priv[0].pcmout_pos],
|
||||
priv[0].pcm_indx << 1, priv[0].volume,
|
||||
priv[0].volume, ogg_add_callback);
|
||||
@ -223,33 +219,25 @@ static void * ogg_player_thread(private_data_ogg * priv)
|
||||
ov_clear(&priv[0].vf);
|
||||
priv[0].fd = -1;
|
||||
priv[0].pcm_indx = 0;
|
||||
ogg_thread_running = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StopOgg()
|
||||
{
|
||||
SND_StopVoice(0);
|
||||
if (ogg_thread_running > 0)
|
||||
{
|
||||
ogg_thread_running = -2;
|
||||
ogg_thread_running = 0;
|
||||
LWP_ThreadSignal(oggplayer_queue);
|
||||
LWP_JoinThread(h_oggplayer, NULL);
|
||||
|
||||
while (((volatile int) ogg_thread_running) != 0)
|
||||
{
|
||||
;;;
|
||||
}
|
||||
}
|
||||
ASND_StopVoice(0);
|
||||
}
|
||||
|
||||
int PlayOgg(int fd, int time_pos, int mode)
|
||||
{
|
||||
StopOgg();
|
||||
|
||||
ogg_thread_running = 0;
|
||||
|
||||
private_ogg.fd = fd;
|
||||
private_ogg.mode = mode;
|
||||
private_ogg.eof = 0;
|
||||
@ -269,23 +257,18 @@ int PlayOgg(int fd, int time_pos, int mode)
|
||||
{
|
||||
mem_close(private_ogg.fd); // mem_close() can too close files from devices
|
||||
private_ogg.fd = -1;
|
||||
ogg_thread_running = -1;
|
||||
ogg_thread_running = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (LWP_CreateThread(&h_oggplayer, (void *) ogg_player_thread,
|
||||
&private_ogg, oggplayer_stack, STACKSIZE, 80) == -1)
|
||||
{
|
||||
ogg_thread_running = -1;
|
||||
ogg_thread_running = 0;
|
||||
ov_clear(&private_ogg.vf);
|
||||
private_ogg.fd = -1;
|
||||
return -1;
|
||||
}
|
||||
LWP_ThreadSignal(oggplayer_queue);
|
||||
while (((volatile int) ogg_thread_running) == 0)
|
||||
{
|
||||
;;;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -304,7 +287,6 @@ void PauseOgg(int pause)
|
||||
if (ogg_thread_running > 0)
|
||||
{
|
||||
LWP_ThreadSignal(oggplayer_queue);
|
||||
// while(((volatile int )private_ogg.flag)!=1 && ((volatile int )ogg_thread_running)>0) {;;;}
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,30 +295,26 @@ void PauseOgg(int pause)
|
||||
|
||||
int StatusOgg()
|
||||
{
|
||||
if (ogg_thread_running <= 0)
|
||||
if (ogg_thread_running == 0)
|
||||
return -1; // Error
|
||||
|
||||
if (private_ogg.eof)
|
||||
else if (private_ogg.eof)
|
||||
return 255; // EOF
|
||||
|
||||
if (private_ogg.flag & 128)
|
||||
else if (private_ogg.flag & 128)
|
||||
return 2; // paused
|
||||
return 1; // running
|
||||
else
|
||||
return 1; // running
|
||||
}
|
||||
|
||||
void SetVolumeOgg(int volume)
|
||||
{
|
||||
private_ogg.volume = volume;
|
||||
|
||||
SND_ChangeVolumeVoice(0, volume, volume);
|
||||
ASND_ChangeVolumeVoice(0, volume, volume);
|
||||
}
|
||||
|
||||
s32 GetTimeOgg()
|
||||
{
|
||||
int ret;
|
||||
if (ogg_thread_running <= 0)
|
||||
return 0;
|
||||
if (private_ogg.fd < 0)
|
||||
if (ogg_thread_running == 0 || private_ogg.fd < 0)
|
||||
return 0;
|
||||
ret = ((s32) ov_time_tell(&private_ogg.vf));
|
||||
if (ret < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user