]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Replace global audio stream state variables with local session variables.
authorToni Wilen <twilen@winuae.net>
Wed, 29 Aug 2018 17:51:59 +0000 (20:51 +0300)
committerToni Wilen <twilen@winuae.net>
Wed, 29 Aug 2018 17:51:59 +0000 (20:51 +0300)
audio.cpp
blkdev_cdimage.cpp
cd32_fmv.cpp
include/audio.h
od-win32/blkdev_win32_ioctl.cpp
od-win32/cda_play.cpp
od-win32/cda_play.h
sndboard.cpp
x86.cpp

index 8f737cdcc76f13aabe808aade065d068d5b89c54..e8ee721f637a9cbc46ade5308ca9810dcd500791 100644 (file)
--- a/audio.cpp
+++ b/audio.cpp
@@ -100,6 +100,7 @@ struct audio_stream_data
        unsigned int evtime;
        struct audio_channel_data2 data[AUDIO_CHANNEL_MAX_STREAM_CH];
        SOUND_STREAM_CALLBACK cb;
+       void *cb_data;
 };
 
 struct audio_channel_data
@@ -634,14 +635,14 @@ static void get_extra_channels(int *data1, int *data2, int sample1, int sample2)
        }
 }
 
-static void do_extra_channels(int i, int *data1, int *data2, int *data3, int *data4, int *data5, int *data6)
+static void do_extra_channels(int idx, int ch, int *data1, int *data2, int *data3, int *data4, int *data5, int *data6)
 {
-       int idx = AUDIO_CHANNELS_PAULA + i * AUDIO_CHANNEL_MAX_STREAM_CH;
-       if (audio_extra_streams[i] == 2) {
+       idx += AUDIO_CHANNELS_PAULA;
+       if (ch == 2) {
                int datas[2];
                samplexx_anti_handler(datas, idx, 2);
                get_extra_channels(data1, data2, datas[0], datas[1]);
-       } else if (audio_extra_streams[i] == 1) {
+       } else if (ch == 1) {
                int datas[1];
                samplexx_anti_handler(datas, idx, 1);
                int d1 = *data1 + datas[0];
@@ -652,7 +653,7 @@ static void do_extra_channels(int i, int *data1, int *data2, int *data3, int *da
                *data1 = d1;
                if (data2)
                        *data2 = d1;
-       } else if (audio_extra_streams[i] > 2) {
+       } else if (ch > 2) {
                int datas[AUDIO_CHANNEL_MAX_STREAM_CH];
                samplexx_anti_handler(datas, idx, 6);
                get_extra_channels(data1, data2, datas[0], datas[1]);
@@ -667,8 +668,13 @@ static void get_extra_channels_sample2(int *data1, int *data2, int mode)
 {
        if (!audio_total_extra_streams)
                return;
+       int idx = 0;
        for (int i = 0; i < AUDIO_CHANNEL_STREAMS; i++) {
-               do_extra_channels(i, data1, data2, NULL, NULL, NULL, NULL);
+               int ch = audio_extra_streams[i];
+               if (ch) {
+                       do_extra_channels(idx, ch, data1, data2, NULL, NULL, NULL, NULL);
+                       idx += ch;
+               }
        }
 }
 
@@ -676,8 +682,13 @@ static void get_extra_channels_sample6(int *data1, int *data2, int *data3, int *
 {
        if (!audio_total_extra_streams)
                return;
+       int idx = 0;
        for (int i = 0; i < AUDIO_CHANNEL_STREAMS; i++) {
-               do_extra_channels(i, data1, data2, data3, data4, data5, data6);
+               int ch = audio_extra_streams[i];
+               if (ch) {
+                       do_extra_channels(idx, ch, data1, data2, data3, data4, data5, data6);
+                       idx += ch;
+               }
        }
 }
 
@@ -1675,7 +1686,7 @@ static void audio_state_channel (int nr, bool perfin)
                int streamid = nr - AUDIO_CHANNELS_PAULA + 1;
                struct audio_stream_data *asd = &audio_stream[nr - AUDIO_CHANNELS_PAULA];
                if (asd->cb) {
-                       ok = asd->cb(streamid);
+                       ok = asd->cb(streamid, asd->cb_data);
                }
                if (!ok) {
                        audio_state_stream_state(streamid, NULL, 0, MAX_EV);
@@ -2398,7 +2409,7 @@ static void audio_set_extra_channels(void)
        set_extra_prehandler();
 }
 
-int audio_enable_stream(bool enable, int streamid, int ch, SOUND_STREAM_CALLBACK cb)
+int audio_enable_stream(bool enable, int streamid, int ch, SOUND_STREAM_CALLBACK cb, void *cb_data)
 {
        if (streamid == 0)
                return 0;
@@ -2423,6 +2434,7 @@ int audio_enable_stream(bool enable, int streamid, int ch, SOUND_STREAM_CALLBACK
                audio_extra_streams[streamid] = ch;
                struct audio_stream_data *asd = audio_stream + streamid;
                asd->cb = cb;
+               asd->cb_data = cb_data;
                asd->evtime = CYCLE_UNIT;
                for (int i = 0; i < ch; i++) {
                        struct audio_channel_data2 *acd = &asd->data[i];
@@ -2451,69 +2463,67 @@ void audio_state_stream_state(int streamid, int *samplep, int highestch, unsigne
        asd->evtime = evt;
 }
 
-static uae_s16 *cda_bufptr;
-static int cda_length, cda_userdata;
 static unsigned int cda_evt;
 static uae_s16 dummy_buffer[4] = { 0 };
-static CDA_CALLBACK cda_next_cd_audio_buffer_callback;
-static int cda_volume[2];
-static int cda_streamid = -1;
 
 void update_cda_sound(double clk)
 {
        cda_evt = clk * CYCLE_UNIT / 44100;
 }
 
-void audio_cda_volume(int left, int right)
+void audio_cda_volume(struct cd_audio_state *cas, int left, int right)
 {
        for (int j = 0; j < 2; j++) {
-               cda_volume[j] = j == 0 ? left : right;
-               cda_volume[j] = sound_cd_volume[j] * cda_volume[j] / 32768;
-               if (cda_volume[j])
-                       cda_volume[j]++;
-               if (cda_volume[j] >= 32768)
-                       cda_volume[j] = 32768;
+               cas->cda_volume[j] = j == 0 ? left : right;
+               cas->cda_volume[j] = sound_cd_volume[j] * cas->cda_volume[j] / 32768;
+               if (cas->cda_volume[j])
+                       cas->cda_volume[j]++;
+               if (cas->cda_volume[j] >= 32768)
+                       cas->cda_volume[j] = 32768;
        }
 }
 
-static bool audio_state_cda(int streamid)
+static bool audio_state_cda(int streamid, void *state)
 {
-       if (cda_bufptr >= dummy_buffer && cda_bufptr <= dummy_buffer + 4) {
-               audio_enable_stream(false, cda_streamid, 0, NULL);
-               cda_streamid = 0;
+       struct cd_audio_state *cas = (struct cd_audio_state*)state;
+       if (cas->cda_bufptr >= dummy_buffer && cas->cda_bufptr <= dummy_buffer + 4) {
+               audio_enable_stream(false, cas->cda_streamid, 0, NULL, NULL);
+               cas->cda_streamid = 0;
                return false;
        }
-       if (cda_streamid <= 0)
+       if (cas->cda_streamid <= 0)
                return false;
        int samples[2];
-       samples[0] = cda_bufptr[0] * cda_volume[0] / 32768;
-       samples[1] = cda_bufptr[1] * cda_volume[1] / 32768;
+       samples[0] = cas->cda_bufptr[0] * cas->cda_volume[0] / 32768;
+       samples[1] = cas->cda_bufptr[1] * cas->cda_volume[1] / 32768;
        audio_state_stream_state(streamid, samples, 2, cda_evt);
-       cda_bufptr += 2;
-       cda_length--;
-       if (cda_length <= 0 && cda_next_cd_audio_buffer_callback) {
-               cda_next_cd_audio_buffer_callback(cda_userdata);
+       cas->cda_bufptr += 2;
+       cas->cda_length--;
+       if (cas->cda_length <= 0 && cas->cda_next_cd_audio_buffer_callback) {
+               cas->cda_next_cd_audio_buffer_callback(cas->cda_userdata, cas->cb_data);
        }
        return true;
 }
 
-void audio_cda_new_buffer(uae_s16 *buffer, int length, int userdata, CDA_CALLBACK next_cd_audio_buffer_callback)
+void audio_cda_new_buffer(struct cd_audio_state *cas, uae_s16 *buffer, int length, int userdata, CDA_CALLBACK next_cd_audio_buffer_callback, void *cb_data)
 {
-       if (length < 0 && cda_streamid > 0) {
-               audio_enable_stream(false, cda_streamid, 0, NULL);
-               cda_streamid = 0;
+       if (length < 0 && cas->cda_streamid > 0) {
+               audio_enable_stream(false, cas->cda_streamid, 0, NULL, cas);
+               cas->cda_streamid = 0;
                return;
        }
        if (!buffer) {
-               cda_bufptr = dummy_buffer;
-               cda_length = 0;
+               cas->cda_bufptr = dummy_buffer;
+               cas->cda_length = 0;
        } else {
-               cda_bufptr = buffer;
-               cda_length = length;
-               cda_userdata = userdata;
-               if (cda_streamid <= 0)
-                       cda_streamid = audio_enable_stream(true, -1, 2, audio_state_cda);
-       }
-       cda_next_cd_audio_buffer_callback = next_cd_audio_buffer_callback;
-       audio_activate();
+               cas->cda_bufptr = buffer;
+               cas->cda_length = length;
+               cas->cda_userdata = userdata;
+               if (cas->cda_streamid <= 0)
+                       cas->cda_streamid = audio_enable_stream(true, -1, 2, audio_state_cda, cas);
+       }
+       cas->cda_next_cd_audio_buffer_callback = next_cd_audio_buffer_callback;
+       cas->cb_data = cb_data;
+       if (cas->cda_streamid > 0)
+               audio_activate();
 }
index fe772cf86456631556b70b3513477c7f85608b5f..5321a12b48a65f41907a9dc570f65589464173cb 100644 (file)
@@ -106,6 +106,9 @@ struct cdunit {
        chd_file *chd_f;
        cdrom_file *chd_cdf;
 #endif
+       volatile int cda_bufon[2];
+       cda_audio *cda;
+       struct cd_audio_state cas;
 };
 
 static struct cdunit cdunits[MAX_TOTAL_SCSI_DEVICES];
@@ -442,22 +445,20 @@ static void audio_unpack (struct cdunit *cdu, struct cdtoc *t)
                sleep_millis(10);
 }
 
-static volatile int cda_bufon[2];
-static cda_audio *cda;
-
-static void next_cd_audio_buffer_callback(int bufnum)
+static void next_cd_audio_buffer_callback(int bufnum, void *params)
 {
+       struct cdunit *cdu = (struct cdunit*)params;
        uae_sem_wait(&play_sem);
        if (bufnum >= 0) {
-               cda_bufon[bufnum] = 0;
+               cdu->cda_bufon[bufnum] = 0;
                bufnum = 1 - bufnum;
-               if (cda_bufon[bufnum])
-                       audio_cda_new_buffer((uae_s16*)cda->buffers[bufnum], CDDA_BUFFERS * 2352 / 4, bufnum, next_cd_audio_buffer_callback);
+               if (cdu->cda_bufon[bufnum])
+                       audio_cda_new_buffer(&cdu->cas, (uae_s16*)cdu->cda->buffers[bufnum], CDDA_BUFFERS * 2352 / 4, bufnum, next_cd_audio_buffer_callback, cdu);
                else
                        bufnum = -1;
        }
        if (bufnum < 0) {
-               audio_cda_new_buffer(NULL, 0, -1, NULL);
+               audio_cda_new_buffer(&cdu->cas, NULL, -1, 0, NULL, cdu);
        }
        uae_sem_post(&play_sem);
 }
@@ -475,15 +476,16 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
        bool restart = false;
 
        cdu->thread_active = true;
+       memset(&cdu->cas, 0, sizeof(struct cd_audio_state));
 
        while (cdu->cdda_play == 0)
                sleep_millis(10);
        oldplay = -1;
 
-       cda_bufon[0] = cda_bufon[1] = 0;
+       cdu->cda_bufon[0] = cdu->cda_bufon[1] = 0;
        bufnum = 0;
 
-       cda = new cda_audio (CDDA_BUFFERS, 2352, 44100);
+       cdu->cda = new cda_audio (CDDA_BUFFERS, 2352, 44100, mode != 0);
 
        while (cdu->cdda_play > 0) {
 
@@ -574,7 +576,7 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
                }
 
                if (mode) {
-                       while (cda_bufon[bufnum] && cdu->cdda_play > 0) {
+                       while (cdu->cda_bufon[bufnum] && cdu->cdda_play > 0) {
                                if (cd_audio_mode_changed) {
                                        restart = true;
                                        goto end;
@@ -582,10 +584,10 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
                                sleep_millis(10);
                        }
                } else {
-                       cda->wait(bufnum);
+                       cdu->cda->wait(bufnum);
                }
 
-               cda_bufon[bufnum] = 0;
+               cdu->cda_bufon[bufnum] = 0;
                if (cdu->cdda_play <= 0)
                        goto end;
 
@@ -604,10 +606,10 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
 
                        setstate(cdu, AUDIO_STATUS_IN_PROGRESS, cdda_pos);
 
-                       memset (cda->buffers[bufnum], 0, CDDA_BUFFERS * 2352);
+                       memset (cdu->cda->buffers[bufnum], 0, CDDA_BUFFERS * 2352);
 
                        for (cnt = 0; cnt < CDDA_BUFFERS && cdu->cdda_play > 0; cnt++) {
-                               uae_u8 *dst = cda->buffers[bufnum] + cnt * 2352;
+                               uae_u8 *dst = cdu->cda->buffers[bufnum] + cnt * 2352;
                                uae_u8 subbuf[SUB_CHANNEL_SIZE];
                                sector = cdda_pos;
 
@@ -683,16 +685,16 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
                                cdu->cd_last_pos = cdda_pos;
 
                        if (mode) {
-                               if (cda_bufon[0] == 0 && cda_bufon[1] == 0) {
-                                       cda_bufon[bufnum] = 1;
-                                       next_cd_audio_buffer_callback(1 - bufnum);
+                               if (cdu->cda_bufon[0] == 0 && cdu->cda_bufon[1] == 0) {
+                                       cdu->cda_bufon[bufnum] = 1;
+                                       next_cd_audio_buffer_callback(1 - bufnum, cdu);
                                }
-                               audio_cda_volume(cdu->cdda_volume[0], cdu->cdda_volume[1]);
-                               cda_bufon[bufnum] = 1;
+                               audio_cda_volume(&cdu->cas, cdu->cdda_volume[0], cdu->cdda_volume[1]);
+                               cdu->cda_bufon[bufnum] = 1;
                        } else {
-                               cda_bufon[bufnum] = 1;
-                               cda->setvolume (cdu->cdda_volume[0], cdu->cdda_volume[1]);
-                               if (!cda->play (bufnum)) {
+                               cdu->cda_bufon[bufnum] = 1;
+                               cdu->cda->setvolume (cdu->cdda_volume[0], cdu->cdda_volume[1]);
+                               if (!cdu->cda->play (bufnum)) {
                                        if (cdu->cdda_play > 0)
                                                setstate (cdu, AUDIO_STATUS_PLAY_ERROR, -1);
                                        goto end;
@@ -708,7 +710,7 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
 
                }
 
-               if (cda_bufon[0] == 0 && cda_bufon[1] == 0) {
+               if (cdu->cda_bufon[0] == 0 && cdu->cda_bufon[1] == 0) {
                        while (cdu->cdda_paused && cdu->cdda_play == oldplay)
                                sleep_millis(10);
                }
@@ -724,18 +726,18 @@ static bool cdda_play_func2 (struct cdunit *cdu, int *outpos)
 end:
        *outpos = cdda_pos;
        if (mode) {
-               next_cd_audio_buffer_callback(-1);
+               next_cd_audio_buffer_callback(-1, cdu);
                if (restart)
-                       audio_cda_new_buffer(NULL, -1, -1, NULL);
+                       audio_cda_new_buffer(&cdu->cas, NULL, -1, -1, NULL, NULL);
        } else {
-               cda->wait (0);
-               cda->wait (1);
+               cdu->cda->wait (0);
+               cdu->cda->wait (1);
        }
 
        while (cdimage_unpack_active == 1)
                sleep_millis(10);
 
-       delete cda;
+       delete cdu->cda;
 
        write_log (_T("IMAGE CDDA: thread killed (%s)\n"), restart ? _T("restart") : _T("play end"));
        cd_audio_mode_changed = false;
index 876a82b8f364e42186b594aee1d08a5db2d9f0b1..8c12e810ec15125358323dee65b77a58a9157d92 100644 (file)
@@ -228,6 +228,7 @@ static bool audio_mode;
 static uae_sem_t play_sem;
 static volatile bool fmv_bufon[2];
 static double fmv_syncadjust;
+static struct cd_audio_state cas;
 
 struct cl450_videoram
 {
@@ -394,7 +395,7 @@ static void l64111_setvolume(void)
        write_log(_T("L64111 mute %d\n"), volume ? 0 : 1);
        if (cda) {
                if (audio_mode) {
-                       audio_cda_volume(volume, volume);
+                       audio_cda_volume(&cas, volume, volume);
                } else {
                        cda->setvolume(volume, volume);
                }
@@ -1373,19 +1374,19 @@ void cd32_fmv_set_sync(double svpos, double adjust)
        fmv_syncadjust = adjust;
 }
 
-static void fmv_next_cd_audio_buffer_callback(int bufnum)
+static void fmv_next_cd_audio_buffer_callback(int bufnum, void *param)
 {
        uae_sem_wait(&play_sem);
        if (bufnum >= 0) {
                fmv_bufon[bufnum] = 0;
                bufnum = 1 - bufnum;
                if (fmv_bufon[bufnum])
-                       audio_cda_new_buffer((uae_s16*)cda->buffers[bufnum], PCM_SECTORS * KJMP2_SAMPLES_PER_FRAME, bufnum, fmv_next_cd_audio_buffer_callback);
+                       audio_cda_new_buffer(&cas, (uae_s16*)cda->buffers[bufnum], PCM_SECTORS * KJMP2_SAMPLES_PER_FRAME, bufnum, fmv_next_cd_audio_buffer_callback, param);
                else
                        bufnum = -1;
        }
        if (bufnum < 0) {
-               audio_cda_new_buffer(NULL, 0, -1, NULL);
+               audio_cda_new_buffer(&cas, NULL, 0, -1, NULL, NULL);
        }
        uae_sem_post(&play_sem);
 }
@@ -1403,14 +1404,17 @@ static void cd32_fmv_audio_handler(void)
        if (!fmv_ram_bank.baseaddr)
                return;
 
-       if (cd_audio_mode_changed) {
+       if (cd_audio_mode_changed || (cl450_play && !cda)) {
                cd_audio_mode_changed = false;
                if (cl450_play) {
                        if (audio_mode) {
-                               audio_cda_new_buffer(NULL, -1, -1, NULL);
+                               audio_cda_new_buffer(&cas, NULL, -1, -1, NULL, NULL);
                        }
                        audio_mode = currprefs.sound_cdaudio;
                        fmv_bufon[0] = fmv_bufon[1] = 0;
+                       delete cda;
+                       cda = new cda_audio(PCM_SECTORS, KJMP2_SAMPLES_PER_FRAME * 4, 44100, audio_mode != 0);
+                       l64111_setvolume();
                }
        }
 
@@ -1458,7 +1462,7 @@ static void cd32_fmv_audio_handler(void)
        if (audio_mode) {
                if (!play0 && !play1) {
                        fmv_bufon[bufnum] = 1;
-                       fmv_next_cd_audio_buffer_callback(1 - bufnum);
+                       fmv_next_cd_audio_buffer_callback(1 - bufnum, NULL);
                }
                fmv_bufon[bufnum] = 1;
        } else {
@@ -1538,7 +1542,7 @@ void cd32_fmv_free(void)
        videoram = NULL;
        if (cda) {
                if (audio_mode) {
-                       fmv_next_cd_audio_buffer_callback(-1);
+                       fmv_next_cd_audio_buffer_callback(-1, NULL);
                } else {
                        cda->wait(0);
                        cda->wait(1);
@@ -1589,16 +1593,12 @@ addrbank *cd32_fmv_init (struct autoconfig_info *aci)
        mapped_malloc(&fmv_ram_bank);
        if (!pcmaudio)
                pcmaudio = xcalloc(struct fmv_pcmaudio, L64111_CHANNEL_BUFFERS);
-
        kjmp2_init(&mp2);
-       if (!cda) {
-               cda = new cda_audio(PCM_SECTORS, KJMP2_SAMPLES_PER_FRAME * 4, 44100);
-               l64111_setvolume();
-       }
        if (!mpeg_decoder) {
                mpeg_decoder = mpeg2_init();
                mpeg_info = mpeg2_info(mpeg_decoder);
        }
+       memset(&cas, 0, sizeof(cas));
        fmv_bank.mask = fmv_board_size - 1;
        map_banks(&fmv_rom_bank, (fmv_start + ROM_BASE) >> 16, fmv_rom_size >> 16, 0);
        map_banks(&fmv_ram_bank, (fmv_start + RAM_BASE) >> 16, fmv_ram_size >> 16, 0);
index a1c7d237709cf27fd36d635432a79593b14246f5..8b149a0e293afb0b4fd5b1fd4e08e61241cc90b0 100644 (file)
@@ -49,14 +49,24 @@ bool audio_is_event_frame_possible(int);
 
 extern int sampleripper_enabled;
 
-typedef void(*CDA_CALLBACK)(int);
-typedef bool(*SOUND_STREAM_CALLBACK)(int);
+typedef void(*CDA_CALLBACK)(int, void*);
+typedef bool(*SOUND_STREAM_CALLBACK)(int, void*);
 
-extern int audio_enable_stream(bool, int, int, SOUND_STREAM_CALLBACK);
+extern int audio_enable_stream(bool, int, int, SOUND_STREAM_CALLBACK, void*);
 extern void audio_state_stream_state(int, int*, int, unsigned int);
 
-extern void audio_cda_new_buffer(uae_s16 *buffer, int length, int userdata, CDA_CALLBACK next_cd_audio_buffer_callback);
-extern void audio_cda_volume(int left, int right);
+struct cd_audio_state
+{
+       uae_s16 *cda_bufptr;
+       int cda_length, cda_userdata;
+       CDA_CALLBACK cda_next_cd_audio_buffer_callback;
+       void *cb_data;
+       int cda_volume[2];
+       int cda_streamid = -1;
+};
+
+extern void audio_cda_new_buffer(struct cd_audio_state *cas, uae_s16 *buffer, int length, int userdata, CDA_CALLBACK next_cd_audio_buffer_callback, void *cb_data);
+extern void audio_cda_volume(struct cd_audio_state *cas, int left, int right);
 
 extern int sound_cd_volume[2];
 extern int sound_paula_volume[2];
index 19006063df4f1452b23d6801ecddcd00a071aa9c..7851c4408e5456ea78841ff3eef12a2eb28fc958 100644 (file)
@@ -73,6 +73,9 @@ struct dev_info_ioctl {
        bool open;
        bool usesptiread;
        bool changed;
+       cda_audio *cda;
+       volatile int cda_bufon[2];
+       struct cd_audio_state cas;
 };
 
 static struct dev_info_ioctl ciw32[MAX_TOTAL_SCSI_DEVICES];
@@ -483,22 +486,20 @@ static int setstate (struct dev_info_ioctl *ciw, int state, int playpos)
        return 0;
 }
 
-static cda_audio *cda;
-static volatile int cda_bufon[2];
-
-void ioctl_next_cd_audio_buffer_callback(int bufnum)
+void ioctl_next_cd_audio_buffer_callback(int bufnum, void *param)
 {
+       struct dev_info_ioctl *ciw = (struct dev_info_ioctl*)param;
        uae_sem_wait(&play_sem);
        if (bufnum >= 0) {
-               cda_bufon[bufnum] = 0;
+               ciw->cda_bufon[bufnum] = 0;
                bufnum = 1 - bufnum;
-               if (cda_bufon[bufnum])
-                       audio_cda_new_buffer((uae_s16*)cda->buffers[bufnum], CDDA_BUFFERS * 2352 / 4, bufnum, ioctl_next_cd_audio_buffer_callback);
+               if (ciw->cda_bufon[bufnum])
+                       audio_cda_new_buffer(&ciw->cas, (uae_s16*)ciw->cda->buffers[bufnum], CDDA_BUFFERS * 2352 / 4, bufnum, ioctl_next_cd_audio_buffer_callback, ciw);
                else
                        bufnum = -1;
        }
        if (bufnum < 0) {
-               audio_cda_new_buffer(NULL, 0, -1, NULL);
+               audio_cda_new_buffer(&ciw->cas, NULL, 0, -1, NULL, ciw);
        }
        uae_sem_post(&play_sem);
 }
@@ -520,16 +521,17 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
                sleep_millis(10);
        oldplay = -1;
 
-       cda_bufon[0] = cda_bufon[1] = 0;
+       ciw->cda_bufon[0] = ciw->cda_bufon[1] = 0;
        bufnum = 0;
        buffered = 0;
 
-       cda = new cda_audio (CDDA_BUFFERS, 2352, 44100);
+       memset(&ciw->cas, 0, sizeof(struct cd_audio_state));
+       ciw->cda = new cda_audio (CDDA_BUFFERS, 2352, 44100, mode != 0);
 
        while (ciw->cdda_play > 0) {
 
                if (mode) {
-                       while (cda_bufon[bufnum] && ciw->cdda_play > 0) {
+                       while (ciw->cda_bufon[bufnum] && ciw->cdda_play > 0) {
                                if (cd_audio_mode_changed) {
                                        restart = true;
                                        goto end;
@@ -537,11 +539,11 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
                                sleep_millis(10);
                        }
                } else {
-                       cda->wait(bufnum);
+                       ciw->cda->wait(bufnum);
                }
                if (ciw->cdda_play <= 0)
                        goto end;
-               cda_bufon[bufnum] = 0;
+               ciw->cda_bufon[bufnum] = 0;
 
                if (oldplay != ciw->cdda_play) {
                        idleframes = 0;
@@ -562,7 +564,7 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
                        }
                        // force spin up
                        if (isaudiotrack (&ciw->di.toc, cdda_pos))
-                               read_block (ciw, -1, cda->buffers[bufnum], cdda_pos, CDDA_BUFFERS, readblocksize);
+                               read_block (ciw, -1, ciw->cda->buffers[bufnum], cdda_pos, CDDA_BUFFERS, readblocksize);
                        if (!isaudiotrack (&ciw->di.toc, cdda_pos - 150))
                                muteframes = 75;
 
@@ -571,7 +573,7 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
                                // buggy CD32/CDTV software CD+G handling does not miss any frames
                                bool seenindex = false;
                                for (int sector = cdda_pos - 200; sector < cdda_pos; sector++) {
-                                       uae_u8 *dst = cda->buffers[bufnum];
+                                       uae_u8 *dst = ciw->cda->buffers[bufnum];
                                        if (sector >= 0 && isaudiotrack (&ciw->di.toc, sector) && read_block (ciw, -1, dst, sector, 1, readblocksize)) {
                                                uae_u8 subbuf[SUB_CHANNEL_SIZE];
                                                sub_deinterleave (dst + 2352, subbuf);
@@ -625,18 +627,18 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
 
                        ciw->subcodevalid = false;
                        memset (ciw->subcode, 0, sizeof ciw->subcode);
-                       memset (cda->buffers[bufnum], 0, CDDA_BUFFERS * readblocksize);
+                       memset (ciw->cda->buffers[bufnum], 0, CDDA_BUFFERS * readblocksize);
 
                        if (cdda_pos >= 0) {
 
                                setstate(ciw, AUDIO_STATUS_IN_PROGRESS, cdda_pos);
 
-                               if (read_block (ciw, -1, cda->buffers[bufnum], cdda_pos, CDDA_BUFFERS, readblocksize)) {
+                               if (read_block (ciw, -1, ciw->cda->buffers[bufnum], cdda_pos, CDDA_BUFFERS, readblocksize)) {
                                        for (i = 0; i < CDDA_BUFFERS; i++) {
-                                               memcpy (ciw->subcode + i * SUB_CHANNEL_SIZE, cda->buffers[bufnum] + readblocksize * i + 2352, SUB_CHANNEL_SIZE);
+                                               memcpy (ciw->subcode + i * SUB_CHANNEL_SIZE, ciw->cda->buffers[bufnum] + readblocksize * i + 2352, SUB_CHANNEL_SIZE);
                                        }
                                        for (i = 1; i < CDDA_BUFFERS; i++) {
-                                               memmove (cda->buffers[bufnum] + 2352 * i, cda->buffers[bufnum] + readblocksize * i, 2352);
+                                               memmove (ciw->cda->buffers[bufnum] + 2352 * i, ciw->cda->buffers[bufnum] + readblocksize * i, 2352);
                                        }
                                        ciw->subcodevalid = true;
                                }
@@ -644,15 +646,15 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
 
                        for (i = 0; i < CDDA_BUFFERS; i++) {
                                if (muteframes > 0) {
-                                       memset (cda->buffers[bufnum] + 2352 * i, 0, 2352);
+                                       memset (ciw->cda->buffers[bufnum] + 2352 * i, 0, 2352);
                                        muteframes--;
                                }
                                if (idleframes > 0) {
                                        idleframes--;
-                                       memset (cda->buffers[bufnum] + 2352 * i, 0, 2352);
+                                       memset (ciw->cda->buffers[bufnum] + 2352 * i, 0, 2352);
                                        memset (ciw->subcode + i * SUB_CHANNEL_SIZE, 0, SUB_CHANNEL_SIZE);
                                } else if (cdda_pos < ciw->cdda_start && ciw->cdda_scan == 0) {
-                                       memset (cda->buffers[bufnum] + 2352 * i, 0, 2352);
+                                       memset (ciw->cda->buffers[bufnum] + 2352 * i, 0, 2352);
                                }
                        }
                        if (idleframes > 0)
@@ -670,16 +672,16 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
                        }
 
                        if (mode) {
-                               if (cda_bufon[0] == 0 && cda_bufon[1] == 0) {
-                                       cda_bufon[bufnum] = 1;
-                                       ioctl_next_cd_audio_buffer_callback(1 - bufnum);
+                               if (ciw->cda_bufon[0] == 0 && ciw->cda_bufon[1] == 0) {
+                                       ciw->cda_bufon[bufnum] = 1;
+                                       ioctl_next_cd_audio_buffer_callback(1 - bufnum, ciw);
                                }
-                               audio_cda_volume(ciw->cdda_volume[0], ciw->cdda_volume[1]);
-                               cda_bufon[bufnum] = 1;
+                               audio_cda_volume(&ciw->cas, ciw->cdda_volume[0], ciw->cdda_volume[1]);
+                               ciw->cda_bufon[bufnum] = 1;
                        } else {
-                               cda_bufon[bufnum] = 1;
-                               cda->setvolume (ciw->cdda_volume[0], ciw->cdda_volume[1]);
-                               if (!cda->play (bufnum)) {
+                               ciw->cda_bufon[bufnum] = 1;
+                               ciw->cda->setvolume (ciw->cdda_volume[0], ciw->cdda_volume[1]);
+                               if (!ciw->cda->play (bufnum)) {
                                        setstate (ciw, AUDIO_STATUS_PLAY_ERROR, -1);
                                        goto end; // data track?
                                }
@@ -707,7 +709,7 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
                        }
                }
 
-               if (cda_bufon[0] == 0 && cda_bufon[1] == 0) {
+               if (ciw->cda_bufon[0] == 0 && ciw->cda_bufon[1] == 0) {
                        while (ciw->cdda_paused && ciw->cdda_play == oldplay)
                                sleep_millis(10);
                }
@@ -724,17 +726,17 @@ static bool cdda_play2 (struct dev_info_ioctl *ciw, int *outpos)
 end:
        *outpos = cdda_pos;
        if (mode) {
-               ioctl_next_cd_audio_buffer_callback(-1);
+               ioctl_next_cd_audio_buffer_callback(-1, ciw);
                if (restart)
-                       audio_cda_new_buffer(NULL, -1, -1, NULL);
+                       audio_cda_new_buffer(&ciw->cas, NULL, -1, -1, NULL, ciw);
        } else {
-               cda->wait (0);
-               cda->wait (1);
+               ciw->cda->wait (0);
+               ciw->cda->wait (1);
        }
 
        ciw->subcodevalid = false;
        cd_audio_mode_changed = false;
-       delete cda;
+       delete ciw->cda;
 
        write_log (_T("IOCTL CDDA: thread killed\n"));
        return restart;
index 5ddea5d12387b001c69f1be30f3352532252c1bc..35c630993461249e8932a48f8f61a2659843c61e 100644 (file)
 
 cda_audio::~cda_audio()
 {
-       wait (0);
-       wait (1);
+       if (active) {
+               wait(0);
+               wait(1);
 #if CDADS
-       if (dsnotify)
-               dsnotify->Release();
-       if (dsbuf)
-               dsbuf->Release();
-       if (ds)
-               ds->Release();
-       if (notifyevent[0])
-               CloseHandle (notifyevent[0]);
-       if (notifyevent[1])
-               CloseHandle (notifyevent[1]);
+               if (dsnotify)
+                       dsnotify->Release();
+               if (dsbuf)
+                       dsbuf->Release();
+               if (ds)
+                       ds->Release();
+               if (notifyevent[0])
+                       CloseHandle(notifyevent[0]);
+               if (notifyevent[1])
+                       CloseHandle(notifyevent[1]);
 #else
-       if (active) {
                for (int i = 0; i < 2; i++)
-                       waveOutUnprepareHeader  (wavehandle, &whdr[i], sizeof (WAVEHDR));
-       }
-       if (wavehandle != NULL)
-               waveOutClose (wavehandle);
+                       waveOutUnprepareHeader(wavehandle, &whdr[i], sizeof(WAVEHDR));
+               if (wavehandle != NULL)
+                       waveOutClose(wavehandle);
 #endif
+       }
        for (int i = 0; i < 2; i++) {
                xfree (buffers[i]);
                buffers[i] = NULL;
        }
 }
 
-cda_audio::cda_audio(int num_sectors, int sectorsize, int samplerate)
+cda_audio::cda_audio(int num_sectors, int sectorsize, int samplerate, bool internalmode)
 {
        active = false;
        playing = false;
@@ -64,6 +64,10 @@ cda_audio::cda_audio(int num_sectors, int sectorsize, int samplerate)
        for (int i = 0; i < 2; i++) {
                buffers[i] = xcalloc (uae_u8, num_sectors * ((bufsize + 4095) & ~4095));
        }
+       this->num_sectors = num_sectors;
+
+       if (internalmode)
+               return;
 
        WAVEFORMATEX wav;
        memset (&wav, 0, sizeof (WAVEFORMATEX));
@@ -151,7 +155,6 @@ cda_audio::cda_audio(int num_sectors, int sectorsize, int samplerate)
                write_log (_T("IMAGE CDDA: wave open %d\n"), mmr);
                return;
        }
-       this->num_sectors = num_sectors;
        for (int i = 0; i < 2; i++) {
                memset (&whdr[i], 0, sizeof(WAVEHDR));
                whdr[i].dwBufferLength = sectorsize * num_sectors;
index 2b8faea090b022a7dc8cdb99ec952edb7635af27..d36d2a7863f24f93a16ca7b35af11b9d1be047af 100644 (file)
@@ -26,7 +26,7 @@ private:
 public:
        uae_u8 *buffers[2];
 
-       cda_audio(int num_sectors, int sectorsize, int samplerate);
+       cda_audio(int num_sectors, int sectorsize, int samplerate, bool internalmode);
        ~cda_audio();
        void setvolume(int left, int right);
        bool play(int bufnum);
index 962769fc6ea16070dade9201810c65a1d19ad9bd..860e99ee79fb9e6ba137bd621305ff465cbb83a8 100644 (file)
@@ -219,7 +219,7 @@ static struct uaesndboard_data uaesndboard[MAX_DUPLICATE_SOUND_BOARDS];
 
 #define STREAM_STRUCT_SIZE 40
 
-static bool audio_state_sndboard_uae(int streamid);
+static bool audio_state_sndboard_uae(int streamid, void *params);
 
 extern addrbank uaesndboard_ram_bank;
 MEMORY_FUNCTIONS(uaesndboard_ram);
@@ -311,7 +311,7 @@ static void uaesndboard_stop(struct uaesndboard_data *data, struct uaesndboard_s
                return;
        s->play = 0;
        data->streammask &= ~(1 << (s - data->stream));
-       audio_enable_stream(false, s->streamid, 0, NULL);
+       audio_enable_stream(false, s->streamid, 0, NULL, NULL);
        s->streamid = 0;
        data->streamcnt--;
 }
@@ -330,7 +330,7 @@ static void uaesndboard_start(struct uaesndboard_data *data, struct uaesndboard_
                s->sample[i] = 0;
        }
        uaesnd_setfreq(s);
-       s->streamid = audio_enable_stream(true, -1, MAX_UAE_CHANNELS, audio_state_sndboard_uae);
+       s->streamid = audio_enable_stream(true, -1, MAX_UAE_CHANNELS, audio_state_sndboard_uae, NULL);
        if (!s->streamid) {
                uaesndboard_stop(data, s);
        }
@@ -511,7 +511,7 @@ static void uaesnd_streammask(struct uaesndboard_data *data, uae_u32 m)
        }
 }
 
-static bool audio_state_sndboard_uae(int streamid)
+static bool audio_state_sndboard_uae(int streamid, void *params)
 {
        struct uaesndboard_data *data = &uaesndboard[0];
        struct uaesndboard_stream *s = NULL;
@@ -1010,7 +1010,7 @@ void uaesndboard_reset(void)
                if (data->enabled) {
                        for (int i = 0; i < MAX_UAE_STREAMS; i++) {
                                if (data->stream[i].streamid) {
-                                       audio_enable_stream(false, data->stream[i].streamid, 0, NULL);
+                                       audio_enable_stream(false, data->stream[i].streamid, 0, NULL, NULL);
                                        memset(&data->stream[i], 0, sizeof(struct uaesndboard_stream));
                                }
                        }
@@ -1270,7 +1270,7 @@ static void process_fifo(void)
                data->fifo_half |= STATUS_FIFO_PLAY;
 }
 
-static bool audio_state_sndboard_toccata(int streamid)
+static bool audio_state_sndboard_toccata(int streamid, void *params)
 {
        struct toccata_data *data = &toccata[0];
        if (!toccata[0].toccata_active)
@@ -1393,7 +1393,7 @@ static void codec_start(void)
        data->record_event_counter = 0;
 
        if (data->toccata_active & STATUS_FIFO_PLAY) {
-               data->streamid = audio_enable_stream(true, -1, 2, audio_state_sndboard_toccata);
+               data->streamid = audio_enable_stream(true, -1, 2, audio_state_sndboard_toccata, NULL);
        }
        if (data->toccata_active & STATUS_FIFO_RECORD) {
                capture_buffer = xcalloc(uae_u8, capture_buffer_size);
@@ -1409,7 +1409,7 @@ static void codec_stop(void)
        write_log(_T("TOCCATA stop\n"));
        data->toccata_active = 0;
        sndboard_free_capture();
-       audio_enable_stream(false, data->streamid, 0, NULL);
+       audio_enable_stream(false, data->streamid, 0, NULL, NULL);
        data->streamid = 0;
        xfree(capture_buffer);
        capture_buffer = NULL;
@@ -1803,7 +1803,7 @@ void sndboard_reset(void)
        codec_stop();
        data->toccata_irq = 0;
        if (data->streamid > 0)
-               audio_enable_stream(false, data->streamid, 0, NULL);
+               audio_enable_stream(false, data->streamid, 0, NULL, NULL);
        data->streamid = 0;
        sndboard_rethink();
        mapped_free(&toccata_bank);
@@ -1856,7 +1856,7 @@ static void fm801_stop(struct fm801_data *data)
 {
        write_log(_T("FM801 STOP\n"));
        data->play_on = false;
-       audio_enable_stream(false, data->streamid, 0, NULL);
+       audio_enable_stream(false, data->streamid, 0, NULL, NULL);
        data->streamid = 0;
 }
 
@@ -1879,7 +1879,7 @@ static void fm801_interrupt(struct fm801_data *data)
        }
 }
 
-static bool audio_state_sndboard_fm801(int streamid)
+static bool audio_state_sndboard_fm801(int streamid, void *params)
 {
        struct fm801_data *data = &fm801;
 
@@ -1957,7 +1957,7 @@ static void fm801_play(struct fm801_data *data)
 
        write_log(_T("FM801 PLAY: freq=%d ch=%d bits=%d\n"), data->freq, data->ch, data->bits);
 
-       data->streamid = audio_enable_stream(true, -1, data->ch, audio_state_sndboard_fm801);
+       data->streamid = audio_enable_stream(true, -1, data->ch, audio_state_sndboard_fm801, NULL);
 }
 
 static void fm801_pause(struct fm801_data *data, bool pause)
@@ -2223,7 +2223,7 @@ const struct pci_board solo1_pci_board =
 
 static SWVoiceOut *qemu_voice_out;
 
-static bool audio_state_sndboard_qemu(int streamid)
+static bool audio_state_sndboard_qemu(int streamid, void *params)
 {
        SWVoiceOut *out = qemu_voice_out;
 
@@ -2299,10 +2299,10 @@ void AUD_set_active_out(SWVoiceOut *sw, int on)
        sw->samplebuf_index = 0;
        sw->samplebuf_total = 0;
        calculate_volume_qemu();
-       audio_enable_stream(false, sw->streamid, 2, NULL);
+       audio_enable_stream(false, sw->streamid, 2, NULL, NULL);
        sw->streamid = 0;
        if (on) {
-               sw->streamid = audio_enable_stream(true, -1, 2, audio_state_sndboard_qemu);
+               sw->streamid = audio_enable_stream(true, -1, 2, audio_state_sndboard_qemu, NULL);
        }
 }
 void AUD_set_active_in(SWVoiceIn *sw, int on)
@@ -2316,7 +2316,7 @@ void AUD_close_out(QEMUSoundCard *card, SWVoiceOut *sw)
 {
        qemu_voice_out = NULL;
        if (sw) {
-               audio_enable_stream(false, sw->streamid, 0, NULL);
+               audio_enable_stream(false, sw->streamid, 0, NULL, NULL);
                sw->streamid = 0;
                xfree(sw);
        }
diff --git a/x86.cpp b/x86.cpp
index 5ff82f3c2f687b851b3b143facc5e0a835c78ede..17140ddff50f9fe57ce57cab6eeabb9d5e208a2f 100644 (file)
--- a/x86.cpp
+++ b/x86.cpp
@@ -1479,7 +1479,7 @@ static void set_pc_io_access(struct x86_bridge *xb, uaecptr portnum, bool write)
                        xb->delayed_interrupt |= 1 << 2;
                }
        } else if (write && (portnum == 0x3d1 || portnum == 0x3d3 || portnum == 0x3d5 || portnum == 0x3d7 || portnum == 0x3d8 || portnum == 0x3d9 || portnum == 0x3dd)) {
-                       // color crt data register
+               // color crt data register
                if (!xb->video_initialized) {
                        set_initial_cpu_turbo(xb);
                }
@@ -3107,7 +3107,7 @@ void x86_bridge_reset(void)
                        zfile_fwrite(nvrram, 1, xb->cmossize, xb->cmosfile);
                }
                if (xb->audstream) {
-                       audio_enable_stream(false, xb->audstream, 0, NULL);
+                       audio_enable_stream(false, xb->audstream, 0, NULL, NULL);
                }
                zfile_fclose(xb->cmosfile);
                xfree(xb->amiga_io);
@@ -3172,7 +3172,7 @@ static void x86_cpu_execute(int cycs)
        check_floppy_delay();
 }
 
-static bool audio_state_sndboard_x86(int streamid)
+static bool audio_state_sndboard_x86(int streamid, void *param)
 {
        static int smp[2] = { 0, 0 };
        struct x86_bridge *xb = bridges[0];
@@ -3242,7 +3242,7 @@ void x86_bridge_hsync(void)
                        write_log(_T("x86 sound init\n"));
                        xb->audeventtime = x86_base_event_clock * CYCLE_UNIT / currprefs.sound_freq + 1;
                        timer_add(sound_poll, &sound_poll_time, TIMER_ALWAYS_ENABLED, NULL);
-                       xb->audstream = audio_enable_stream(true, -1, 2, audio_state_sndboard_x86);
+                       xb->audstream = audio_enable_stream(true, -1, 2, audio_state_sndboard_x86, NULL);
                }
        }