Previous 199869 Revisions Next

r22815 Monday 13th May, 2013 at 23:35:54 UTC by smf
modernised CDDA & discard buffered samples when starting to play to avoid audio glitches and timing issues. [smf]
[src/emu/machine]matsucd.c scsicd.c scsicd.h stvcd.c
[src/emu/sound]cdda.c cdda.h
[src/mame/machine]cd32.c cdicdic.c gdrom.c gdrom.h megacdcd.c
[src/mess/drivers]fmtowns.c
[src/mess/includes]fmtowns.h
[src/mess/machine]pce.c

trunk/src/mame/machine/cdicdic.c
r22814r22815
813813//              next_lba = next_nybbles[0] + next_nybbles[1]*10 + ((next_nybbles[2] + next_nybbles[3]*10)*75) + ((next_nybbles[4] + next_nybbles[5]*10)*75*60);
814814            verboselog(machine(), 0, "Playing CDDA sector from MSF location %06x\n", m_time | 2 );
815815
816            cdda_start_audio(state->m_cdda, lba, rounded_next_msf);
816            state->m_cdda->start_audio(lba, rounded_next_msf);
817817         }
818818
819819         m_ram[(m_data_buffer & 5) * (0xa00/2) + 0x924/2] = 0x0001;                      //  CTRL
r22814r22815
11151115                  break;
11161116               }
11171117               case 0x2b: // Stop CDDA
1118                  cdda_stop_audio(state->m_cdda);
1118                  state->m_cdda->stop_audio();
11191119                  m_interrupt_timer->adjust(attotime::never);
11201120                  break;
11211121               case 0x23: // Reset Mode 1
r22814r22815
12261226   {
12271227      // MESS case (has CDROM device)
12281228      m_cd = cdrom_dev->get_cdrom_file();
1229      cdda_set_cdrom(state->m_cdda, m_cd);
1229      state->m_cdda->set_cdrom(m_cd);
12301230   }
12311231   else
12321232   {
12331233      // MAME case
12341234      m_cd = cdrom_open(get_disk_handle(machine(), ":cdrom"));
1235      cdda_set_cdrom(state->m_cdda, m_cd);
1235      state->m_cdda->set_cdrom(m_cd);
12361236   }
12371237}
12381238
trunk/src/mame/machine/gdrom.c
r22814r22815
77#include "emu.h"
88#include "machine/scsihle.h"
99#include "cdrom.h"
10#include "sound/cdda.h"
1110#include "imagedev/chd_cd.h"
1211#include "gdrom.h"
1312
r22814r22815
2928const device_type GDROM = &device_creator<gdrom_device>;
3029
3130gdrom_device::gdrom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
32   : scsihle_device(mconfig, GDROM, "GDROM", tag, owner, clock, "gdrom", __FILE__)
31   : scsihle_device(mconfig, GDROM, "GDROM", tag, owner, clock, "gdrom", __FILE__),
32      m_cdda(*this, "cdda")
3333{
3434}
3535
r22814r22815
103103
104104void gdrom_device::ExecCommand( int *transferLength )
105105{
106   device_t *cdda;
107106   int trk;
108107
109108   switch ( command[0] )
r22814r22815
141140         break;
142141
143142      case 0x1b: // START STOP UNIT
144         cdda = cdda_from_cdrom( machine(), cdrom);
145         if (cdda != NULL)
143         if (m_cdda != NULL)
146144         {
147            cdda_stop_audio(cdda);
145            m_cdda->stop_audio();
148146         }
149147         SetPhase( SCSI_PHASE_STATUS );
150148         *transferLength = 0;
r22814r22815
177175            cur_subblock = 0;
178176         }
179177
180         cdda = cdda_from_cdrom(machine(), cdrom);
181         if (cdda != NULL)
178         if (m_cdda != NULL)
182179         {
183            cdda_stop_audio(cdda);
180            m_cdda->stop_audio();
184181         }
185182
186183         SetPhase( SCSI_PHASE_DATAIN );
r22814r22815
223220               cur_subblock = 0;
224221            }
225222
226            cdda = cdda_from_cdrom(machine(), cdrom);
227            if (cdda != NULL)
223            if (m_cdda != NULL)
228224            {
229               cdda_stop_audio(cdda);
225               m_cdda->stop_audio();
230226            }
231227
232228            SetPhase( SCSI_PHASE_DATAIN );
r22814r22815
266262            length = 4;
267263         }
268264
269         cdda = cdda_from_cdrom(machine(), cdrom);
270         if (cdda != NULL)
265         if (m_cdda != NULL)
271266         {
272            cdda_stop_audio(cdda);
267            m_cdda->stop_audio();
273268         }
274269
275270         SetPhase( SCSI_PHASE_DATAIN );
r22814r22815
297292         if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO)
298293         {
299294            play_err_flag = 0;
300            cdda = cdda_from_cdrom(machine(), cdrom);
301            if (cdda != NULL)
302               cdda_start_audio(cdda, lba, blocks);
295            if (m_cdda != NULL)
296               m_cdda->start_audio(lba, blocks);
303297         }
304298         else
305299         {
r22814r22815
328322
329323         if (blocks && cdrom)
330324         {
331            cdda = cdda_from_cdrom(machine(), cdrom);
332            if (cdda != NULL)
333               cdda_start_audio(cdda, lba, blocks);
325            if (m_cdda != NULL)
326               m_cdda->start_audio(lba, blocks);
334327         }
335328
336329         logerror("GDROM: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], blocks);
r22814r22815
341334      case 0x4b: // PAUSE/RESUME
342335         if (cdrom)
343336         {
344            cdda = cdda_from_cdrom(machine(), cdrom);
345            if (cdda != NULL)
346               cdda_pause_audio(cdda, (command[8] & 0x01) ^ 0x01);
337            if (m_cdda != NULL)
338               m_cdda->pause_audio((command[8] & 0x01) ^ 0x01);
347339         }
348340
349341         logerror("GDROM: PAUSE/RESUME: %s\n", command[8]&1 ? "RESUME" : "PAUSE");
r22814r22815
383375         if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO)
384376         {
385377            play_err_flag = 0;
386            cdda = cdda_from_cdrom(machine(), cdrom);
387            if (cdda != NULL)
388               cdda_start_audio(cdda, lba, blocks);
378            if (m_cdda != NULL)
379               m_cdda->start_audio(lba, blocks);
389380         }
390381         else
391382         {
r22814r22815
412403            cur_subblock = 0;
413404         }
414405
415         cdda = cdda_from_cdrom(machine(), cdrom);
416         if (cdda != NULL)
406         if (m_cdda != NULL)
417407         {
418            cdda_stop_audio(cdda);
408            m_cdda->stop_audio();
419409         }
420410
421411         SetPhase( SCSI_PHASE_DATAIN );
r22814r22815
444434   UINT32 last_phys_frame;
445435   UINT32 temp;
446436   UINT8 tmp_buffer[2048];
447   device_t *cdda;
448437
449438   switch ( command[0] )
450439   {
r22814r22815
455444
456445         data[0] = 0x71; // deferred error
457446
458         cdda = cdda_from_cdrom(machine(), cdrom);
459         if (cdda != NULL && cdda_audio_active(cdda))
447         if (m_cdda != NULL && m_cdda->audio_active())
460448         {
461449            data[12] = 0x00;
462450            data[13] = 0x11;    // AUDIO PLAY OPERATION IN PROGRESS
r22814r22815
583571
584572               msf = command[1] & 0x2;
585573
586               cdda = cdda_from_cdrom(machine(), cdrom);
587               audio_active = cdda != NULL && cdda_audio_active(cdda);
574               audio_active = m_cdda != NULL && m_cdda->audio_active();
588575               if (audio_active)
589576               {
590                  if (cdda_audio_paused(cdda))
577                  if (m_cdda->audio_paused())
591578                  {
592579                     data[1] = 0x12;     // audio is paused
593580                  }
r22814r22815
598585               }
599586               else
600587               {
601                  if (cdda != NULL && cdda_audio_ended(cdda))
588                  if (m_cdda != NULL && m_cdda->audio_ended())
602589                  {
603590                     data[1] = 0x13; // ended successfully
604591                  }
r22814r22815
612599               // if audio is playing, get the latest LBA from the CDROM layer
613600               if (audio_active)
614601               {
615                  last_lba = cdda_get_audio_lba(cdda);
602                  last_lba = m_cdda->get_audio_lba();
616603               }
617604               else
618605               {
trunk/src/mame/machine/gdrom.h
r22814r22815
88#define _GDROM_H_
99
1010#include "machine/scsihle.h"
11#include "sound/cdda.h"
1112
1213// Sega GD-ROM handler
1314class gdrom_device : public scsihle_device
r22814r22815
4344   UINT32 read_type;   // for command 0x30 only
4445   UINT32 data_select; // for command 0x30 only
4546   cdrom_file *cdrom;
47   optional_device<cdda_device> m_cdda;
4648   bool is_file;
4749};
4850
trunk/src/mame/machine/megacdcd.c
r22814r22815
201201   SCD_STATUS = CDD_STOPPED;
202202   CDD_STATUS = 0x0000;
203203   SET_CDD_DATA_MODE
204   cdda_stop_audio( m_cdda ); //stop any pending CD-DA
204   m_cdda->stop_audio(); //stop any pending CD-DA
205205
206206   //neocd
207207   NeoCD_StatusHack = 0x0E;
r22814r22815
366366   printf("%d Track played\n",SCD_CURTRK);
367367   CDD_MIN = to_bcd(SCD_CURTRK, false);
368368   if(!(CURRENT_TRACK_IS_DATA))
369      cdda_start_audio( m_cdda, SCD_CURLBA, end_msf - SCD_CURLBA );
369      m_cdda->start_audio(SCD_CURLBA, end_msf - SCD_CURLBA);
370370   SET_CDC_READ
371371
372372
r22814r22815
399399
400400   //segacd.current_frame = cdda_get_audio_lba( machine.device( "cdda" ) );
401401   //if(!(CURRENT_TRACK_IS_DATA))
402   cdda_pause_audio( m_cdda, 1 );
402   m_cdda->pause_audio(1);
403403
404404
405405   NeoCD_StatusHack = 4;
r22814r22815
418418   CDD_MIN = to_bcd (SCD_CURTRK, false);
419419   SET_CDC_READ
420420   //if(!(CURRENT_TRACK_IS_DATA))
421   cdda_pause_audio( m_cdda, 0 );
421   m_cdda->pause_audio(0);
422422
423423   NeoCD_StatusHack = 1;
424424}
r22814r22815
993993
994994   //printf("%f\n",cdfader_vol);
995995
996   cdda_set_volume( m_cdda, cdfader_vol);
996   m_cdda->set_volume(cdfader_vol);
997997}
998998
999999void lc89510_temp_device::reset_cd(void)
r22814r22815
10101010         if ( segacd.cd )
10111011         {
10121012            segacd.toc = cdrom_get_toc( segacd.cd );
1013            cdda_set_cdrom( m_cdda, segacd.cd );
1014            cdda_stop_audio(m_cdda ); //stop any pending CD-DA
1013            m_cdda->set_cdrom(segacd.cd);
1014            m_cdda->stop_audio(); //stop any pending CD-DA
10151015         }
10161016      }
10171017   }
trunk/src/mame/machine/cd32.c
r22814r22815
6161   UINT8   m_cdrom_cmd_start;
6262   UINT8   m_cdrom_cmd_end;
6363   UINT8   m_cdrom_cmd_resp;
64   cdda_device *m_cdda;
6465   cdrom_file *m_cdrom;
6566   UINT8 * m_cdrom_toc;
6667   emu_timer *m_dma_timer;
r22814r22815
203204   state->m_dma_timer = machine.scheduler().timer_alloc(FUNC(akiko_dma_proc), state);
204205   state->m_frame_timer = machine.scheduler().timer_alloc(FUNC(akiko_frame_proc), state);
205206   state->m_i2cmem = machine.device("i2cmem");
206
207
207   state->m_cdda = machine.device<cdda_device>("cdda");
208208}
209209
210210static void akiko_nvram_write(akiko_state *state, UINT32 data)
r22814r22815
323323
324324static void akiko_cdda_stop(akiko_state *state)
325325{
326   device_t *cdda = cdda_from_cdrom(state->machine(), state->m_cdrom);
327
328   if (cdda != NULL)
326   if (state->m_cdda != NULL)
329327   {
330      cdda_stop_audio(cdda);
328      state->m_cdda->stop_audio();
331329      state->m_frame_timer->reset(  );
332330   }
333331}
334332
335333static void akiko_cdda_play(akiko_state *state, UINT32 lba, UINT32 num_blocks)
336334{
337   device_t *cdda = cdda_from_cdrom(state->machine(), state->m_cdrom);
338   if (cdda != NULL)
335   if (state->m_cdda != NULL)
339336   {
340      cdda_start_audio(cdda, lba, num_blocks);
337      state->m_cdda->start_audio(lba, num_blocks);
341338      state->m_frame_timer->adjust( attotime::from_hz( 75 ) );
342339   }
343340}
344341
345342static void akiko_cdda_pause(akiko_state *state, int pause)
346343{
347   device_t *cdda = cdda_from_cdrom(state->machine(), state->m_cdrom);
348   if (cdda != NULL)
344   if (state->m_cdda != NULL)
349345   {
350      if (cdda_audio_active(cdda) && cdda_audio_paused(cdda) != pause )
346      if (state->m_cdda->audio_active() && state->m_cdda->audio_paused() != pause )
351347      {
352         cdda_pause_audio(cdda, pause);
348         state->m_cdda->pause_audio(pause);
353349
354350         if ( pause )
355351         {
r22814r22815
365361
366362static UINT8 akiko_cdda_getstatus(akiko_state *state, UINT32 *lba)
367363{
368   device_t *cdda = cdda_from_cdrom(state->machine(), state->m_cdrom);
369
370364   if ( lba ) *lba = 0;
371365
372   if (cdda != NULL)
366   if (state->m_cdda != NULL)
373367   {
374      if (cdda_audio_active(cdda))
368      if (state->m_cdda->audio_active())
375369      {
376         if ( lba ) *lba = cdda_get_audio_lba(cdda);
370         if ( lba ) *lba = state->m_cdda->get_audio_lba();
377371
378         if (cdda_audio_paused(cdda))
372         if (state->m_cdda->audio_paused())
379373         {
380374            return 0x12;    /* audio paused */
381375         }
r22814r22815
384378            return 0x11;    /* audio in progress */
385379         }
386380      }
387      else if (cdda_audio_ended(cdda))
381      else if (state->m_cdda->audio_ended())
388382      {
389383         return 0x13;    /* audio ended */
390384      }
r22814r22815
409403static TIMER_CALLBACK(akiko_frame_proc)
410404{
411405   akiko_state *state = (akiko_state *)ptr;
412   device_t *cdda = cdda_from_cdrom(machine, state->m_cdrom);
413406
414407   (void)param;
415408
416   if (cdda != NULL)
409   if (state->m_cdda != NULL)
417410   {
418411      UINT8   s = akiko_cdda_getstatus(state, NULL);
419412
r22814r22815
787780   switch( offset )
788781   {
789782      case 0x00/4:    /* ID */
790         if ( state->m_cdrom != NULL ) cdda_set_cdrom(state->m_space->machine().device("cdda"), state->m_cdrom);
783         if ( state->m_cdrom != NULL ) state->m_cdda->set_cdrom(state->m_cdrom);
791784         return 0x0000cafe;
792785
793786      case 0x04/4:    /* CDROM STATUS 1 */
trunk/src/emu/sound/cdda.c
r22814r22815
44*/
55
66#include "emu.h"
7#include "cdrom.h"
87#include "cdda.h"
98
10struct cdda_info
11{
12   sound_stream *      stream;
13   cdrom_file *        disc;
14
15   INT8                audio_playing, audio_pause, audio_ended_normally;
16   UINT32              audio_lba, audio_length;
17
18   UINT8 *             audio_cache;
19   UINT32              audio_samples;
20   UINT32              audio_bptr;
21   INT16               audio_volume[2];
22};
23
24INLINE cdda_info *get_safe_token(device_t *device)
25{
26   assert(device != NULL);
27   assert(device->type() == CDDA);
28   return (cdda_info *)downcast<cdda_device *>(device)->token();
29}
30
319#define MAX_SECTORS ( 4 )
3210
33static void get_audio_data(cdda_info *info, stream_sample_t *bufL, stream_sample_t *bufR, UINT32 samples_wanted);
3411
12//-------------------------------------------------
13//  sound_stream_update - handle a stream update
14//-------------------------------------------------
3515
36/*-------------------------------------------------
37    cdda_update - stream update callback
38-------------------------------------------------*/
39
40static STREAM_UPDATE( cdda_update )
16void cdda_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
4117{
42   cdda_info *info = (cdda_info *)param;
43   get_audio_data(info, &outputs[0][0], &outputs[1][0], samples);
44   info->audio_volume[0] = (INT16)outputs[0][0];
45   info->audio_volume[1] = (INT16)outputs[1][0];
18   get_audio_data(&outputs[0][0], &outputs[1][0], samples);
19   m_audio_volume[0] = (INT16)outputs[0][0];
20   m_audio_volume[1] = (INT16)outputs[1][0];
4621}
4722
23//-------------------------------------------------
24//  device_start - device-specific startup
25//-------------------------------------------------
4826
49/*-------------------------------------------------
50    DEVICE_START( cdda ) - audio start callback
51-------------------------------------------------*/
52
53static DEVICE_START( cdda )
27void cdda_device::device_start()
5428{
55   //const struct CDDAinterface *intf;
56   cdda_info *info = get_safe_token(device);
57
5829   /* allocate an audio cache */
59   info->audio_cache = auto_alloc_array( device->machine(), UINT8, CD_MAX_SECTOR_DATA * MAX_SECTORS );
30   m_audio_cache = auto_alloc_array( machine(), UINT8, CD_MAX_SECTOR_DATA * MAX_SECTORS );
6031
61   //intf = (const struct CDDAinterface *)device->static_config();
32   m_stream = machine().sound().stream_alloc(*this, 0, 2, 44100);
6233
63   info->stream = device->machine().sound().stream_alloc(*device, 0, 2, 44100, info, cdda_update);
34   m_audio_playing = 0;
35   m_audio_pause = 0;
36   m_audio_ended_normally = 0;
37   m_audio_lba = 0;
38   m_audio_length = 0;
39   m_audio_samples = 0;
40   m_audio_bptr = 0;
6441
65   device->save_item( NAME(info->audio_playing) );
66   device->save_item( NAME(info->audio_pause) );
67   device->save_item( NAME(info->audio_ended_normally) );
68   device->save_item( NAME(info->audio_lba) );
69   device->save_item( NAME(info->audio_length) );
70   device->save_pointer( NAME(info->audio_cache), CD_MAX_SECTOR_DATA * MAX_SECTORS );
71   device->save_item( NAME(info->audio_samples) );
72   device->save_item( NAME(info->audio_bptr) );
42   save_item( NAME(m_audio_playing) );
43   save_item( NAME(m_audio_pause) );
44   save_item( NAME(m_audio_ended_normally) );
45   save_item( NAME(m_audio_lba) );
46   save_item( NAME(m_audio_length) );
47   save_pointer( NAME(m_audio_cache), CD_MAX_SECTOR_DATA * MAX_SECTORS );
48   save_item( NAME(m_audio_samples) );
49   save_item( NAME(m_audio_bptr) );
7350}
7451
7552
r22814r22815
7855    given CDDA stream
7956-------------------------------------------------*/
8057
81void cdda_set_cdrom(device_t *device, void *file)
58void cdda_device::set_cdrom(void *file)
8259{
83   cdda_info *info = get_safe_token(device);
84   info->disc = (cdrom_file *)file;
60   m_disc = (cdrom_file *)file;
8561}
8662
8763
8864/*-------------------------------------------------
89    cdda_from_cdrom - find the CDDA stream
90    that references the given CD-ROM file
91-------------------------------------------------*/
92
93device_t *cdda_from_cdrom(running_machine &machine, void *file)
94{
95   sound_interface_iterator iter(machine.root_device());
96   for (device_sound_interface *sound = iter.first(); sound != NULL; sound = iter.next())
97      if (sound->device().type() == CDDA)
98      {
99         cdda_info *info = get_safe_token(*sound);
100         if (info->disc == file)
101            return *sound;
102      }
103
104   return NULL;
105}
106
107
108/*-------------------------------------------------
10965    cdda_start_audio - begin playback of a Red
11066    Book audio track
11167-------------------------------------------------*/
11268
113void cdda_start_audio(device_t *device, UINT32 startlba, UINT32 numblocks)
69void cdda_device::start_audio(UINT32 startlba, UINT32 numblocks)
11470{
115   cdda_info *info = get_safe_token(device);
116
117   info->stream->update();
118   info->audio_playing = TRUE;
119   info->audio_pause = FALSE;
120   info->audio_ended_normally = FALSE;
121   info->audio_lba = startlba;
122   info->audio_length = numblocks;
71   m_stream->update();
72   m_audio_playing = TRUE;
73   m_audio_pause = FALSE;
74   m_audio_ended_normally = FALSE;
75   m_audio_lba = startlba;
76   m_audio_length = numblocks;
77   m_audio_samples = 0;
12378}
12479
12580
r22814r22815
12883    audio track
12984-------------------------------------------------*/
13085
131void cdda_stop_audio(device_t *device)
86void cdda_device::stop_audio()
13287{
133   cdda_info *info = get_safe_token(device);
134
135   info->stream->update();
136   info->audio_playing = FALSE;
137   info->audio_ended_normally = TRUE;
88   m_stream->update();
89   m_audio_playing = FALSE;
90   m_audio_ended_normally = TRUE;
13891}
13992
14093
r22814r22815
14396    a Red Book audio track
14497-------------------------------------------------*/
14598
146void cdda_pause_audio(device_t *device, int pause)
99void cdda_device::pause_audio(int pause)
147100{
148   cdda_info *info = get_safe_token(device);
149
150   info->stream->update();
151   info->audio_pause = pause;
101   m_stream->update();
102   m_audio_pause = pause;
152103}
153104
154105
r22814r22815
157108    (physical sector) during Red Book playback
158109-------------------------------------------------*/
159110
160UINT32 cdda_get_audio_lba(device_t *device)
111UINT32 cdda_device::get_audio_lba()
161112{
162   cdda_info *info = get_safe_token(device);
163
164   info->stream->update();
165   return info->audio_lba;
113   m_stream->update();
114   return m_audio_lba;
166115}
167116
168117
r22814r22815
171120    playback status
172121-------------------------------------------------*/
173122
174int cdda_audio_active(device_t *device)
123int cdda_device::audio_active()
175124{
176   cdda_info *info = get_safe_token(device);
177
178   info->stream->update();
179   return info->audio_playing;
125   m_stream->update();
126   return m_audio_playing;
180127}
181128
182129
r22814r22815
185132    playback is paused
186133-------------------------------------------------*/
187134
188int cdda_audio_paused(device_t *device)
135int cdda_device::audio_paused()
189136{
190   cdda_info *info = get_safe_token(device);
191   return info->audio_pause;
137   return m_audio_pause;
192138}
193139
194140
r22814r22815
197143    track reached it's natural end
198144-------------------------------------------------*/
199145
200int cdda_audio_ended(device_t *device)
146int cdda_device::audio_ended()
201147{
202   cdda_info *info = get_safe_token(device);
203   return info->audio_ended_normally;
148   return m_audio_ended_normally;
204149}
205150
206151
r22814r22815
210155    converts it to 2 16-bit 44.1 kHz streams
211156-------------------------------------------------*/
212157
213static void get_audio_data(cdda_info *info, stream_sample_t *bufL, stream_sample_t *bufR, UINT32 samples_wanted)
158void cdda_device::get_audio_data(stream_sample_t *bufL, stream_sample_t *bufR, UINT32 samples_wanted)
214159{
215   int i, sectoread, remaining;
216   INT16 *audio_cache = (INT16 *) info->audio_cache;
160   int i;
161   INT16 *audio_cache = (INT16 *) m_audio_cache;
217162
218   /* if no file, audio not playing, audio paused, or out of disc data,
219      just zero fill */
220   if (!info->disc || !info->audio_playing || info->audio_pause || (!info->audio_length && !info->audio_samples))
163   while (samples_wanted > 0)
221164   {
222      if( info->disc && info->audio_playing && !info->audio_pause && !info->audio_length )
165      /* if no file, audio not playing, audio paused, or out of disc data,
166         just zero fill */
167      if (!m_disc || !m_audio_playing || m_audio_pause || (!m_audio_length && !m_audio_samples))
223168      {
224         info->audio_playing = FALSE;
225         info->audio_ended_normally = TRUE;
169         if( m_disc && m_audio_playing && !m_audio_pause && !m_audio_length )
170         {
171            m_audio_playing = FALSE;
172            m_audio_ended_normally = TRUE;
173         }
174
175         memset(bufL, 0, sizeof(stream_sample_t)*samples_wanted);
176         memset(bufR, 0, sizeof(stream_sample_t)*samples_wanted);
177         return;
226178      }
227179
228      memset(bufL, 0, sizeof(stream_sample_t)*samples_wanted);
229      memset(bufR, 0, sizeof(stream_sample_t)*samples_wanted);
230      return;
231   }
180      int samples = samples_wanted;
181      if (samples > m_audio_samples)
182      {
183         samples = m_audio_samples;
184      }
232185
233   /* if we've got enough samples, just feed 'em out */
234   if (samples_wanted <= info->audio_samples)
235   {
236      for (i = 0; i < samples_wanted; i++)
186      for (i = 0; i < samples; i++)
237187      {
238         *bufL++ = audio_cache[ info->audio_bptr++ ];
239         *bufR++ = audio_cache[ info->audio_bptr++ ];
188         /* CD-DA data on the disc is big-endian */
189         *bufL++ = (INT16) BIG_ENDIANIZE_INT16( audio_cache[ m_audio_bptr ] ); m_audio_bptr++;
190         *bufR++ = (INT16) BIG_ENDIANIZE_INT16( audio_cache[ m_audio_bptr ] ); m_audio_bptr++;
240191      }
241192
242      info->audio_samples -= samples_wanted;
243      return;
244   }
193      samples_wanted -= samples;
194      m_audio_samples -= samples;
245195
246   /* we don't have enough, so first feed what we've got */
247   for (i = 0; i < info->audio_samples; i++)
248   {
249      *bufL++ = audio_cache[ info->audio_bptr++ ];
250      *bufR++ = audio_cache[ info->audio_bptr++ ];
251   }
196      if (m_audio_samples == 0)
197      {
198         int sectors = m_audio_length;
199         if (sectors > MAX_SECTORS)
200         {
201            sectors = MAX_SECTORS;
202         }
252203
253   /* remember how much left for later */
254   remaining = samples_wanted - info->audio_samples;
204         for (i = 0; i < sectors; i++)
205         {
206            cdrom_read_data(m_disc, m_audio_lba, &m_audio_cache[CD_MAX_SECTOR_DATA*i], CD_TRACK_AUDIO);
255207
256   /* reset the buffer and get what we can from the disc */
257   info->audio_samples = 0;
258   if (info->audio_length >= MAX_SECTORS)
259   {
260      sectoread = MAX_SECTORS;
261   }
262   else
263   {
264      sectoread = info->audio_length;
265   }
208            m_audio_lba++;
209         }
266210
267   for (i = 0; i < sectoread; i++)
268   {
269      cdrom_read_data(info->disc, info->audio_lba, &info->audio_cache[CD_MAX_SECTOR_DATA*i], CD_TRACK_AUDIO);
211         m_audio_samples = (CD_MAX_SECTOR_DATA*sectors)/4;
212         m_audio_length -= sectors;
270213
271      info->audio_lba++;
272   }
273
274   info->audio_samples = (CD_MAX_SECTOR_DATA*sectoread)/4;
275   info->audio_length -= sectoread;
276
277   /* CD-DA data on the disc is big-endian, flip if we're not */
278   if (ENDIANNESS_NATIVE == ENDIANNESS_LITTLE)
279   {
280      for( i = 0; i < info->audio_samples * 2; i++ )
281      {
282         audio_cache[ i ] = BIG_ENDIANIZE_INT16( audio_cache[ i ] );
214         /* reset feedout ptr */
215         m_audio_bptr = 0;
283216      }
284217   }
285
286   /* reset feedout ptr */
287   info->audio_bptr = 0;
288
289   /* we've got data, feed it out by calling ourselves recursively */
290   get_audio_data(info, bufL, bufR, remaining);
291218}
292219
293220/*-------------------------------------------------
r22814r22815
295222    for both speakers, used for fade in/out effects
296223-------------------------------------------------*/
297224
298void cdda_set_volume(device_t *device,int volume)
225void cdda_device::set_volume(int volume)
299226{
300   cdda_info *cdda = get_safe_token(device);
301
302   cdda->stream->set_output_gain(0,volume / 100.0);
303   cdda->stream->set_output_gain(1,volume / 100.0);
227   m_stream->set_output_gain(0,volume / 100.0);
228   m_stream->set_output_gain(1,volume / 100.0);
304229}
305230
306231/*-------------------------------------------------
r22814r22815
308233    for either speaker, used for fade in/out effects
309234-------------------------------------------------*/
310235
311void cdda_set_channel_volume(device_t *device, int channel, int volume)
236void cdda_device::set_channel_volume(int channel, int volume)
312237{
313   cdda_info *cdda = get_safe_token(device);
314
315   cdda->stream->set_output_gain(channel,volume / 100.0);
238   m_stream->set_output_gain(channel,volume / 100.0);
316239}
317240
318241
r22814r22815
321244    for either speaker, used for volume control display
322245-------------------------------------------------*/
323246
324INT16 cdda_get_channel_volume(device_t *device, int channel)
247INT16 cdda_device::get_channel_volume(int channel)
325248{
326   cdda_info *cdda = get_safe_token(device);
327
328   return cdda->audio_volume[channel];
249   return m_audio_volume[channel];
329250}
330251
331252const device_type CDDA = &device_creator<cdda_device>;
r22814r22815
334255   : device_t(mconfig, CDDA, "CD/DA", tag, owner, clock),
335256      device_sound_interface(mconfig, *this)
336257{
337   m_token = global_alloc_clear(cdda_info);
338258}
339259
340260//-------------------------------------------------
r22814r22815
346266void cdda_device::device_config_complete()
347267{
348268}
349
350//-------------------------------------------------
351//  device_start - device-specific startup
352//-------------------------------------------------
353
354void cdda_device::device_start()
355{
356   DEVICE_START_NAME( cdda )(this);
357}
358
359//-------------------------------------------------
360//  sound_stream_update - handle a stream update
361//-------------------------------------------------
362
363void cdda_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
364{
365   // should never get here
366   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
367}
trunk/src/emu/sound/cdda.h
r22814r22815
33#ifndef __CDDA_H__
44#define __CDDA_H__
55
6#include "devlegcy.h"
6#include "cdrom.h"
77
8void cdda_set_cdrom(device_t *device, void *file);
9device_t *cdda_from_cdrom(running_machine &machine, void *file);
10
11void cdda_start_audio(device_t *device, UINT32 startlba, UINT32 numblocks);
12void cdda_stop_audio(device_t *device);
13void cdda_pause_audio(device_t *device, int pause);
14void cdda_set_volume(device_t *device, int volume);
15void cdda_set_channel_volume(device_t *device, int channel, int volume);
16INT16 cdda_get_channel_volume(device_t *device, int channel);
17
18UINT32 cdda_get_audio_lba(device_t *device);
19int cdda_audio_active(device_t *device);
20int cdda_audio_paused(device_t *device);
21int cdda_audio_ended(device_t *device);
22
238class cdda_device : public device_t,
249                           public device_sound_interface
2510{
2611public:
2712   cdda_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
28   ~cdda_device() { global_free(m_token); }
2913
30   // access to legacy token
31   void *token() const { assert(m_token != NULL); return m_token; }
14   void set_cdrom(void *file);
15
16   void start_audio(UINT32 startlba, UINT32 numblocks);
17   void stop_audio();
18   void pause_audio(int pause);
19   void set_volume(int volume);
20   void set_channel_volume(int channel, int volume);
21   INT16 get_channel_volume(int channel);
22
23   UINT32 get_audio_lba();
24   int audio_active();
25   int audio_paused();
26   int audio_ended();
27
28   cdrom_file *        m_disc;
29
3230protected:
3331   // device-level overrides
3432   virtual void device_config_complete();
r22814r22815
3634
3735   // sound stream update overrides
3836   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
37
3938private:
39   void get_audio_data(stream_sample_t *bufL, stream_sample_t *bufR, UINT32 samples_wanted);
40
4041   // internal state
41   void *m_token;
42   sound_stream *      m_stream;
43
44   INT8                m_audio_playing, m_audio_pause, m_audio_ended_normally;
45   UINT32              m_audio_lba, m_audio_length;
46
47   UINT8 *             m_audio_cache;
48   UINT32              m_audio_samples;
49   UINT32              m_audio_bptr;
50   INT16               m_audio_volume[2];
4251};
4352
4453extern const device_type CDDA;
trunk/src/emu/machine/stvcd.c
r22814r22815
364364                  cur_track = (start_pos)>>8;
365365                  cd_fad_seek = cdrom_get_track_start(cdrom, cur_track-1);
366366                  cd_stat = CD_STAT_SEEK;
367                  cdda_pause_audio( machine().device( "cdda" ), 0 );
367                  machine().device<cdda_device>("cdda")->pause_audio(0);
368368               }
369369               else
370370               {
r22814r22815
437437         // cdda
438438         if(cdrom_get_track_type(cdrom, cdrom_get_track(cdrom, cd_curfad)) == CD_TRACK_AUDIO)
439439         {
440            cdda_pause_audio( machine().device( "cdda" ), 0 );
441            //cdda_start_audio( machine.device( "cdda" ), cd_curfad, fadstoplay  );
440            machine().device<cdda_device>("cdda")->pause_audio(0);
441            //machine().device<cdda_device>("cdda")->start_audio(cd_curfad, fadstoplay);
442442            //cdda_repeat_count = 0;
443443         }
444444
r22814r22815
464464            if (temp == 0xffffff)
465465            {
466466               cd_stat = CD_STAT_PAUSE;
467               cdda_pause_audio( machine().device( "cdda" ), 1 );
467               machine().device<cdda_device>("cdda")->pause_audio(1);
468468            }
469469            else
470470            {
r22814r22815
480480               cd_stat = CD_STAT_PAUSE;
481481               cur_track = cr2>>8;;
482482               cd_curfad = cdrom_get_track_start(cdrom, cur_track-1);
483               cdda_pause_audio( machine().device( "cdda" ), 1 );
483               machine().device<cdda_device>("cdda")->pause_audio(1);
484484               // (index is cr2 low byte)
485485            }
486486            else // error!
r22814r22815
488488               cd_stat = CD_STAT_STANDBY;
489489               cd_curfad = 0xffffffff;
490490               cur_track = 0xff;
491               cdda_stop_audio( machine().device( "cdda" ) ); //stop any pending CD-DA
491               machine().device<cdda_device>("cdda")->stop_audio(); //stop any pending CD-DA
492492            }
493493         }
494494
r22814r22815
14771477      cdrom = cdrom_open(get_disk_handle(machine(), "cdrom"));
14781478   }
14791479
1480   cdda_set_cdrom( machine().device("cdda"), cdrom );
1480   machine().device<cdda_device>("cdda")->set_cdrom(cdrom);
14811481
14821482   if (cdrom)
14831483   {
r22814r22815
25932593            if(cdrom_get_track_type(cdrom, cdrom_get_track(cdrom, cd_curfad)) != CD_TRACK_AUDIO)
25942594            {
25952595               cd_read_filtered_sector(cd_curfad,&p_ok);
2596               cdda_stop_audio( machine().device( "cdda" ) ); //stop any pending CD-DA
2596               machine().device<cdda_device>("cdda")->stop_audio(); //stop any pending CD-DA
25972597            }
25982598            else
25992599            {
26002600               p_ok = 1; // TODO
2601               cdda_start_audio( machine().device( "cdda" ), cd_curfad, 1  );
2601               machine().device<cdda_device>("cdda")->start_audio(cd_curfad, 1);
26022602            }
26032603
26042604            if(p_ok)
r22814r22815
26812681      cdrom = cdrom_open(get_disk_handle(machine(), "cdrom"));
26822682   }
26832683
2684   cdda_set_cdrom( machine().device("cdda"), cdrom );
2684   machine().device<cdda_device>("cdda")->set_cdrom(cdrom);
26852685
26862686   if (cdrom)
26872687   {
trunk/src/emu/machine/scsicd.c
r22814r22815
77#include "emu.h"
88#include "machine/scsihle.h"
99#include "cdrom.h"
10#include "sound/cdda.h"
1110#include "imagedev/chd_cd.h"
1211#include "scsicd.h"
1312
r22814r22815
2322const device_type SCSICD = &device_creator<scsicd_device>;
2423
2524scsicd_device::scsicd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
26   : scsihle_device(mconfig, SCSICD, "SCSICD", tag, owner, clock, "scsicd", __FILE__)
25   : scsihle_device(mconfig, SCSICD, "SCSICD", tag, owner, clock, "scsicd", __FILE__),
26   m_cdda(*this, "cdda")
2727{
2828}
2929
3030scsicd_device::scsicd_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) :
31   scsihle_device(mconfig, type, name, tag, owner, clock, shortname, source)
31   scsihle_device(mconfig, type, name, tag, owner, clock, shortname, source),
32   m_cdda(*this, "cdda")
3233{
3334}
3435
r22814r22815
8283
8384void scsicd_device::ExecCommand( int *transferLength )
8485{
85   device_t *cdda;
8686   int trk;
8787
8888   switch ( command[0] )
r22814r22815
110110         break;
111111
112112      case 0x1b: // START STOP UNIT
113         cdda = cdda_from_cdrom(machine(), cdrom);
114         if (cdda != NULL)
115         {
116            cdda_stop_audio(cdda);
117         }
113         m_cdda->stop_audio();
118114         SetPhase( SCSI_PHASE_STATUS );
119115         *transferLength = 0;
120116         break;
r22814r22815
146142            cur_subblock = 0;
147143         }
148144
149         cdda = cdda_from_cdrom(machine(), cdrom);
150         if (cdda != NULL)
151         {
152            cdda_stop_audio(cdda);
153         }
145         m_cdda->stop_audio();
154146
155147         SetPhase( SCSI_PHASE_DATAIN );
156148         *transferLength = blocks * bytes_per_sector;
r22814r22815
188180            length = 4;
189181         }
190182
191         cdda = cdda_from_cdrom(machine(), cdrom);
192         if (cdda != NULL)
193         {
194            cdda_stop_audio(cdda);
195         }
183         m_cdda->stop_audio();
196184
197185         SetPhase( SCSI_PHASE_DATAIN );
198186         *transferLength = length;
r22814r22815
219207         if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO)
220208         {
221209            play_err_flag = 0;
222            cdda = cdda_from_cdrom(machine(), cdrom);
223            if (cdda != NULL)
224               cdda_start_audio(cdda, lba, blocks);
210            m_cdda->start_audio(lba, blocks);
225211         }
226212         else
227213         {
r22814r22815
250236
251237         if (blocks && cdrom)
252238         {
253            cdda = cdda_from_cdrom(machine(), cdrom);
254            if (cdda != NULL)
255               cdda_start_audio(cdda, lba, blocks);
239            m_cdda->start_audio(lba, blocks);
256240         }
257241
258242         logerror("SCSICD: PLAY AUDIO T/I: strk %d idx %d etrk %d idx %d frames %d\n", command[4], command[5], command[7], command[8], blocks);
r22814r22815
263247      case 0x4b: // PAUSE/RESUME
264248         if (cdrom)
265249         {
266            cdda = cdda_from_cdrom(machine(), cdrom);
267            if (cdda != NULL)
268               cdda_pause_audio(cdda, (command[8] & 0x01) ^ 0x01);
250            m_cdda->pause_audio((command[8] & 0x01) ^ 0x01);
269251         }
270252
271253         logerror("SCSICD: PAUSE/RESUME: %s\n", command[8]&1 ? "RESUME" : "PAUSE");
r22814r22815
276258      case 0x4e: // STOP
277259         if (cdrom)
278260         {
279            cdda = cdda_from_cdrom(machine(), cdrom);
280            if (cdda != NULL)
281               cdda_stop_audio(cdda);
261            m_cdda->stop_audio();
282262         }
283263
284264         logerror("SCSICD: STOP_PLAY_SCAN\n");
r22814r22815
318298         if (cdrom_get_track_type(cdrom, trk) == CD_TRACK_AUDIO)
319299         {
320300            play_err_flag = 0;
321            cdda = cdda_from_cdrom(machine(), cdrom);
322            if (cdda != NULL)
323               cdda_start_audio(cdda, lba, blocks);
301            m_cdda->start_audio(lba, blocks);
324302         }
325303         else
326304         {
r22814r22815
347325            cur_subblock = 0;
348326         }
349327
350         cdda = cdda_from_cdrom(machine(), cdrom);
351         if (cdda != NULL)
352         {
353            cdda_stop_audio(cdda);
354         }
328         m_cdda->stop_audio();
355329
356330         SetPhase( SCSI_PHASE_DATAIN );
357331         *transferLength = blocks * bytes_per_sector;
r22814r22815
378352   UINT32 last_phys_frame;
379353   UINT32 temp;
380354   UINT8 tmp_buffer[2048];
381   device_t *cdda;
382355
383356   switch ( command[0] )
384357   {
r22814r22815
389362
390363         data[0] = 0x71; // deferred error
391364
392         cdda = cdda_from_cdrom(machine(), cdrom);
393         if (cdda != NULL && cdda_audio_active(cdda))
365         if (m_cdda->audio_active())
394366         {
395367            data[12] = 0x00;
396368            data[13] = 0x11;    // AUDIO PLAY OPERATION IN PROGRESS
r22814r22815
470442         {
471443            case 1: // return current position
472444            {
473               int audio_active;
474445               int msf;
475446
476447               if (!cdrom)
r22814r22815
482453
483454               msf = command[1] & 0x2;
484455
485               cdda = cdda_from_cdrom(machine(), cdrom);
486               audio_active = cdda != NULL && cdda_audio_active(cdda);
456               int audio_active = m_cdda->audio_active();
487457               if (audio_active)
488458               {
489                  if (cdda_audio_paused(cdda))
459                  // if audio is playing, get the latest LBA from the CDROM layer
460                  last_lba = m_cdda->get_audio_lba();
461                  if (m_cdda->audio_paused())
490462                  {
491463                     data[1] = 0x12;     // audio is paused
492464                  }
r22814r22815
497469               }
498470               else
499471               {
500                  if (cdda != NULL && cdda_audio_ended(cdda))
472                  last_lba = 0;
473                  if (m_cdda->audio_ended())
501474                  {
502475                     data[1] = 0x13; // ended successfully
503476                  }
r22814r22815
508481                  }
509482               }
510483
511               // if audio is playing, get the latest LBA from the CDROM layer
512               if (audio_active)
513               {
514                  last_lba = cdda_get_audio_lba(cdda);
515               }
516               else
517               {
518                  last_lba = 0;
519               }
520
521484               data[2] = 0;
522485               data[3] = 12;       // data length
523486               data[4] = 0x01; // sub-channel format code
r22814r22815
752715void scsicd_device::SetDevice( void *_cdrom )
753716{
754717   cdrom = (cdrom_file *)_cdrom;
755   cdda_set_cdrom(subdevice("cdda"), cdrom);
718   m_cdda->set_cdrom(cdrom);
756719}
757720
758721int scsicd_device::GetSectorBytes()
trunk/src/emu/machine/scsicd.h
r22814r22815
88#define _SCSICD_H_
99
1010#include "machine/scsihle.h"
11#include "sound/cdda.h"
1112#include "cdrom.h"
1213
1314class scsicd_device : public scsihle_device
r22814r22815
3334   virtual void device_reset();
3435
3536private:
37   required_device<cdda_device> m_cdda;
3638   UINT32 lba;
3739   UINT32 blocks;
3840   UINT32 last_lba;
trunk/src/emu/machine/matsucd.c
r22814r22815
5151   void (*stch_cb)( running_machine &machine, int level ); /* Status changed callback */
5252   void (*scor_cb)( running_machine &machine, int level ); /* Subcode ready callback */
5353   cdrom_file *cdrom;
54   device_t *cdda;
54   cdda_device *cdda;
5555   emu_timer *frame_timer;
5656};
5757
r22814r22815
6767   memset(&cd, 0, sizeof( matsucd ) );
6868
6969   cd.cdrom = cdrom_device->get_cdrom_file();
70   cd.cdda = cdrom_device->machine().device(cdda_tag);
70   cd.cdda = cdrom_device->machine().device<cdda_device>(cdda_tag);
7171
7272   cd.frame_timer = cdrom_device->machine().scheduler().timer_alloc(FUNC(matsu_subcode_proc));
7373
r22814r22815
137137
138138static void matsucd_cdda_stop( running_machine &machine )
139139{
140   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
141
142   if (cdda != NULL)
140   if (cd.cdda != NULL)
143141   {
144      cdda_stop_audio(cdda);
142      cd.cdda->stop_audio();
145143      cd.frame_timer->reset(  );
146144   }
147145}
148146
149147static void matsucd_cdda_play( running_machine &machine, UINT32 lba, UINT32 num_blocks )
150148{
151   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
152   if (cdda != NULL)
149   if (cd.cdda != NULL)
153150   {
154      cdda_start_audio(cdda, lba, num_blocks);
151      cd.cdda->start_audio(lba, num_blocks);
155152      cd.frame_timer->adjust(attotime::from_hz( 75 ));
156153   }
157154}
158155
159156static void matsucd_cdda_pause( running_machine &machine, int pause )
160157{
161   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
162   if (cdda != NULL)
158   if (cd.cdda != NULL)
163159   {
164      cdda_pause_audio(cdda, pause);
160      cd.cdda->pause_audio(pause);
165161
166162      if ( pause )
167163      {
r22814r22815
176172
177173static UINT8 matsucd_cdda_getstatus( running_machine &machine, UINT32 *lba )
178174{
179   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
180
181175   if ( lba ) *lba = 0;
182176
183   if (cdda != NULL)
177   if (cd.cdda != NULL)
184178   {
185      if (cdda_audio_active(cdda))
179      if (cd.cdda->audio_active())
186180      {
187         if ( lba ) *lba = cdda_get_audio_lba(cdda);
181         if ( lba ) *lba = cd.cdda->get_audio_lba();
188182
189         if (cdda_audio_paused(cdda))
183         if (cd.cdda->audio_paused())
190184         {
191185            return 0x12;    /* audio paused */
192186         }
r22814r22815
195189            return 0x11;    /* audio in progress */
196190         }
197191      }
198      else if (cdda_audio_ended(cdda))
192      else if (cd.cdda->audio_ended())
199193      {
200194         return 0x13;    /* audio ended */
201195      }
r22814r22815
280274
281275static TIMER_CALLBACK(matsu_subcode_proc)
282276{
283   device_t *cdda = cdda_from_cdrom(machine, cd.cdrom);
284
285277   (void)param;
286278
287   if (cdda != NULL)
279   if (cd.cdda != NULL)
288280   {
289281      UINT8   s = matsucd_cdda_getstatus(machine, NULL);
290282      UINT8   newstatus = cd.status;
r22814r22815
364356
365357   if ( cd.cdda_set == 0 )
366358   {
367      // 2009-10, FP: for some reason, cdda_from_cdrom was not returning the correct
368      // CDDA device. Hence, as a temp workaround, I added the cdda to the struct
369      // and its tag is configured in matsucd_init
370359      if ( cd.cdrom )
371         cdda_set_cdrom( cd.cdda, cd.cdrom);
360         cd.cdda->set_cdrom(cd.cdrom);
372361
373362      cd.cdda_set = 1;
374363   }
trunk/src/mess/machine/pce.c
r22814r22815
519519   if ( pce_cd.cdda_status != PCE_CD_CDDA_OFF )
520520   {
521521      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
522      cdda_stop_audio( machine.device( "cdda" ) );
522      machine.device<cdda_device>("cdda")->stop_audio();
523523      pce_cd.end_mark = 0;
524524   }
525525
r22814r22815
589589   if ( pce_cd.cdda_status == PCE_CD_CDDA_PAUSED )
590590   {
591591      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
592      cdda_stop_audio( machine.device( "cdda" ) );
592      machine.device<cdda_device>("cdda")->stop_audio();
593593      pce_cd.end_frame = pce_cd.last_frame;
594594      pce_cd.end_mark = 0;
595595   }
r22814r22815
599599      {
600600         pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
601601         pce_cd.end_frame = pce_cd.last_frame; //get the end of the CD
602         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
602         machine.device<cdda_device>("cdda")->start_audio( pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
603603         pce_cd.cdda_play_mode = (pce_cd.command_buffer[1] & 0x02) ? 2 : 3; // mode 2 sets IRQ at end
604604         pce_cd.end_mark =  (pce_cd.command_buffer[1] & 0x02) ? 1 : 0;
605605      }
r22814r22815
607607      {
608608         pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
609609         pce_cd.end_frame = pce_cd.toc->tracks[ cdrom_get_track(pce_cd.cd, pce_cd.current_frame) + 1 ].logframeofs; //get the end of THIS track
610         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
610         machine.device<cdda_device>("cdda")->start_audio( pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
611611         pce_cd.end_mark = 0;
612612         pce_cd.cdda_play_mode = 3;
613613      }
r22814r22815
666666   {
667667      if ( pce_cd.cdda_status == PCE_CD_CDDA_PAUSED )
668668      {
669         cdda_pause_audio( machine.device( "cdda" ), 0 );
669         machine.device<cdda_device>("cdda")->pause_audio( 0 );
670670      }
671671      else
672672      {
673673         //printf("%08x %08x\n",pce_cd.current_frame,pce_cd.end_frame - pce_cd.current_frame);
674         cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
674         machine.device<cdda_device>("cdda")->start_audio( pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame );
675675         pce_cd.end_mark = 1;
676676      }
677677      pce_cd.cdda_status = PCE_CD_CDDA_PLAYING;
r22814r22815
679679   else
680680   {
681681      pce_cd.cdda_status = PCE_CD_CDDA_OFF;
682      cdda_stop_audio( machine.device( "cdda" ) );
682      machine.device<cdda_device>("cdda")->stop_audio();
683683      pce_cd.end_frame = pce_cd.last_frame;
684684      pce_cd.end_mark = 0;
685685//      assert( NULL == pce_cd_nec_set_audio_stop_position );
r22814r22815
710710   }
711711
712712   pce_cd.cdda_status = PCE_CD_CDDA_PAUSED;
713   pce_cd.current_frame = cdda_get_audio_lba( machine.device( "cdda" ) );
714   cdda_pause_audio( machine.device( "cdda" ), 1 );
713   pce_cd.current_frame = machine.device<cdda_device>("cdda")->get_audio_lba();
714   machine.device<cdda_device>("cdda")->pause_audio( 1 );
715715   pce_cd_reply_status_byte( state, SCSI_STATUS_OK );
716716}
717717
r22814r22815
736736   {
737737   case PCE_CD_CDDA_PAUSED:
738738      pce_cd.data_buffer[0] = 2;
739      frame = cdda_get_audio_lba( machine.device( "cdda" ) );
739      frame = machine.device<cdda_device>("cdda")->get_audio_lba();
740740      break;
741741   case PCE_CD_CDDA_PLAYING:
742742      pce_cd.data_buffer[0] = 0;
743      frame = cdda_get_audio_lba( machine.device( "cdda" ) );
743      frame = machine.device<cdda_device>("cdda")->get_audio_lba();
744744      break;
745745   default:
746746      pce_cd.data_buffer[0] = 3;
r22814r22815
999999         pce_cd.cd_motor_on = 0;
10001000         pce_cd.selected = 0;
10011001         pce_cd.cdda_status = PCE_CD_CDDA_OFF;
1002         cdda_stop_audio( machine.device( "cdda" ) );
1002         machine.device<cdda_device>("cdda")->stop_audio();
10031003         pce_cd.adpcm_dma_timer->adjust(attotime::never); // stop ADPCM DMA here
10041004      }
10051005      pce_cd.scsi_last_RST = pce_cd.scsi_RST;
r22814r22815
10641064   }
10651065
10661066   /* FIXME: presumably CD-DA needs an irq interface for this */
1067   if(cdda_audio_ended(machine.device("cdda")) && pce_cd.end_mark == 1)
1067   if(machine.device<cdda_device>("cdda")->audio_ended() && pce_cd.end_mark == 1)
10681068   {
10691069      switch(pce_cd.cdda_play_mode & 3)
10701070      {
1071         case 1: cdda_start_audio( machine.device( "cdda" ), pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame ); pce_cd.end_mark = 1; break; //play with repeat
1071         case 1: machine.device<cdda_device>("cdda")->start_audio( pce_cd.current_frame, pce_cd.end_frame - pce_cd.current_frame ); pce_cd.end_mark = 1; break; //play with repeat
10721072         case 2: pce_cd_set_irq_line( machine, PCE_CD_IRQ_TRANSFER_DONE, ASSERT_LINE ); pce_cd.end_mark = 0; break; //irq when finished
10731073         case 3: pce_cd.end_mark = 0; break; //play without repeat
10741074      }
r22814r22815
11781178      if ( pce_cd.cd )
11791179      {
11801180         pce_cd.toc = cdrom_get_toc( pce_cd.cd );
1181         cdda_set_cdrom( machine.device("cdda"), pce_cd.cd );
1181         machine.device<cdda_device>("cdda")->set_cdrom( pce_cd.cd );
11821182         pce_cd.last_frame = cdrom_get_track_start( pce_cd.cd, cdrom_get_last_track( pce_cd.cd ) - 1 );
11831183         pce_cd.last_frame += pce_cd.toc->tracks[ cdrom_get_last_track( pce_cd.cd ) - 1 ].frames;
11841184         pce_cd.end_frame = pce_cd.last_frame;
r22814r22815
12341234   if(pce_cd.cdda_volume <= 0)
12351235   {
12361236      pce_cd.cdda_volume = 0.0;
1237      cdda_set_volume(machine().device("cdda"), 0.0);
1237      machine().device<cdda_device>("cdda")->set_volume(0.0);
12381238      pce_cd.cdda_fadeout_timer->adjust(attotime::never);
12391239   }
12401240   else
12411241   {
1242      cdda_set_volume(machine().device("cdda"), pce_cd.cdda_volume);
1242      machine().device<cdda_device>("cdda")->set_volume(pce_cd.cdda_volume);
12431243      pce_cd.cdda_fadeout_timer->adjust(attotime::from_usec(param), param);
12441244   }
12451245}
r22814r22815
12521252   if(pce_cd.cdda_volume >= 100.0)
12531253   {
12541254      pce_cd.cdda_volume = 100.0;
1255      cdda_set_volume(machine().device("cdda"), 100.0);
1255      machine().device<cdda_device>("cdda")->set_volume(100.0);
12561256      pce_cd.cdda_fadein_timer->adjust(attotime::never);
12571257   }
12581258   else
12591259   {
1260      cdda_set_volume(machine().device("cdda"), pce_cd.cdda_volume);
1260      machine().device<cdda_device>("cdda")->set_volume(pce_cd.cdda_volume);
12611261      pce_cd.cdda_fadein_timer->adjust(attotime::from_usec(param), param);
12621262   }
12631263}
r22814r22815
15991599   case 0x04:  /* CD reset */
16001600      break;
16011601   case 0x05:  /* Convert PCM data / PCM data */
1602      data = cdda_get_channel_volume(machine().device( "cdda" ),(pce_cd.regs[0x03] & 2) ? 0 : 1) & 0xff;
1602      data = machine().device<cdda_device>("cdda")->get_channel_volume((pce_cd.regs[0x03] & 2) ? 0 : 1) & 0xff;
16031603      break;
16041604   case 0x06:  /* PCM data */
1605      data = cdda_get_channel_volume(machine().device( "cdda" ),(pce_cd.regs[0x03] & 2) ? 0 : 1) >> 8;
1605      data = machine().device<cdda_device>("cdda")->get_channel_volume((pce_cd.regs[0x03] & 2) ? 0 : 1) >> 8;
16061606      break;
16071607   case 0x07:  /* BRAM unlock / CD status */
16081608      data = ( pce_cd.bram_locked ? ( data & 0x7F ) : ( data | 0x80 ) );
trunk/src/mess/includes/fmtowns.h
r22814r22815
9595   device_t* m_pit;
9696   ram_device* m_messram;
9797   cdrom_image_device* m_cdrom;
98   device_t* m_cdda;
98   cdda_device* m_cdda;
9999   required_device<speaker_sound_device> m_speaker;
100100   class fmscsi_device* m_scsi;
101101   required_device<ram_device> m_ram;
trunk/src/mess/drivers/fmtowns.c
r22814r22815
13811381UINT8 towns_state::towns_cd_get_track()
13821382{
13831383   cdrom_image_device* cdrom = m_cdrom;
1384   device_t* cdda = m_cdda;
1385   UINT32 lba = cdda_get_audio_lba(cdda);
1384   UINT32 lba = m_cdda->get_audio_lba();
13861385   UINT8 track;
13871386
13881387   for(track=1;track<99;track++)
r22814r22815
15661565   m_towns_cd.cdda_current = msf_to_lbafm(lba1);
15671566   m_towns_cd.cdda_length = msf_to_lbafm(lba2) - m_towns_cd.cdda_current;
15681567
1569   cdda_set_cdrom(m_cdda,device->get_cdrom_file());
1570   cdda_start_audio(m_cdda,m_towns_cd.cdda_current,m_towns_cd.cdda_length);
1568   m_cdda->set_cdrom(device->get_cdrom_file());
1569   m_cdda->start_audio(m_towns_cd.cdda_current,m_towns_cd.cdda_length);
15711570   logerror("CD: CD-DA start from LBA:%i length:%i\n",m_towns_cd.cdda_current,m_towns_cd.cdda_length);
15721571   if(m_towns_cd.command & 0x20)
15731572   {
r22814r22815
16361635            if(m_towns_cd.command & 0x20)
16371636            {
16381637               m_towns_cd.extra_status = 0;
1639               if(cdda_audio_active(m_cdda) && !cdda_audio_paused(m_cdda))
1638               if(m_cdda->audio_active() && !m_cdda->audio_paused())
16401639                  towns_cd_set_status(0x00,0x03,0x00,0x00);
16411640               else
16421641                  towns_cd_set_status(0x00,0x01,0x00,0x00);
r22814r22815
16571656               m_towns_cd.extra_status = 1;
16581657               towns_cd_set_status(0x00,0x00,0x00,0x00);
16591658            }
1660            cdda_pause_audio(m_cdda,1);
1659            m_cdda->pause_audio(1);
16611660            logerror("CD: Command 0x84: STOP CD-DA\n");
16621661            break;
16631662         case 0x85:   // Stop CD audio track (difference from 0x84?)
r22814r22815
16661665               m_towns_cd.extra_status = 1;
16671666               towns_cd_set_status(0x00,0x00,0x00,0x00);
16681667            }
1669            cdda_pause_audio(m_cdda,1);
1668            m_cdda->pause_audio(1);
16701669            logerror("CD: Command 0x85: STOP CD-DA\n");
16711670            break;
16721671         case 0x87:  // Resume CD-DA playback
r22814r22815
16751674               m_towns_cd.extra_status = 1;
16761675               towns_cd_set_status(0x00,0x03,0x00,0x00);
16771676            }
1678            cdda_pause_audio(m_cdda,0);
1677            m_cdda->pause_audio(0);
16791678            logerror("CD: Command 0x87: RESUME CD-DA\n");
16801679            break;
16811680         default:
r22814r22815
17921791                           m_towns_cd.extra_status++;
17931792                           break;
17941793                        case 2:  // st0/1/2 = MSF from beginning of current track
1795                           addr = cdda_get_audio_lba(m_cdda);
1794                           addr = m_cdda->get_audio_lba();
17961795                           addr = lba_to_msf(addr - m_towns_cd.cdda_current);
17971796                           towns_cd_set_status(0x19,
17981797                              (addr & 0xff0000) >> 16,(addr & 0x00ff00) >> 8,addr & 0x0000ff);
17991798                           m_towns_cd.extra_status++;
18001799                           break;
18011800                        case 3:  // st1/2 = current MSF
1802                           addr = cdda_get_audio_lba(m_cdda);
1801                           addr = m_cdda->get_audio_lba();
18031802                           addr = lba_to_msf(addr);  // this data is incorrect, but will do until exact meaning is found
18041803                           towns_cd_set_status(0x19,
18051804                              0x00,(addr & 0xff0000) >> 16,(addr & 0x00ff00) >> 8);
18061805                           m_towns_cd.extra_status++;
18071806                           break;
18081807                        case 4:
1809                           addr = cdda_get_audio_lba(m_cdda);
1808                           addr = m_cdda->get_audio_lba();
18101809                           addr = lba_to_msf(addr);  // this data is incorrect, but will do until exact meaning is found
18111810                           towns_cd_set_status(0x20,
18121811                              addr & 0x0000ff,0x00,0x00);
r22814r22815
20302029   case 2:
20312030      m_towns_volume[m_towns_volume_select] = data;
20322031      if(m_towns_volume_select == 4)
2033         cdda_set_channel_volume(m_cdda,0,100.0 * (data / 64.0f));
2032         m_cdda->set_channel_volume(0,100.0 * (data / 64.0f));
20342033      if(m_towns_volume_select == 5)
2035         cdda_set_channel_volume(m_cdda,1,100.0 * (data / 64.0f));
2034         m_cdda->set_channel_volume(1,100.0 * (data / 64.0f));
20362035      break;
20372036   case 3:  // select channel
20382037      if(data < 8)
r22814r22815
26162615   m_pit = machine().device("pit");
26172616   m_messram = m_ram;
26182617   m_cdrom = machine().device<cdrom_image_device>("cdrom");
2619   m_cdda = machine().device("cdda");
2618   m_cdda = machine().device<cdda_device>("cdda");
26202619   m_scsi = machine().device<fmscsi_device>("scsi:fm");
26212620   m_ftimer = 0x00;
26222621   m_freerun_timer = 0x00;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team