1 // license:GPL-2.0+
2 // copyright-holders:Peter Trauner
3 /***************************************************************************
4 
5   PeT mess@utanet.at
6   main part in video/
7 
8 ***************************************************************************/
9 
10 #include "emu.h"
11 #include "vc4000.h"
12 
13 
14 DEFINE_DEVICE_TYPE(VC4000_SND, vc4000_sound_device, "vc4000_sound", "Interton Electronic VC 4000 Custom Sound")
15 
vc4000_sound_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)16 vc4000_sound_device::vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
17 	: device_t(mconfig, VC4000_SND, tag, owner, clock)
18 	, device_sound_interface(mconfig, *this)
19 	, m_channel(nullptr)
20 	, m_reg{ 0 }
21 	, m_size(0)
22 	, m_pos(0)
23 	, m_level(0)
24 {
25 }
26 
27 
28 //-------------------------------------------------
29 //  device_start - device-specific startup
30 //-------------------------------------------------
31 
device_start()32 void vc4000_sound_device::device_start()
33 {
34 	m_channel = stream_alloc(0, 1, machine().sample_rate());
35 }
36 
37 
38 //-------------------------------------------------
39 //  sound_stream_update - handle a stream update
40 //-------------------------------------------------
41 
sound_stream_update(sound_stream & stream,std::vector<read_stream_view> const & inputs,std::vector<write_stream_view> & outputs)42 void vc4000_sound_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
43 {
44 	int i;
45 	auto &buffer = outputs[0];
46 
47 	for (i = 0; i < buffer.samples(); i++)
48 	{
49 		buffer.put(i, (m_reg[0] && m_pos <= m_size / 2) ? 1.0 : 0.0);
50 		if (m_pos <= m_size)
51 			m_pos++;
52 		if (m_pos > m_size)
53 			m_pos = 0;
54 	}
55 }
56 
57 
soundport_w(int offset,int data)58 void vc4000_sound_device::soundport_w(int offset, int data)
59 {
60 	m_channel->update();
61 	m_reg[offset] = data;
62 	switch (offset)
63 	{
64 		case 0:
65 			m_pos = 0;
66 			m_level = true;
67 			// frequency 7874/(data+1)
68 			m_size = machine().sample_rate() * (data + 1) /7874;
69 			break;
70 	}
71 }
72