1 // license:BSD-3-Clause
2 // copyright-holders:K.Wilkins,Derrick Renaud
3 /************************************************************************
4  *
5  *  MAME - Discrete sound system emulation library
6  *
7  *  Written by K.Wilkins (mame@esplexo.co.uk)
8  *
9  *  (c) K.Wilkins 2000
10  *  (c) Derrick Renaud 2003-2004
11  *
12  ************************************************************************
13  *
14  * DSO_OUTPUT            - Output node
15  * DSO_TASK              - Task node
16  *
17  * Task and list routines
18  *
19  ************************************************************************/
20 
21 
22 
23 
24 /*************************************
25  *
26  *  Task node (main task execution)
27  *
28  *************************************/
29 
DISCRETE_START(dso_csvlog)30 DISCRETE_START( dso_csvlog )
31 {
32 	int log_num, node_num;
33 
34 	log_num = m_device->same_module_index(*this);
35 	m_sample_num = 0;
36 
37 	sprintf(m_name, "%s_%d.csv", m_device->basetag(), log_num);
38 	m_csv_file = fopen(m_name, "w");
39 	/* Output some header info */
40 	fprintf(m_csv_file, "\"MAME Discrete System Node Log\"\n");
41 	fprintf(m_csv_file, "\"Log Version\", 1.0\n");
42 	fprintf(m_csv_file, "\"Sample Rate\", %d\n", this->sample_rate());
43 	fprintf(m_csv_file, "\n");
44 	fprintf(m_csv_file, "\"Sample\"");
45 	for (node_num = 0; node_num < this->active_inputs(); node_num++)
46 	{
47 		fprintf(m_csv_file, ", \"NODE_%2d\"", NODE_INDEX(this->input_node(node_num)));
48 	}
49 	fprintf(m_csv_file, "\n");
50 }
51 
DISCRETE_STOP(dso_csvlog)52 DISCRETE_STOP( dso_csvlog )
53 {
54 	/* close any csv files */
55 	if (m_csv_file)
56 		fclose(m_csv_file);
57 }
58 
DISCRETE_STEP(dso_csvlog)59 DISCRETE_STEP( dso_csvlog )
60 {
61 	int nodenum;
62 
63 	/* Dump any csv logs */
64 	fprintf(m_csv_file, "%s", string_format("%d", ++m_sample_num).c_str());
65 	for (nodenum = 0; nodenum < this->active_inputs(); nodenum++)
66 	{
67 		fprintf(m_csv_file, ", %f", *this->m_input[nodenum]);
68 	}
69 	fprintf(m_csv_file, "\n");
70 }
71 
DISCRETE_RESET(dso_csvlog)72 DISCRETE_RESET( dso_csvlog )
73 {
74 	this->step();
75 }
76 
77 
DISCRETE_START(dso_wavlog)78 DISCRETE_START( dso_wavlog )
79 {
80 	int log_num;
81 
82 	log_num = m_device->same_module_index(*this);
83 	sprintf(m_name, "%s_%d.csv", m_device->basetag(), log_num);
84 	m_wavfile = wav_open(m_name, sample_rate(), active_inputs()/2);
85 }
86 
DISCRETE_STOP(dso_wavlog)87 DISCRETE_STOP( dso_wavlog )
88 {
89 	/* close any wave files */
90 	if (m_wavfile)
91 		wav_close(m_wavfile);
92 }
93 
DISCRETE_STEP(dso_wavlog)94 DISCRETE_STEP( dso_wavlog )
95 {
96 	double val;
97 	int16_t wave_data_l, wave_data_r;
98 
99 	/* Dump any wave logs */
100 	/* get nodes to be logged and apply gain, then clip to 16 bit */
101 	val = DISCRETE_INPUT(0) * DISCRETE_INPUT(1);
102 	val = (val < -32768) ? -32768 : (val > 32767) ? 32767 : val;
103 	wave_data_l = (int16_t)val;
104 	if (this->active_inputs() == 2)
105 	{
106 		/* DISCRETE_WAVLOG1 */
107 		wav_add_data_16(m_wavfile, &wave_data_l, 1);
108 	}
109 	else
110 	{
111 		/* DISCRETE_WAVLOG2 */
112 		val = DISCRETE_INPUT(2) * DISCRETE_INPUT(3);
113 		val = (val < -32768) ? -32768 : (val > 32767) ? 32767 : val;
114 		wave_data_r = (int16_t)val;
115 
116 		wav_add_data_16lr(m_wavfile, &wave_data_l, &wave_data_r, 1);
117 	}
118 }
119 
DISCRETE_RESET(dso_wavlog)120 DISCRETE_RESET( dso_wavlog )
121 {
122 	this->step();
123 }
124