Previous 199869 Revisions Next

r24582 Tuesday 30th July, 2013 at 17:09:46 UTC by Tafoid
Modernized MultiPCM, mjkjidai, renegage, ninjaw_subwoofer devices  [Osso]

Multisession bug fix for exidy440 audio from Osso (nw)
[src/emu/sound]multipcm.c multipcm.h
[src/mame/audio]exidy440.c
[src/mame/drivers]mjkjidai.c model1.c model2.c ninjaw.c renegade.c segas32.c
[src/mame/includes]mjkjidai.h model1.h model2.h renegade.h segas32.h

trunk/src/emu/sound/multipcm.c
r24581r24582
3333
3434#include "emu.h"
3535#include "multipcm.h"
36#include "devlegcy.h"
3736
3837//????
3938#define MULTIPCM_CLOCKDIV       (180.0)
4039
41struct Sample_t
42{
43   unsigned int Start;
44   unsigned int Loop;
45   unsigned int End;
46   unsigned char AR,DR1,DR2,DL,RR;
47   unsigned char KRS;
48   unsigned char LFOVIB;
49   unsigned char AM;
50};
51
52enum STATE {ATTACK,DECAY1,DECAY2,RELEASE};
5340ALLOW_SAVE_TYPE(STATE); // allow save_item on a non-fundamental type
54struct EG_t
55{
56   int volume; //
57   STATE state;
58   int step;
59   //step vals
60   int AR;     //Attack
61   int D1R;    //Decay1
62   int D2R;    //Decay2
63   int RR;     //Release
64   int DL;     //Decay level
65};
6641
67struct LFO_t
68{
69   unsigned short phase;
70   UINT32 phase_step;
71   int *table;
72   int *scale;
73};
74
75
76struct SLOT
77{
78   unsigned char Num;
79   unsigned char Regs[8];
80   int Playing;
81   Sample_t *Sample;
82   unsigned int Base;
83   unsigned int offset;
84   unsigned int step;
85   unsigned int Pan,TL;
86   unsigned int DstTL;
87   int TLStep;
88   signed int Prev;
89   EG_t EG;
90   LFO_t PLFO; //Phase lfo
91   LFO_t ALFO; //AM lfo
92};
93
94struct MultiPCM
95{
96   sound_stream * stream;
97   Sample_t Samples[0x200];        //Max 512 samples
98   SLOT Slots[28];
99   unsigned int CurSlot;
100   unsigned int Address;
101   unsigned int BankR,BankL;
102   float Rate;
103   INT8 *ROM;
104   //I include these in the chip because they depend on the chip clock
105   unsigned int ARStep[0x40],DRStep[0x40]; //Envelope step table
106   unsigned int FNS_Table[0x400];      //Frequency step table
107};
108
109
11042static signed int LPANTABLE[0x800],RPANTABLE[0x800];
11143
11244#define FIX(v)  ((UINT32) ((float) (1<<SHIFT)*(v)))
r24581r24582
12658#define MULTIPCM_RATE   44100.0
12759
12860
129INLINE MultiPCM *get_safe_token(device_t *device)
130{
131   assert(device != NULL);
132   assert(device->type() == MULTIPCM);
133   return (MultiPCM *)downcast<multipcm_device *>(device)->token();
134}
13561
13662
13763/*******************************
r24581r24582
202128   return Steps[r];
203129}
204130
205static void EG_Calc(MultiPCM *ptChip,SLOT *slot)
131void multipcm_device::EG_Calc(SLOT *slot)
206132{
207133   int octave=((slot->Regs[3]>>4)-1)&0xf;
208134   int rate;
r24581r24582
212138   else
213139      rate=0;
214140
215   slot->EG.AR=Get_RATE(ptChip->ARStep,rate,slot->Sample->AR);
216   slot->EG.D1R=Get_RATE(ptChip->DRStep,rate,slot->Sample->DR1);
217   slot->EG.D2R=Get_RATE(ptChip->DRStep,rate,slot->Sample->DR2);
218   slot->EG.RR=Get_RATE(ptChip->DRStep,rate,slot->Sample->RR);
141   slot->EG.AR=Get_RATE(m_ARStep,rate,slot->Sample->AR);
142   slot->EG.D1R=Get_RATE(m_DRStep,rate,slot->Sample->DR1);
143   slot->EG.D2R=Get_RATE(m_DRStep,rate,slot->Sample->DR2);
144   slot->EG.RR=Get_RATE(m_DRStep,rate,slot->Sample->RR);
219145   slot->EG.DL=0xf-slot->Sample->DL;
220146
221147}
r24581r24582
302228   return p<<(SHIFT-LFO_SHIFT);
303229}
304230
305static void LFO_ComputeStep(MultiPCM *ptChip,LFO_t *LFO,UINT32 LFOF,UINT32 LFOS,int ALFO)
231void multipcm_device::LFO_ComputeStep(LFO_t *LFO,UINT32 LFOF,UINT32 LFOS,int ALFO)
306232{
307   float step=(float) LFOFreq[LFOF]*256.0/(float) ptChip->Rate;
233   float step=(float) LFOFreq[LFOF]*256.0/(float) m_Rate;
308234   LFO->phase_step=(unsigned int) ((float) (1<<LFO_SHIFT)*step);
309235   if(ALFO)
310236   {
r24581r24582
320246
321247
322248
323static void WriteSlot(MultiPCM *ptChip,SLOT *slot,int reg,unsigned char data)
249void multipcm_device::WriteSlot(SLOT *slot,int reg,unsigned char data)
324250{
325251   slot->Regs[reg]=data;
326252
r24581r24582
333259         //according to YMF278 sample write causes some base params written to the regs (envelope+lfos)
334260         //the game should never change the sample while playing.
335261         {
336            Sample_t *Sample=ptChip->Samples+slot->Regs[1];
337            WriteSlot(ptChip,slot,6,Sample->LFOVIB);
338            WriteSlot(ptChip,slot,7,Sample->AM);
262            Sample_t *Sample=m_Samples+slot->Regs[1];
263            WriteSlot(slot,6,Sample->LFOVIB);
264            WriteSlot(slot,7,Sample->AM);
339265         }
340266         break;
341267      case 2: //Pitch
r24581r24582
343269         {
344270            unsigned int oct=((slot->Regs[3]>>4)-1)&0xf;
345271            unsigned int pitch=((slot->Regs[3]&0xf)<<6)|(slot->Regs[2]>>2);
346            pitch=ptChip->FNS_Table[pitch];
272            pitch=m_FNS_Table[pitch];
347273            if(oct&0x8)
348274               pitch>>=(16-oct);
349275            else
350276               pitch<<=oct;
351            slot->step=pitch/ptChip->Rate;
277            slot->step=pitch/m_Rate;
352278         }
353279         break;
354280      case 4:     //KeyOn/Off (and more?)
355281         {
356282            if(data&0x80)       //KeyOn
357283            {
358               slot->Sample=ptChip->Samples+slot->Regs[1];
284               slot->Sample=m_Samples+slot->Regs[1];
359285               slot->Playing=1;
360286               slot->Base=slot->Sample->Start;
361287               slot->offset=0;
362288               slot->Prev=0;
363289               slot->TL=slot->DstTL<<SHIFT;
364290
365               EG_Calc(ptChip,slot);
291               EG_Calc(slot);
366292               slot->EG.state=ATTACK;
367293               slot->EG.volume=0;
368294
369295               if(slot->Base>=0x100000)
370296               {
371297                  if(slot->Pan&8)
372                     slot->Base=(slot->Base&0xfffff)|(ptChip->BankL);
298                     slot->Base=(slot->Base&0xfffff)|(m_BankL);
373299                  else
374                     slot->Base=(slot->Base&0xfffff)|(ptChip->BankR);
300                     slot->Base=(slot->Base&0xfffff)|(m_BankR);
375301               }
376302
377303            }
r24581r24582
405331         {
406332            if(data)
407333            {
408               LFO_ComputeStep(ptChip,&(slot->PLFO),(slot->Regs[6]>>3)&7,slot->Regs[6]&7,0);
409               LFO_ComputeStep(ptChip,&(slot->ALFO),(slot->Regs[6]>>3)&7,slot->Regs[7]&7,1);
334               LFO_ComputeStep(&(slot->PLFO),(slot->Regs[6]>>3)&7,slot->Regs[6]&7,0);
335               LFO_ComputeStep(&(slot->ALFO),(slot->Regs[6]>>3)&7,slot->Regs[7]&7,1);
410336            }
411337         }
412338         break;
r24581r24582
414340         {
415341            if(data)
416342            {
417               LFO_ComputeStep(ptChip,&(slot->PLFO),(slot->Regs[6]>>3)&7,slot->Regs[6]&7,0);
418               LFO_ComputeStep(ptChip,&(slot->ALFO),(slot->Regs[6]>>3)&7,slot->Regs[7]&7,1);
343               LFO_ComputeStep(&(slot->PLFO),(slot->Regs[6]>>3)&7,slot->Regs[6]&7,0);
344               LFO_ComputeStep(&(slot->ALFO),(slot->Regs[6]>>3)&7,slot->Regs[7]&7,1);
419345            }
420346         }
421347         break;
422348   }
423349}
424350
425static STREAM_UPDATE( MultiPCM_update )
351READ8_MEMBER( multipcm_device::read )
426352{
427   MultiPCM *ptChip = (MultiPCM *)param;
428   stream_sample_t  *datap[2];
429   int i,sl;
353   return 0;
354}
430355
431   datap[0] = outputs[0];
432   datap[1] = outputs[1];
433356
434   memset(datap[0], 0, sizeof(*datap[0])*samples);
435   memset(datap[1], 0, sizeof(*datap[1])*samples);
436
437
438   for(i=0;i<samples;++i)
357WRITE8_MEMBER( multipcm_device::write )
358{
359   switch(offset)
439360   {
440      signed int smpl=0;
441      signed int smpr=0;
442      for(sl=0;sl<28;++sl)
443      {
444         SLOT *slot=ptChip->Slots+sl;
445         if(slot->Playing)
446         {
447            unsigned int vol=(slot->TL>>SHIFT)|(slot->Pan<<7);
448            unsigned int adr=slot->offset>>SHIFT;
449            signed int sample;
450            unsigned int step=slot->step;
451            signed int csample=(signed short) (ptChip->ROM[slot->Base+adr]<<8);
452            signed int fpart=slot->offset&((1<<SHIFT)-1);
453            sample=(csample*fpart+slot->Prev*((1<<SHIFT)-fpart))>>SHIFT;
361      case 0:     //Data write
362         WriteSlot(m_Slots+m_CurSlot,m_Address,data);
363         break;
364      case 1:
365         m_CurSlot=val2chan[data&0x1f];
366         break;
454367
455            if(slot->Regs[6]&7) //Vibrato enabled
456            {
457               step=step*PLFO_Step(&(slot->PLFO));
458               step>>=SHIFT;
459            }
368      case 2:
369         m_Address=(data>7)?7:data;
370         break;
371   }
372}
460373
461            slot->offset+=step;
462            if(slot->offset>=(slot->Sample->End<<SHIFT))
463            {
464               slot->offset=slot->Sample->Loop<<SHIFT;
465            }
466            if(adr^(slot->offset>>SHIFT))
467            {
468               slot->Prev=csample;
469            }
374/* MAME/M1 access functions */
470375
471            if((slot->TL>>SHIFT)!=slot->DstTL)
472               slot->TL+=slot->TLStep;
376void multipcm_device::set_bank(UINT32 leftoffs, UINT32 rightoffs)
377{
378   m_BankL = leftoffs;
379   m_BankR = rightoffs;
380}
473381
474            if(slot->Regs[7]&7) //Tremolo enabled
475            {
476               sample=sample*ALFO_Step(&(slot->ALFO));
477               sample>>=SHIFT;
478            }
382const device_type MULTIPCM = &device_creator<multipcm_device>;
479383
480            sample=(sample*EG_Update(slot))>>10;
481
482            smpl+=(LPANTABLE[vol]*sample)>>SHIFT;
483            smpr+=(RPANTABLE[vol]*sample)>>SHIFT;
484         }
485      }
486#define ICLIP16(x) (x<-32768)?-32768:((x>32767)?32767:x)
487      datap[0][i]=ICLIP16(smpl);
488      datap[1][i]=ICLIP16(smpr);
489   }
384multipcm_device::multipcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
385   : device_t(mconfig, MULTIPCM, "Sega/Yamaha 315-5560", tag, owner, clock, "multipcm", __FILE__),
386      device_sound_interface(mconfig, *this),
387      m_stream(NULL),
388      //m_Samples(0x200),
389      //m_Slots[28],
390      m_CurSlot(0),
391      m_Address(0),
392      m_BankR(0),
393      m_BankL(0),
394      m_Rate(0),
395      m_ROM(NULL)
396      //m_ARStep(0),
397      //m_DRStep(0),
398      //m_FNS_Table(0)
399{
490400}
491401
492READ8_DEVICE_HANDLER( multipcm_r )
402//-------------------------------------------------
403//  device_config_complete - perform any
404//  operations now that the configuration is
405//  complete
406//-------------------------------------------------
407
408void multipcm_device::device_config_complete()
493409{
494//  MultiPCM *ptChip = get_safe_token(device);
495   return 0;
496410}
497411
498static DEVICE_START( multipcm )
412//-------------------------------------------------
413//  device_start - device-specific startup
414//-------------------------------------------------
415
416void multipcm_device::device_start()
499417{
500   MultiPCM *ptChip = get_safe_token(device);
501   int i;
418      int i;
502419
503   ptChip->ROM=*device->region();
504   ptChip->Rate=(float) device->clock() / MULTIPCM_CLOCKDIV;
420   m_ROM=*region();
421   m_Rate=(float) clock() / MULTIPCM_CLOCKDIV;
505422
506   ptChip->stream = device->machine().sound().stream_alloc(*device, 0, 2, ptChip->Rate, ptChip, MultiPCM_update);
423   m_stream = machine().sound().stream_alloc(*this, 0, 2, m_Rate, this);
507424
508425   //Volume+pan table
509426   for(i=0;i<0x800;++i)
r24581r24582
561478   //Pitch steps
562479   for(i=0;i<0x400;++i)
563480   {
564      float fcent=ptChip->Rate*(1024.0+(float) i)/1024.0;
565      ptChip->FNS_Table[i]=(unsigned int ) ((float) (1<<SHIFT) *fcent);
481      float fcent=m_Rate*(1024.0+(float) i)/1024.0;
482      m_FNS_Table[i]=(unsigned int ) ((float) (1<<SHIFT) *fcent);
566483   }
567484
568485   //Envelope steps
569486   for(i=0;i<0x40;++i)
570487   {
571488      //Times are based on 44100 clock, adjust to real chip clock
572      ptChip->ARStep[i]=(float) (0x400<<EG_SHIFT)/(BaseTimes[i]*44100.0/(1000.0));
573      ptChip->DRStep[i]=(float) (0x400<<EG_SHIFT)/(BaseTimes[i]*AR2DR*44100.0/(1000.0));
489      m_ARStep[i]=(float) (0x400<<EG_SHIFT)/(BaseTimes[i]*44100.0/(1000.0));
490      m_DRStep[i]=(float) (0x400<<EG_SHIFT)/(BaseTimes[i]*AR2DR*44100.0/(1000.0));
574491   }
575   ptChip->ARStep[0]=ptChip->ARStep[1]=ptChip->ARStep[2]=ptChip->ARStep[3]=0;
576   ptChip->ARStep[0x3f]=0x400<<EG_SHIFT;
577   ptChip->DRStep[0]=ptChip->DRStep[1]=ptChip->DRStep[2]=ptChip->DRStep[3]=0;
492   m_ARStep[0]=m_ARStep[1]=m_ARStep[2]=m_ARStep[3]=0;
493   m_ARStep[0x3f]=0x400<<EG_SHIFT;
494   m_DRStep[0]=m_DRStep[1]=m_DRStep[2]=m_DRStep[3]=0;
578495
579496   //TL Interpolation steps
580497   //lower
r24581r24582
592509
593510   for(i=0;i<512;++i)
594511   {
595      UINT8 *ptSample=(UINT8 *) ptChip->ROM+i*12;
596      ptChip->Samples[i].Start=(ptSample[0]<<16)|(ptSample[1]<<8)|(ptSample[2]<<0);
597      ptChip->Samples[i].Loop=(ptSample[3]<<8)|(ptSample[4]<<0);
598      ptChip->Samples[i].End=0xffff-((ptSample[5]<<8)|(ptSample[6]<<0));
599      ptChip->Samples[i].LFOVIB=ptSample[7];
600      ptChip->Samples[i].DR1=ptSample[8]&0xf;
601      ptChip->Samples[i].AR=(ptSample[8]>>4)&0xf;
602      ptChip->Samples[i].DR2=ptSample[9]&0xf;
603      ptChip->Samples[i].DL=(ptSample[9]>>4)&0xf;
604      ptChip->Samples[i].RR=ptSample[10]&0xf;
605      ptChip->Samples[i].KRS=(ptSample[10]>>4)&0xf;
606      ptChip->Samples[i].AM=ptSample[11];
512      UINT8 *ptSample=(UINT8 *) m_ROM+i*12;
513      m_Samples[i].Start=(ptSample[0]<<16)|(ptSample[1]<<8)|(ptSample[2]<<0);
514      m_Samples[i].Loop=(ptSample[3]<<8)|(ptSample[4]<<0);
515      m_Samples[i].End=0xffff-((ptSample[5]<<8)|(ptSample[6]<<0));
516      m_Samples[i].LFOVIB=ptSample[7];
517      m_Samples[i].DR1=ptSample[8]&0xf;
518      m_Samples[i].AR=(ptSample[8]>>4)&0xf;
519      m_Samples[i].DR2=ptSample[9]&0xf;
520      m_Samples[i].DL=(ptSample[9]>>4)&0xf;
521      m_Samples[i].RR=ptSample[10]&0xf;
522      m_Samples[i].KRS=(ptSample[10]>>4)&0xf;
523      m_Samples[i].AM=ptSample[11];
607524   }
608525
609   device->save_item(NAME(ptChip->CurSlot));
610   device->save_item(NAME(ptChip->Address));
611   device->save_item(NAME(ptChip->BankL));
612   device->save_item(NAME(ptChip->BankR));
526   save_item(NAME(m_CurSlot));
527   save_item(NAME(m_Address));
528   save_item(NAME(m_BankL));
529   save_item(NAME(m_BankR));
613530
614531   for(i=0;i<28;++i)
615532   {
616      ptChip->Slots[i].Num=i;
617      ptChip->Slots[i].Playing=0;
533      m_Slots[i].Num=i;
534      m_Slots[i].Playing=0;
618535
619      device->save_item(NAME(ptChip->Slots[i].Num), i);
620      device->save_item(NAME(ptChip->Slots[i].Regs), i);
621      device->save_item(NAME(ptChip->Slots[i].Playing), i);
622      device->save_item(NAME(ptChip->Slots[i].Base), i);
623      device->save_item(NAME(ptChip->Slots[i].offset), i);
624      device->save_item(NAME(ptChip->Slots[i].step), i);
625      device->save_item(NAME(ptChip->Slots[i].Pan), i);
626      device->save_item(NAME(ptChip->Slots[i].TL), i);
627      device->save_item(NAME(ptChip->Slots[i].DstTL), i);
628      device->save_item(NAME(ptChip->Slots[i].TLStep), i);
629      device->save_item(NAME(ptChip->Slots[i].Prev), i);
630      device->save_item(NAME(ptChip->Slots[i].EG.volume), i);
631      device->save_item(NAME(ptChip->Slots[i].EG.state), i);
632      device->save_item(NAME(ptChip->Slots[i].EG.step), i);
633      device->save_item(NAME(ptChip->Slots[i].EG.AR), i);
634      device->save_item(NAME(ptChip->Slots[i].EG.D1R), i);
635      device->save_item(NAME(ptChip->Slots[i].EG.D2R), i);
636      device->save_item(NAME(ptChip->Slots[i].EG.RR), i);
637      device->save_item(NAME(ptChip->Slots[i].EG.DL), i);
638      device->save_item(NAME(ptChip->Slots[i].PLFO.phase), i);
639      device->save_item(NAME(ptChip->Slots[i].PLFO.phase_step), i);
640      device->save_item(NAME(ptChip->Slots[i].ALFO.phase), i);
641      device->save_item(NAME(ptChip->Slots[i].ALFO.phase_step), i);
536      save_item(NAME(m_Slots[i].Num), i);
537      save_item(NAME(m_Slots[i].Regs), i);
538      save_item(NAME(m_Slots[i].Playing), i);
539      save_item(NAME(m_Slots[i].Base), i);
540      save_item(NAME(m_Slots[i].offset), i);
541      save_item(NAME(m_Slots[i].step), i);
542      save_item(NAME(m_Slots[i].Pan), i);
543      save_item(NAME(m_Slots[i].TL), i);
544      save_item(NAME(m_Slots[i].DstTL), i);
545      save_item(NAME(m_Slots[i].TLStep), i);
546      save_item(NAME(m_Slots[i].Prev), i);
547      save_item(NAME(m_Slots[i].EG.volume), i);
548      save_item(NAME(m_Slots[i].EG.state), i);
549      save_item(NAME(m_Slots[i].EG.step), i);
550      save_item(NAME(m_Slots[i].EG.AR), i);
551      save_item(NAME(m_Slots[i].EG.D1R), i);
552      save_item(NAME(m_Slots[i].EG.D2R), i);
553      save_item(NAME(m_Slots[i].EG.RR), i);
554      save_item(NAME(m_Slots[i].EG.DL), i);
555      save_item(NAME(m_Slots[i].PLFO.phase), i);
556      save_item(NAME(m_Slots[i].PLFO.phase_step), i);
557      save_item(NAME(m_Slots[i].ALFO.phase), i);
558      save_item(NAME(m_Slots[i].ALFO.phase_step), i);
642559   }
643560
644561   LFO_Init();
645562}
646563
564//-------------------------------------------------
565//  sound_stream_update - handle a stream update
566//-------------------------------------------------
647567
648WRITE8_DEVICE_HANDLER( multipcm_w )
568void multipcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
649569{
650   MultiPCM *ptChip = get_safe_token(device);
651   switch(offset)
652   {
653      case 0:     //Data write
654         WriteSlot(ptChip,ptChip->Slots+ptChip->CurSlot,ptChip->Address,data);
655         break;
656      case 1:
657         ptChip->CurSlot=val2chan[data&0x1f];
658         break;
570   stream_sample_t  *datap[2];
571   int i,sl;
659572
660      case 2:
661         ptChip->Address=(data>7)?7:data;
662         break;
663   }
664}
573   datap[0] = outputs[0];
574   datap[1] = outputs[1];
665575
666/* MAME/M1 access functions */
576   memset(datap[0], 0, sizeof(*datap[0])*samples);
577   memset(datap[1], 0, sizeof(*datap[1])*samples);
667578
668void multipcm_set_bank(device_t *device, UINT32 leftoffs, UINT32 rightoffs)
669{
670   MultiPCM *ptChip = get_safe_token(device);
671   ptChip->BankL = leftoffs;
672   ptChip->BankR = rightoffs;
673}
674579
580   for(i=0;i<samples;++i)
581   {
582      signed int smpl=0;
583      signed int smpr=0;
584      for(sl=0;sl<28;++sl)
585      {
586         SLOT *slot=m_Slots+sl;
587         if(slot->Playing)
588         {
589            unsigned int vol=(slot->TL>>SHIFT)|(slot->Pan<<7);
590            unsigned int adr=slot->offset>>SHIFT;
591            signed int sample;
592            unsigned int step=slot->step;
593            signed int csample=(signed short) (m_ROM[slot->Base+adr]<<8);
594            signed int fpart=slot->offset&((1<<SHIFT)-1);
595            sample=(csample*fpart+slot->Prev*((1<<SHIFT)-fpart))>>SHIFT;
675596
676const device_type MULTIPCM = &device_creator<multipcm_device>;
597            if(slot->Regs[6]&7) //Vibrato enabled
598            {
599               step=step*PLFO_Step(&(slot->PLFO));
600               step>>=SHIFT;
601            }
677602
678multipcm_device::multipcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
679   : device_t(mconfig, MULTIPCM, "Sega/Yamaha 315-5560", tag, owner, clock, "multipcm", __FILE__),
680      device_sound_interface(mconfig, *this)
681{
682   m_token = global_alloc_clear(MultiPCM);
683}
603            slot->offset+=step;
604            if(slot->offset>=(slot->Sample->End<<SHIFT))
605            {
606               slot->offset=slot->Sample->Loop<<SHIFT;
607            }
608            if(adr^(slot->offset>>SHIFT))
609            {
610               slot->Prev=csample;
611            }
684612
685//-------------------------------------------------
686//  device_config_complete - perform any
687//  operations now that the configuration is
688//  complete
689//-------------------------------------------------
613            if((slot->TL>>SHIFT)!=slot->DstTL)
614               slot->TL+=slot->TLStep;
690615
691void multipcm_device::device_config_complete()
692{
693}
616            if(slot->Regs[7]&7) //Tremolo enabled
617            {
618               sample=sample*ALFO_Step(&(slot->ALFO));
619               sample>>=SHIFT;
620            }
694621
695//-------------------------------------------------
696//  device_start - device-specific startup
697//-------------------------------------------------
622            sample=(sample*EG_Update(slot))>>10;
698623
699void multipcm_device::device_start()
700{
701   DEVICE_START_NAME( multipcm )(this);
624            smpl+=(LPANTABLE[vol]*sample)>>SHIFT;
625            smpr+=(RPANTABLE[vol]*sample)>>SHIFT;
626         }
627      }
628#define ICLIP16(x) (x<-32768)?-32768:((x>32767)?32767:x)
629      datap[0][i]=ICLIP16(smpl);
630      datap[1][i]=ICLIP16(smpr);
631   }
702632}
703
704//-------------------------------------------------
705//  sound_stream_update - handle a stream update
706//-------------------------------------------------
707
708void multipcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
709{
710   // should never get here
711   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
712}
trunk/src/emu/sound/multipcm.h
r24581r24582
33#ifndef __MULTIPCM_H__
44#define __MULTIPCM_H__
55
6struct Sample_t
7{
8   unsigned int Start;
9   unsigned int Loop;
10   unsigned int End;
11   unsigned char AR,DR1,DR2,DL,RR;
12   unsigned char KRS;
13   unsigned char LFOVIB;
14   unsigned char AM;
15};
616
7DECLARE_WRITE8_DEVICE_HANDLER( multipcm_w );
8DECLARE_READ8_DEVICE_HANDLER( multipcm_r );
17enum STATE {ATTACK,DECAY1,DECAY2,RELEASE};
918
10void multipcm_set_bank(device_t *device, UINT32 leftoffs, UINT32 rightoffs);
19struct EG_t
20{
21   int volume; //
22   STATE state;
23   int step;
24   //step vals
25   int AR;     //Attack
26   int D1R;    //Decay1
27   int D2R;    //Decay2
28   int RR;     //Release
29   int DL;     //Decay level
30};
1131
32struct LFO_t
33{
34   unsigned short phase;
35   UINT32 phase_step;
36   int *table;
37   int *scale;
38};
39
40
41struct SLOT
42{
43   unsigned char Num;
44   unsigned char Regs[8];
45   int Playing;
46   Sample_t *Sample;
47   unsigned int Base;
48   unsigned int offset;
49   unsigned int step;
50   unsigned int Pan,TL;
51   unsigned int DstTL;
52   int TLStep;
53   signed int Prev;
54   EG_t EG;
55   LFO_t PLFO; //Phase lfo
56   LFO_t ALFO; //AM lfo
57};
58
1259class multipcm_device : public device_t,
1360                           public device_sound_interface
1461{
1562public:
1663   multipcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
17   ~multipcm_device() { global_free(m_token); }
64   ~multipcm_device() {}
1865
19   // access to legacy token
20   void *token() const { assert(m_token != NULL); return m_token; }
66   DECLARE_WRITE8_MEMBER( write );
67   DECLARE_READ8_MEMBER( read );
68
69   void set_bank(UINT32 leftoffs, UINT32 rightoffs);
70
2171protected:
2272   // device-level overrides
2373   virtual void device_config_complete();
r24581r24582
2575
2676   // sound stream update overrides
2777   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
78
2879private:
2980   // internal state
30   void *m_token;
81   sound_stream * m_stream;
82   Sample_t m_Samples[0x200];        //Max 512 samples
83   SLOT m_Slots[28];
84   unsigned int m_CurSlot;
85   unsigned int m_Address;
86   unsigned int m_BankR, m_BankL;
87   float m_Rate;
88   INT8 *m_ROM;
89   //I include these in the chip because they depend on the chip clock
90   unsigned int m_ARStep[0x40], m_DRStep[0x40]; //Envelope step table
91   unsigned int m_FNS_Table[0x400];      //Frequency step table
92   
93   void EG_Calc(SLOT *slot);
94   void LFO_ComputeStep(LFO_t *LFO,UINT32 LFOF,UINT32 LFOS,int ALFO);
95   void WriteSlot(SLOT *slot,int reg,unsigned char data);
3196};
3297
3398extern const device_type MULTIPCM;
trunk/src/mame/drivers/model2.c
r24581r24582
9696#include "cpu/mb86233/mb86233.h"
9797#include "cpu/z80/z80.h"
9898#include "sound/scsp.h"
99#include "sound/multipcm.h"
10099#include "sound/2612intf.h"
101100#include "includes/model2.h"
102101
r24581r24582
18081807
18091808WRITE16_MEMBER(model2_state::m1_snd_mpcm_bnk1_w)
18101809{
1811   device_t *device = machine().device("sega1");
1812   multipcm_set_bank(device, 0x100000 * (data & 0xf), 0x100000 * (data & 0xf));
1810   m_multipcm_1->set_bank(0x100000 * (data & 0xf), 0x100000 * (data & 0xf));
18131811}
18141812
18151813WRITE16_MEMBER(model2_state::m1_snd_mpcm_bnk2_w)
18161814{
1817   device_t *device = machine().device("sega2");
1818   multipcm_set_bank(device, 0x100000 * (data & 0xf), 0x100000 * (data & 0xf));
1815   m_multipcm_2->set_bank(0x100000 * (data & 0xf), 0x100000 * (data & 0xf));
18191816}
18201817
18211818WRITE16_MEMBER(model2_state::m1_snd_68k_latch1_w)
r24581r24582
18311828   AM_RANGE(0x080000, 0x0bffff) AM_ROM AM_REGION("audiocpu", 0x20000)  // mirror of second program ROM
18321829   AM_RANGE(0xc20000, 0xc20001) AM_READWRITE(m1_snd_68k_latch_r, m1_snd_68k_latch1_w )
18331830   AM_RANGE(0xc20002, 0xc20003) AM_READWRITE(m1_snd_v60_ready_r, m1_snd_68k_latch2_w )
1834   AM_RANGE(0xc40000, 0xc40007) AM_DEVREADWRITE8_LEGACY("sega1", multipcm_r, multipcm_w, 0x00ff )
1831   AM_RANGE(0xc40000, 0xc40007) AM_DEVREADWRITE8("sega1", multipcm_device, read, write, 0x00ff )
18351832   AM_RANGE(0xc40012, 0xc40013) AM_WRITENOP
18361833   AM_RANGE(0xc50000, 0xc50001) AM_WRITE(m1_snd_mpcm_bnk1_w )
1837   AM_RANGE(0xc60000, 0xc60007) AM_DEVREADWRITE8_LEGACY("sega2", multipcm_r, multipcm_w, 0x00ff )
1834   AM_RANGE(0xc60000, 0xc60007) AM_DEVREADWRITE8("sega2", multipcm_device, read, write, 0x00ff )
18381835   AM_RANGE(0xc70000, 0xc70001) AM_WRITE(m1_snd_mpcm_bnk2_w )
18391836   AM_RANGE(0xd00000, 0xd00007) AM_DEVREADWRITE8("ymsnd", ym3438_device, read, write, 0x00ff )
18401837   AM_RANGE(0xf00000, 0xf0ffff) AM_RAM
trunk/src/mame/drivers/model1.c
r24581r24582
629629#include "video/segaic24.h"
630630#include "cpu/m68000/m68000.h"
631631#include "cpu/mb86233/mb86233.h"
632#include "sound/multipcm.h"
633632#include "sound/2612intf.h"
634633#include "machine/nvram.h"
635634#include "includes/model1.h"
r24581r24582
10131012
10141013WRITE16_MEMBER(model1_state::m1_snd_mpcm_bnk1_w)
10151014{
1016   device_t *device = machine().device("sega1");
1017   multipcm_set_bank(device, 0x100000 * (data & 3), 0x100000 * (data & 3));
1015   m_multipcm_1->set_bank(0x100000 * (data & 3), 0x100000 * (data & 3));
10181016}
10191017WRITE16_MEMBER(model1_state::m1_snd_mpcm_bnk2_w)
10201018{
1021   device_t *device = machine().device("sega2");
1022   multipcm_set_bank(device, 0x100000 * (data & 3), 0x100000 * (data & 3));
1019   m_multipcm_2->set_bank(0x100000 * (data & 3), 0x100000 * (data & 3));
10231020}
10241021WRITE16_MEMBER(model1_state::m1_snd_68k_latch1_w)
10251022{
r24581r24582
10331030   AM_RANGE(0x000000, 0x0bffff) AM_ROM
10341031   AM_RANGE(0xc20000, 0xc20001) AM_READWRITE(m1_snd_68k_latch_r, m1_snd_68k_latch1_w )
10351032   AM_RANGE(0xc20002, 0xc20003) AM_READWRITE(m1_snd_v60_ready_r, m1_snd_68k_latch2_w )
1036   AM_RANGE(0xc40000, 0xc40007) AM_DEVREADWRITE8_LEGACY("sega1", multipcm_r, multipcm_w, 0x00ff )
1033   AM_RANGE(0xc40000, 0xc40007) AM_DEVREADWRITE8("sega1", multipcm_device, read, write, 0x00ff )
10371034   AM_RANGE(0xc40012, 0xc40013) AM_WRITENOP
10381035   AM_RANGE(0xc50000, 0xc50001) AM_WRITE(m1_snd_mpcm_bnk1_w )
1039   AM_RANGE(0xc60000, 0xc60007) AM_DEVREADWRITE8_LEGACY("sega2", multipcm_r, multipcm_w, 0x00ff )
1036   AM_RANGE(0xc60000, 0xc60007) AM_DEVREADWRITE8("sega2", multipcm_device, read, write, 0x00ff )
10401037   AM_RANGE(0xc70000, 0xc70001) AM_WRITE(m1_snd_mpcm_bnk2_w )
10411038   AM_RANGE(0xd00000, 0xd00007) AM_DEVREADWRITE8("ymsnd", ym3438_device, read, write, 0x00ff )
10421039   AM_RANGE(0xf00000, 0xf0ffff) AM_RAM
trunk/src/mame/drivers/segas32.c
r24581r24582
338338#include "machine/eepromser.h"
339339#include "sound/2612intf.h"
340340#include "sound/rf5c68.h"
341#include "sound/multipcm.h"
342341
343342#include "radr.lh"
344343
r24581r24582
11331132
11341133WRITE8_MEMBER(segas32_state::multipcm_bank_w)
11351134{
1136   device_t *device = machine().device("sega");
1137   multipcm_set_bank(device, 0x80000 * ((data >> 3) & 7), 0x80000 * (data & 7));
1135   m_multipcm->set_bank(0x80000 * ((data >> 3) & 7), 0x80000 * (data & 7));
11381136}
11391137
11401138
11411139WRITE8_MEMBER(segas32_state::scross_bank_w)
11421140{
1143   multipcm_device *multipcm = machine().device<multipcm_device>("sega");
1144   multipcm_set_bank(multipcm, 0x80000 * (data & 7), 0x80000 * (data & 7));
1141   m_multipcm->set_bank(0x80000 * (data & 7), 0x80000 * (data & 7));
11451142}
11461143
11471144
r24581r24582
12431240static ADDRESS_MAP_START( multi32_sound_map, AS_PROGRAM, 8, segas32_state )
12441241   AM_RANGE(0x0000, 0x9fff) AM_ROM AM_REGION("soundcpu", 0x100000)
12451242   AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1")
1246   AM_RANGE(0xc000, 0xdfff) AM_DEVREADWRITE_LEGACY("sega", multipcm_r, multipcm_w)
1243   AM_RANGE(0xc000, 0xdfff) AM_DEVREADWRITE("sega", multipcm_device, read, write)
12471244   AM_RANGE(0xe000, 0xffff) AM_RAM AM_SHARE("z80_shared_ram")
12481245ADDRESS_MAP_END
12491246
trunk/src/mame/drivers/ninjaw.c
r24581r24582
642642/**************************************************************
643643                 SUBWOOFER (SOUND)
644644**************************************************************/
645
646645#if 0
647static DEVICE_START( subwoofer )
648{
649   /* Adjust the lowpass filter of the first three YM2610 channels */
650646
651   /* The 150 Hz is a common top frequency played by a generic */
652   /* subwoofer, the real Arcade Machine may differs */
653
654   mixer_set_lowpass_frequency(0, 20);
655   mixer_set_lowpass_frequency(1, 20);
656   mixer_set_lowpass_frequency(2, 20);
657
658   return 0;
659}
660
661647class subwoofer_device : public device_t,
662648                           public device_sound_interface
663649{
664650public:
665651   subwoofer_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
666   ~subwoofer_device() { global_free(m_token); }
652   ~subwoofer_device() {}
667653
668   // access to legacy token
669   void *token() const { assert(m_token != NULL); return m_token; }
670654protected:
671655   // device-level overrides
672656   virtual void device_config_complete();
r24581r24582
674658
675659   // sound stream update overrides
676660   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
661
677662private:
678663   // internal state
679   void *m_token;
664
680665};
681666
682667extern const device_type SUBWOOFER;
r24581r24582
687672   : device_t(mconfig, SUBWOOFER, "Subwoofer", tag, owner, clock),
688673      device_sound_interface(mconfig, *this)
689674{
690   m_token = global_alloc_array_clear(UINT8, sizeof());
691675}
692676
693677//-------------------------------------------------
r24581r24582
706690
707691void subwoofer_device::device_start()
708692{
709   DEVICE_START_NAME( subwoofer )(this);
693   /* Adjust the lowpass filter of the first three YM2610 channels */
694
695   /* The 150 Hz is a common top frequency played by a generic */
696   /* subwoofer, the real Arcade Machine may differs */
697
698   mixer_set_lowpass_frequency(0, 20);
699   mixer_set_lowpass_frequency(1, 20);
700   mixer_set_lowpass_frequency(2, 20);
701
702   return 0;
710703}
711704
712705//-------------------------------------------------
r24581r24582
715708
716709void subwoofer_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
717710{
718   // should never get here
719   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
720711}
721712
722713
trunk/src/mame/drivers/mjkjidai.c
r24581r24582
2424#include "emu.h"
2525#include "cpu/z80/z80.h"
2626#include "sound/sn76496.h"
27#include "sound/okiadpcm.h"
2827#include "includes/mjkjidai.h"
29#include "devlegcy.h"
3028#include "mcfglgcy.h"
3129
32class mjkjidai_adpcm_device : public device_t,
33                           public device_sound_interface
34{
35public:
36   mjkjidai_adpcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
37   ~mjkjidai_adpcm_device() { global_free(m_token); }
38
39   // access to legacy token
40   void *token() const { assert(m_token != NULL); return m_token; }
41protected:
42   // device-level overrides
43   virtual void device_config_complete();
44   virtual void device_start();
45
46   // sound stream update overrides
47   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
48private:
49   // internal state
50   void *m_token;
51};
52
53extern const device_type MJKJIDAI;
54
5530/* Start of ADPCM custom chip code */
56struct mjkjidai_adpcm_state
57{
58   oki_adpcm_state m_adpcm;
59   sound_stream *m_stream;
60   UINT32 m_current;
61   UINT32 m_end;
62   UINT8 m_nibble;
63   UINT8 m_playing;
64   UINT8 *m_base;
65} _mjkjidai_adpcm_state_dummy;
6631
67static STREAM_UPDATE( mjkjidai_adpcm_callback )
68{
69   mjkjidai_adpcm_state *state = (mjkjidai_adpcm_state *)param;
70   stream_sample_t *dest = outputs[0];
71
72   while (state->m_playing && samples > 0)
73   {
74      int val = (state->m_base[state->m_current] >> state->m_nibble) & 15;
75
76      state->m_nibble ^= 4;
77      if (state->m_nibble == 4)
78      {
79         state->m_current++;
80         if (state->m_current >= state->m_end)
81            state->m_playing = 0;
82      }
83
84      *dest++ = state->m_adpcm.clock(val) << 4;
85      samples--;
86   }
87   while (samples > 0)
88   {
89      *dest++ = 0;
90      samples--;
91   }
92}
93
94static DEVICE_START( mjkjidai_adpcm )
95{
96   running_machine &machine = device->machine();
97   mjkjidai_adpcm_state *state = (mjkjidai_adpcm_state *)downcast<mjkjidai_adpcm_device *>(device)->token();
98
99   state->m_playing = 0;
100   state->m_stream = device->machine().sound().stream_alloc(*device, 0, 1, device->clock(), state, mjkjidai_adpcm_callback);
101   state->m_base = machine.root_device().memregion("adpcm")->base();
102   state->m_adpcm.reset();
103}
104
10532const device_type MJKJIDAI = &device_creator<mjkjidai_adpcm_device>;
10633
10734mjkjidai_adpcm_device::mjkjidai_adpcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
10835   : device_t(mconfig, MJKJIDAI, "Custom ADPCM", tag, owner, clock, "mjkjidai_adpcm", __FILE__),
109      device_sound_interface(mconfig, *this)
36      device_sound_interface(mconfig, *this),
37      m_stream(NULL),
38      m_current(0),
39      m_end(0),
40      m_nibble(0),
41      m_playing(0),
42      m_base(NULL)
11043{
111   m_token = global_alloc_clear(mjkjidai_adpcm_state);
11244}
11345
11446//-------------------------------------------------
r24581r24582
12759
12860void mjkjidai_adpcm_device::device_start()
12961{
130   DEVICE_START_NAME( mjkjidai_adpcm )(this);
62   m_playing = 0;
63   m_stream = machine().sound().stream_alloc(*this, 0, 1, clock(), this);
64   m_base = machine().root_device().memregion("adpcm")->base();
65   m_adpcm.reset();
66   
67   save_item(NAME(m_current));
68   save_item(NAME(m_end));
69   save_item(NAME(m_nibble));
70   save_item(NAME(m_playing));
13171}
13272
13373//-------------------------------------------------
r24581r24582
13676
13777void mjkjidai_adpcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
13878{
139   // should never get here
140   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
141}
79   stream_sample_t *dest = outputs[0];
14280
81   while (m_playing && samples > 0)
82   {
83      int val = (m_base[m_current] >> m_nibble) & 15;
14384
85      m_nibble ^= 4;
86      if (m_nibble == 4)
87      {
88         m_current++;
89         if (m_current >= m_end)
90            m_playing = 0;
91      }
14492
93      *dest++ = m_adpcm.clock(val) << 4;
94      samples--;
95   }
96   while (samples > 0)
97   {
98      *dest++ = 0;
99      samples--;
100   }
101}
145102
146static void mjkjidai_adpcm_play (mjkjidai_adpcm_state *state, int offset, int length)
103void mjkjidai_adpcm_device::mjkjidai_adpcm_play (int offset, int length)
147104{
148   state->m_current = offset;
149   state->m_end = offset + length/2;
150   state->m_nibble = 4;
151   state->m_playing = 1;
105   m_current = offset;
106   m_end = offset + length/2;
107   m_nibble = 4;
108   m_playing = 1;
152109}
153110
154111WRITE8_MEMBER(mjkjidai_state::adpcm_w)
155112{
156   device_t *device = machine().device("adpcm");
157   mjkjidai_adpcm_state *state = (mjkjidai_adpcm_state *)downcast<mjkjidai_adpcm_device *>(device)->token();
158   mjkjidai_adpcm_play (state, (data & 0x07) * 0x1000, 0x1000 * 2);
113   m_mjk_adpcm->mjkjidai_adpcm_play ((data & 0x07) * 0x1000, 0x1000 * 2);
159114}
160115/* End of ADPCM custom chip code */
161116
trunk/src/mame/drivers/renegade.c
r24581r24582
105105#include "cpu/m6809/m6809.h"
106106#include "cpu/m6805/m6805.h"
107107#include "sound/3526intf.h"
108#include "sound/okiadpcm.h"
109108#include "includes/renegade.h"
110#include "devlegcy.h"
111109
112110
113111/********************************************************************************************/
114112
115struct renegade_adpcm_state
116{
117   oki_adpcm_state m_adpcm;
118   sound_stream *m_stream;
119   UINT32 m_current;
120   UINT32 m_end;
121   UINT8 m_nibble;
122   UINT8 m_playing;
123   UINT8 *m_base;
124} _renegade_adpcm_state_dummy;
125
126class renegade_adpcm_device : public device_t,
127                           public device_sound_interface
128{
129public:
130   renegade_adpcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
131   ~renegade_adpcm_device() { global_free(m_token); }
132
133   // access to legacy token
134   void *token() const { assert(m_token != NULL); return m_token; }
135protected:
136   // device-level overrides
137   virtual void device_config_complete();
138   virtual void device_start();
139
140   // sound stream update overrides
141   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
142private:
143   // internal state
144   void *m_token;
145};
146
147extern const device_type RENEGADE_ADPCM;
148
149
150INLINE renegade_adpcm_state *get_safe_token(device_t *device)
151{
152   assert(device != NULL);
153   assert(device->type() == RENEGADE_ADPCM);
154
155   return (renegade_adpcm_state *)downcast<renegade_adpcm_device *>(device)->token();
156}
157
158static STREAM_UPDATE( renegade_adpcm_callback )
159{
160   renegade_adpcm_state *state = (renegade_adpcm_state *)param;
161   stream_sample_t *dest = outputs[0];
162
163   while (state->m_playing && samples > 0)
164   {
165      int val = (state->m_base[state->m_current] >> state->m_nibble) & 15;
166
167      state->m_nibble ^= 4;
168      if (state->m_nibble == 4)
169      {
170         state->m_current++;
171         if (state->m_current >= state->m_end)
172            state->m_playing = 0;
173      }
174
175      *dest++ = state->m_adpcm.clock(val) << 4;
176      samples--;
177   }
178   while (samples > 0)
179   {
180      *dest++ = 0;
181      samples--;
182   }
183}
184
185static DEVICE_START( renegade_adpcm )
186{
187   renegade_adpcm_state *state = get_safe_token(device);
188   state->m_playing = 0;
189   state->m_stream = device->machine().sound().stream_alloc(*device, 0, 1, device->clock(), state, renegade_adpcm_callback);
190   state->m_base = device->machine().root_device().memregion("adpcm")->base();
191   state->m_adpcm.reset();
192}
193
194113const device_type RENEGADE_ADPCM = &device_creator<renegade_adpcm_device>;
195114
196115renegade_adpcm_device::renegade_adpcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
197116   : device_t(mconfig, RENEGADE_ADPCM, "Renegade Custom ADPCM", tag, owner, clock, "renegade_adpcm", __FILE__),
198      device_sound_interface(mconfig, *this)
117      device_sound_interface(mconfig, *this),
118      m_stream(NULL),
119      m_current(0),
120      m_end(0),
121      m_nibble(0),
122      m_playing(0),
123      m_base(NULL)
199124{
200   m_token = global_alloc_clear(renegade_adpcm_state);
201125}
202126
203127//-------------------------------------------------
r24581r24582
216140
217141void renegade_adpcm_device::device_start()
218142{
219   DEVICE_START_NAME( renegade_adpcm )(this);
143   m_playing = 0;
144   m_stream = machine().sound().stream_alloc(*this, 0, 1, clock(), this);
145   m_base = machine().root_device().memregion("adpcm")->base();
146   m_adpcm.reset();
147   
148   save_item(NAME(m_current));
149   save_item(NAME(m_end));
150   save_item(NAME(m_nibble));
151   save_item(NAME(m_playing));
220152}
221153
222154//-------------------------------------------------
r24581r24582
225157
226158void renegade_adpcm_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
227159{
228   // should never get here
229   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
230}
160   stream_sample_t *dest = outputs[0];
231161
162   while (m_playing && samples > 0)
163   {
164      int val = (m_base[m_current] >> m_nibble) & 15;
232165
166      m_nibble ^= 4;
167      if (m_nibble == 4)
168      {
169         m_current++;
170         if (m_current >= m_end)
171            m_playing = 0;
172      }
233173
174      *dest++ = m_adpcm.clock(val) << 4;
175      samples--;
176   }
177   while (samples > 0)
178   {
179      *dest++ = 0;
180      samples--;
181   }
182}
234183
235WRITE8_MEMBER(renegade_state::adpcm_play_w)
184
185WRITE8_MEMBER(renegade_adpcm_device::play_w)
236186{
237   device_t *device = machine().device("adpcm");
238   renegade_adpcm_state *renstate = get_safe_token(device);
239187   int offs = (data - 0x2c) * 0x2000;
240188   int len = 0x2000 * 2;
241189
r24581r24582
245193
246194   if (offs >= 0 && offs+len <= 0x20000)
247195   {
248      renstate->m_stream->update();
249      renstate->m_adpcm.reset();
196      m_stream->update();
197      m_adpcm.reset();
250198
251      renstate->m_current = offs;
252      renstate->m_end = offs + len/2;
253      renstate->m_nibble = 4;
254      renstate->m_playing = 1;
199      m_current = offs;
200      m_end = offs + len/2;
201      m_nibble = 4;
202      m_playing = 1;
255203   }
256204   else
257205      logerror("out of range adpcm command: 0x%02x\n", data);
r24581r24582
705653   AM_RANGE(0x0000, 0x0fff) AM_RAM
706654   AM_RANGE(0x1000, 0x1000) AM_READ(soundlatch_byte_r)
707655   AM_RANGE(0x1800, 0x1800) AM_WRITENOP // this gets written the same values as 0x2000
708   AM_RANGE(0x2000, 0x2000) AM_WRITE(adpcm_play_w)
656   AM_RANGE(0x2000, 0x2000) AM_DEVWRITE("adpcm", renegade_adpcm_device, play_w)
709657   AM_RANGE(0x2800, 0x2801) AM_DEVREADWRITE("ymsnd", ym3526_device, read, write)
710658   AM_RANGE(0x3000, 0x3000) AM_WRITENOP /* adpcm related? stereo pan? */
711659   AM_RANGE(0x8000, 0xffff) AM_ROM
trunk/src/mame/audio/exidy440.c
r24581r24582
6161      m_m6844_chain(0x00),
6262      m_stream(NULL)
6363{
64   m_sound_banks[0] = m_sound_banks[1] = m_sound_banks[2] = m_sound_banks[3] = 0;
65   
66   for (int i = 0; i < 4; i++)
67   {
68      m_sound_channel[i].base = NULL;
69      m_sound_channel[i].offset = 0;
70      m_sound_channel[i].remaining = 0;
71   }
6472}
6573
6674//-------------------------------------------------
r24581r24582
100108   save_item(NAME(m_m6844_priority));
101109   save_item(NAME(m_m6844_interrupt));
102110   save_item(NAME(m_m6844_chain));
103
111   
104112   m_channel_frequency[0] = clock();   /* channels 0 and 1 are run by FCLK */
105113   m_channel_frequency[1] = clock();
106114   m_channel_frequency[2] = clock()/2; /* channels 2 and 3 are run by SCLK */
trunk/src/mame/includes/model1.h
r24581r24582
11#include "audio/dsbz80.h"
2#include "sound/multipcm.h"
23
34typedef void (*tgp_func)(running_machine &machine);
45
r24581r24582
1213      : driver_device(mconfig, type, tag),
1314      m_maincpu(*this, "maincpu"),
1415      m_audiocpu(*this, "audiocpu"),
16      m_multipcm_1(*this, "sega1"),
17      m_multipcm_2(*this, "sega2"),
1518      m_dsbz80(*this, DSBZ80_TAG),
1619      m_mr2(*this, "mr2"),
1720      m_mr(*this, "mr"),
r24581r24582
2124
2225   required_device<cpu_device> m_maincpu;      // V60
2326   required_device<cpu_device> m_audiocpu;     // sound 68000
27   required_device<multipcm_device> m_multipcm_1;
28   required_device<multipcm_device> m_multipcm_2;
2429   optional_device<dsbz80_device> m_dsbz80;    // Digital Sound Board
2530
2631   required_shared_ptr<UINT16> m_mr2;
trunk/src/mame/includes/model2.h
r24581r24582
11#include "video/poly.h"
22#include "audio/dsbz80.h"
33#include "machine/eepromser.h"
4#include "sound/multipcm.h"
45
56struct raster_state;
67struct geo_state;
r24581r24582
1112public:
1213   model2_state(const machine_config &mconfig, device_type type, const char *tag)
1314      : driver_device(mconfig, type, tag),
14      m_maincpu(*this,"maincpu"),
1515      m_workram(*this, "workram"),
1616      m_bufferram(*this, "bufferram"),
1717      m_paletteram32(*this, "paletteram32"),
r24581r24582
2020      m_textureram1(*this, "textureram1"),
2121      m_lumaram(*this, "lumaram"),
2222      m_soundram(*this, "soundram"),
23      m_tgp_program(*this, "tgp_program"),
24      m_maincpu(*this,"maincpu"),
2325      m_dsbz80(*this, DSBZ80_TAG),
24      m_tgp_program(*this, "tgp_program"),
2526      m_audiocpu(*this, "audiocpu"),
27      m_multipcm_1(*this, "sega1"),
28      m_multipcm_2(*this, "sega2"),
2629      m_tgp(*this, "tgp"),
2730      m_dsp(*this, "dsp"),
2831      m_drivecpu(*this, "drivecpu"),
2932      m_eeprom(*this, "eeprom") { }
3033
31   required_device<cpu_device> m_maincpu;
3234   required_shared_ptr<UINT32> m_workram;
3335   required_shared_ptr<UINT32> m_bufferram;
3436   required_shared_ptr<UINT32> m_paletteram32;
r24581r24582
3739   required_shared_ptr<UINT32> m_textureram1;
3840   required_shared_ptr<UINT32> m_lumaram;
3941   optional_shared_ptr<UINT16> m_soundram;
42   optional_shared_ptr<UINT32> m_tgp_program;
43   
44   required_device<cpu_device> m_maincpu;
4045   optional_device<dsbz80_device> m_dsbz80;    // Z80-based MPEG Digital Sound Board
41   optional_shared_ptr<UINT32> m_tgp_program;
46   required_device<cpu_device> m_audiocpu;
47   optional_device<multipcm_device> m_multipcm_1;
48   optional_device<multipcm_device> m_multipcm_2;
49   optional_device<cpu_device> m_tgp;
50   optional_device<cpu_device> m_dsp;
51   optional_device<cpu_device> m_drivecpu;
52   required_device<eeprom_serial_93cxx_device> m_eeprom;
4253
4354   UINT32 m_intreq;
4455   UINT32 m_intena;
r24581r24582
176187   TIMER_DEVICE_CALLBACK_MEMBER(model2c_interrupt);
177188   void model2_exit();
178189   DECLARE_WRITE_LINE_MEMBER(scsp_irq);
179   required_device<cpu_device> m_audiocpu;
180   optional_device<cpu_device> m_tgp;
181   optional_device<cpu_device> m_dsp;
182   optional_device<cpu_device> m_drivecpu;
183   required_device<eeprom_serial_93cxx_device> m_eeprom;
184190};
185191
186192/*----------- defined in video/model2.c -----------*/
trunk/src/mame/includes/mjkjidai.h
r24581r24582
1#include "sound/okiadpcm.h"
2
3class mjkjidai_adpcm_device;
4
15class mjkjidai_state : public driver_device
26{
37public:
r24581r24582
812      m_spriteram2(*this, "spriteram2"),
913      m_spriteram3(*this, "spriteram3"),
1014      m_videoram(*this, "videoram"),
11      m_maincpu(*this, "maincpu") { }
15      m_maincpu(*this, "maincpu"),
16      m_mjk_adpcm(*this, "adpcm") { }
1217
1318   required_shared_ptr<UINT8> m_nvram;
1419   required_shared_ptr<UINT8> m_spriteram1;
1520   required_shared_ptr<UINT8> m_spriteram2;
1621   required_shared_ptr<UINT8> m_spriteram3;
1722   required_shared_ptr<UINT8> m_videoram;
23   
24   required_device<cpu_device> m_maincpu;
25   required_device<mjkjidai_adpcm_device> m_mjk_adpcm;
1826
1927   int m_keyb;
2028   int m_nvram_init_count;
r24581r24582
3240   UINT32 screen_update_mjkjidai(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
3341   INTERRUPT_GEN_MEMBER(vblank_irq);
3442   void draw_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
35   required_device<cpu_device> m_maincpu;
3643};
44
45class mjkjidai_adpcm_device : public device_t,
46                           public device_sound_interface
47{
48public:
49   mjkjidai_adpcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
50   ~mjkjidai_adpcm_device() {}
51   
52   void mjkjidai_adpcm_play (int offset, int length);
53
54protected:
55   // device-level overrides
56   virtual void device_config_complete();
57   virtual void device_start();
58
59   // sound stream update overrides
60   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
61private:
62   // internal state
63   oki_adpcm_state m_adpcm;
64   sound_stream *m_stream;
65   UINT32 m_current;
66   UINT32 m_end;
67   UINT8 m_nibble;
68   UINT8 m_playing;
69   UINT8 *m_base;
70};
71
72extern const device_type MJKJIDAI;
trunk/src/mame/includes/renegade.h
r24581r24582
1#include "sound/okiadpcm.h"
2
13#define MCU_BUFFER_MAX 6
24
5class renegade_adpcm_device;
6
37class renegade_state : public driver_device
48{
59public:
r24581r24582
8185   required_device<cpu_device> m_audiocpu;
8286   optional_device<cpu_device> m_mcu;
8387};
88
89class renegade_adpcm_device : public device_t,
90                           public device_sound_interface
91{
92public:
93   renegade_adpcm_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
94   ~renegade_adpcm_device() {}
95
96   DECLARE_WRITE8_MEMBER(play_w);
97
98protected:
99   // device-level overrides
100   virtual void device_config_complete();
101   virtual void device_start();
102
103   // sound stream update overrides
104   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
105
106private:
107   // internal state
108   oki_adpcm_state m_adpcm;
109   sound_stream *m_stream;
110   UINT32 m_current;
111   UINT32 m_end;
112   UINT8 m_nibble;
113   UINT8 m_playing;
114   UINT8 *m_base;
115};
116
117extern const device_type RENEGADE_ADPCM;
trunk/src/mame/includes/segas32.h
r24581r24582
55***************************************************************************/
66
77#include "machine/eepromser.h"
8#include "sound/multipcm.h"
89
910
1011class segas32_state : public driver_device
r24581r24582
2021      m_system32_paletteram(*this,"paletteram", 0) ,
2122      m_maincpu(*this, "maincpu"),
2223      m_soundcpu(*this, "soundcpu"),
24      m_multipcm(*this, "sega"),
2325      m_eeprom(*this, "eeprom") { }
2426
2527   required_shared_ptr<UINT8> m_z80_shared_ram;
r24581r24582
2729   optional_shared_ptr<UINT16> m_system32_workram;
2830   required_shared_ptr<UINT16> m_system32_videoram;
2931   required_shared_ptr<UINT16> m_system32_spriteram;
32   optional_shared_ptr_array<UINT16, 2> m_system32_paletteram;
33   
34   required_device<cpu_device> m_maincpu;
35   required_device<cpu_device> m_soundcpu;
36   optional_device<multipcm_device> m_multipcm;
37   required_device<eeprom_serial_93cxx_device> m_eeprom;
3038
3139   typedef void (segas32_state::*sys32_output_callback)(int which, UINT16 data);
3240
r24581r24582
6876   sys32_output_callback m_sw3_output;
6977   UINT16* m_dual_pcb_comms;
7078   UINT16 *m_system32_protram;
71   optional_shared_ptr_array<UINT16, 2> m_system32_paletteram;
7279   UINT16 m_system32_displayenable[2];
7380   UINT16 m_system32_tilebank_external;
7481   UINT16 m_arescue_dsp_io[6];
r24581r24582
252259   void update_bitmap(screen_device &screen, struct layer_info *layer, const rectangle &cliprect);
253260   void update_background(struct layer_info *layer, const rectangle &cliprect);
254261   DECLARE_WRITE_LINE_MEMBER(ym3438_irq_handler);
255   required_device<cpu_device> m_maincpu;
256   required_device<cpu_device> m_soundcpu;
257   required_device<eeprom_serial_93cxx_device> m_eeprom;
258262};
259263
260264/*----------- defined in machine/segas32.c -----------*/

Previous 199869 Revisions Next


© 1997-2024 The MAME Team