Previous 199869 Revisions Next

r21510 Friday 1st March, 2013 at 08:47:05 UTC by Miodrag Milanović
channelf sound device modernized (nw)
[src/mess/audio]channelf.c channelf.h*
[src/mess/drivers]channelf.c
[src/mess/includes]channelf.h

trunk/src/mess/drivers/channelf.c
r21509r21510
133133WRITE8_MEMBER( channelf_state::channelf_port_5_w )
134134{
135135   m_latch[3] = data;
136   channelf_sound_w(machine().device("custom"), (data>>6)&3);
136   m_custom->sound_w((data>>6)&3);
137137   m_row_reg = (data | 0xc0) ^ 0xff;
138138}
139139
r21509r21510
277277
278278   /* sound hardware */
279279   MCFG_SPEAKER_STANDARD_MONO("mono")
280   MCFG_SOUND_ADD("custom", CHANNELF, 0)
280   MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0)
281281   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
282282
283283   MCFG_FRAGMENT_ADD( channelf_cart )
r21509r21510
303303
304304   /* sound hardware */
305305   MCFG_SPEAKER_STANDARD_MONO("mono")
306   MCFG_SOUND_ADD("custom", CHANNELF, 0)
306   MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0)
307307   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
308308
309309   MCFG_FRAGMENT_ADD( channelf_cart )
r21509r21510
330330
331331   /* sound hardware */
332332   MCFG_SPEAKER_STANDARD_MONO("mono")
333   MCFG_SOUND_ADD("custom", CHANNELF, 0)
333   MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0)
334334   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
335335
336336   MCFG_FRAGMENT_ADD( channelf_cart )
r21509r21510
357357
358358   /* sound hardware */
359359   MCFG_SPEAKER_STANDARD_MONO("mono")
360   MCFG_SOUND_ADD("custom", CHANNELF, 0)
360   MCFG_SOUND_ADD("custom", CHANNELF_SOUND, 0)
361361   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
362362
363363   MCFG_FRAGMENT_ADD( channelf_cart )
trunk/src/mess/audio/channelf.c
r21509r21510
1#include "includes/channelf.h"
1#include "emu.h"
2#include "audio/channelf.h"
23
34
4static const int max_amplitude = 0x7fff;
5#define MAX_AMPLITUDE  0x7fff
56
6struct channelf_sound_state
7{
8   sound_stream *channel;
9   int sound_mode;
10   int incr;
11   float decay_mult;
12   int envelope;
13   UINT32 sample_counter;
14   int forced_ontime;           //  added for improved sound
15   int min_ontime;              //  added for improved sound
16};
7const device_type CHANNELF_SOUND = &device_creator<channelf_sound_device>;
178
18INLINE channelf_sound_state *get_safe_token(device_t *device)
9channelf_sound_device::channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
10   : device_t(mconfig, CHANNELF_SOUND, "Channel F Sound", tag, owner, clock),
11      device_sound_interface(mconfig, *this),
12      m_channel(NULL),
13      m_sound_mode(0),
14      m_incr(0),
15      m_decay_mult(0),
16      m_envelope(0),
17      m_sample_counter(0),
18      m_forced_ontime(0),
19      m_min_ontime(0)   
1920{
20   assert(device != NULL);
21   assert(device->type() == CHANNELF);
22   return (channelf_sound_state *)downcast<channelf_sound_device *>(device)->token();
21   
2322}
2423
25void channelf_sound_w(device_t *device, int mode)
26{
27   channelf_sound_state *state = get_safe_token(device);
28   if (mode == state->sound_mode)
29      return;
24//-------------------------------------------------
25//  device_config_complete - perform any
26//  operations now that the configuration is
27//  complete
28//-------------------------------------------------
3029
31   state->channel->update();
32   state->sound_mode = mode;
33
34   switch(mode)
35   {
36      case 0:
37         state->envelope = 0;
38         state->forced_ontime = 0;     //  added for improved sound
39         break;
40      case 1:
41      case 2:
42      case 3:
43         state->envelope = max_amplitude;
44         state->forced_ontime = state->min_ontime;   //  added for improved sound
45         break;
46   }
47}
48
49
50
51static STREAM_UPDATE( channelf_sh_update )
30void channelf_sound_device::device_config_complete()
5231{
53   channelf_sound_state *state = get_safe_token(device);
54   UINT32 mask = 0, target = 0;
55   stream_sample_t *buffer = outputs[0];
56   stream_sample_t *sample = buffer;
57
58   switch( state->sound_mode )
59   {
60      case 0: /* sound off */
61         memset(buffer,0,sizeof(*buffer)*samples);
62         return;
63
64      case 1: /* high tone (2V) - 1000Hz */
65         mask   = 0x00010000;
66         target = 0x00010000;
67         break;
68      case 2: /* medium tone (4V) - 500Hz */
69         mask   = 0x00020000;
70         target = 0x00020000;
71         break;
72      case 3: /* low (weird) tone (32V & 8V) */
73         mask   = 0x00140000;
74         target = 0x00140000;
75         break;
76   }
77
78   while (samples-- > 0)
79   {
80      if ((state->forced_ontime > 0) || ((state->sample_counter & mask) == target))   //  change made for improved sound
81         *sample++ = state->envelope;
82      else
83         *sample++ = 0;
84      state->sample_counter += state->incr;
85      state->envelope *= state->decay_mult;
86      if (state->forced_ontime > 0)          //  added for improved sound
87         state->forced_ontime -= 1;      //  added for improved sound
88   }
8932}
9033
34//-------------------------------------------------
35//  device_start - device-specific startup
36//-------------------------------------------------
9137
92
93static DEVICE_START(channelf_sound)
38void channelf_sound_device::device_start()
9439{
95   channelf_sound_state *state = get_safe_token(device);
9640   int rate;
9741
98   state->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), 0, channelf_sh_update);
99   rate = device->machine().sample_rate();
42   m_channel = stream_alloc(0, 1, machine().sample_rate());
43   rate = machine().sample_rate();
10044
10145   /*
10246    * 2V = 1000Hz ~= 3579535/224/16
r21509r21510
11761    */
11862
11963   /* This is the proper value to add per sample */
120   state->incr = 65536.0/(rate/1000.0/2.0);
64   m_incr = 65536.0/(rate/1000.0/2.0);
12165
12266   //  added for improved sound
12367   /* This is the minimum forced ontime, in samples */
124   state->min_ontime = rate/1000*2;  /* approx 2ms - estimated, not verified on HW */
68   m_min_ontime = rate/1000*2;  /* approx 2ms - estimated, not verified on HW */
12569
12670   /* This was measured, decay envelope with half life of ~9ms */
12771   /* (this is decay multiplier per sample) */
128   state->decay_mult = exp((-0.693/9e-3)/rate);
72   m_decay_mult = exp((-0.693/9e-3)/rate);
12973
13074   /* initial conditions */
131   state->envelope = 0;
75   m_envelope = 0;
13276}
13377
134const device_type CHANNELF = &device_creator<channelf_sound_device>;
135
136channelf_sound_device::channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
137   : device_t(mconfig, CHANNELF, "Channel F", tag, owner, clock),
138      device_sound_interface(mconfig, *this)
139{
140   m_token = global_alloc_clear(channelf_sound_state);
141}
142
14378//-------------------------------------------------
144//  device_config_complete - perform any
145//  operations now that the configuration is
146//  complete
79//  sound_stream_update - handle a stream update
14780//-------------------------------------------------
14881
149void channelf_sound_device::device_config_complete()
82void channelf_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
15083{
151}
84   UINT32 mask = 0, target = 0;
85   stream_sample_t *buffer = outputs[0];
86   stream_sample_t *sample = buffer;
15287
153//-------------------------------------------------
154//  device_start - device-specific startup
155//-------------------------------------------------
88   switch( m_sound_mode )
89   {
90      case 0: /* sound off */
91         memset(buffer,0,sizeof(*buffer)*samples);
92         return;
15693
157void channelf_sound_device::device_start()
158{
159   DEVICE_START_NAME( channelf_sound )(this);
94      case 1: /* high tone (2V) - 1000Hz */
95         mask   = 0x00010000;
96         target = 0x00010000;
97         break;
98      case 2: /* medium tone (4V) - 500Hz */
99         mask   = 0x00020000;
100         target = 0x00020000;
101         break;
102      case 3: /* low (weird) tone (32V & 8V) */
103         mask   = 0x00140000;
104         target = 0x00140000;
105         break;
106   }
107
108   while (samples-- > 0)
109   {
110      if ((m_forced_ontime > 0) || ((m_sample_counter & mask) == target))   //  change made for improved sound
111         *sample++ = m_envelope;
112      else
113         *sample++ = 0;
114      m_sample_counter += m_incr;
115      m_envelope *= m_decay_mult;
116      if (m_forced_ontime > 0)          //  added for improved sound
117         m_forced_ontime -= 1;      //  added for improved sound
118   }
160119}
161120
162//-------------------------------------------------
163//  sound_stream_update - handle a stream update
164//-------------------------------------------------
165
166void channelf_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
121void channelf_sound_device::sound_w(int mode)
167122{
168   // should never get here
169   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
123   if (mode == m_sound_mode)
124      return;
125
126   m_channel->update();
127   m_sound_mode = mode;
128
129   switch(mode)
130   {
131      case 0:
132         m_envelope = 0;
133         m_forced_ontime = 0;     //  added for improved sound
134         break;
135      case 1:
136      case 2:
137      case 3:
138         m_envelope = MAX_AMPLITUDE;
139         m_forced_ontime = m_min_ontime;   //  added for improved sound
140         break;
141   }
170142}
trunk/src/mess/audio/channelf.h
r0r21510
1/*****************************************************************************
2 *
3 * audio/channelf.h
4 *
5 ****************************************************************************/
6
7#ifndef CHANNELF_SOUND_H_
8#define CHANNELF_SOUND_H_
9
10class channelf_sound_device : public device_t,
11                           public device_sound_interface
12{
13public:
14   channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
15   
16   void sound_w(int mode);
17protected:
18   // device-level overrides
19   virtual void device_config_complete();
20   virtual void device_start();
21
22   // sound stream update overrides
23   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
24private:
25   // internal state
26   sound_stream *m_channel;
27   int m_sound_mode;
28   int m_incr;
29   float m_decay_mult;
30   int m_envelope;
31   UINT32 m_sample_counter;
32   int m_forced_ontime;           //  added for improved sound
33   int m_min_ontime;              //  added for improved sound
34
35};
36
37extern const device_type CHANNELF_SOUND;
38
39
40#endif /* CHANNELF_SOUND_H_ */
Property changes on: trunk/src/mess/audio/channelf.h
Added: svn:eol-style
   + native
Added: svn:mime-type
   + text/plain
trunk/src/mess/includes/channelf.h
r21509r21510
1010#include "emu.h"
1111#include "cpu/f8/f8.h"
1212#include "imagedev/cartslot.h"
13#include "audio/channelf.h"
1314
1415
1516/* SKR - 2102 RAM chip on carts 10 and 18 I/O ports */
r21509r21510
2728{
2829public:
2930   channelf_state(const machine_config &mconfig, device_type type, const char *tag)
30      : driver_device(mconfig, type, tag) { }
31      : driver_device(mconfig, type, tag),
32        m_custom(*this,"custom")   { }
3133
3234   DECLARE_READ8_MEMBER(channelf_port_0_r);
3335   DECLARE_READ8_MEMBER(channelf_port_1_r);
r21509r21510
5254   virtual void palette_init();
5355   UINT32 screen_update_channelf(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
5456   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( channelf_cart );
57   required_device<channelf_sound_device> m_custom;
5558};
5659
57
58/*----------- defined in video/channelf.c -----------*/
59
60
61
62
63
64
65/*----------- defined in audio/channelf.c -----------*/
66
67class channelf_sound_device : public device_t,
68                           public device_sound_interface
69{
70public:
71   channelf_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
72   ~channelf_sound_device() { global_free(m_token); }
73
74   // access to legacy token
75   void *token() const { assert(m_token != NULL); return m_token; }
76protected:
77   // device-level overrides
78   virtual void device_config_complete();
79   virtual void device_start();
80
81   // sound stream update overrides
82   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
83private:
84   // internal state
85   void *m_token;
86};
87
88extern const device_type CHANNELF;
89
90
91void channelf_sound_w(device_t *device, int mode);
92
93
9460#endif /* CHANNELF_H_ */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team