User avatar
Parduz
Posts: 4
Joined: Thu Dec 08, 2022 2:12 pm
Location: Bologna, Italy

es5506 driver: write to wav file is broken, Help?

I'm trying to save the output of the Ensoniq SQ1 (es5505.cpp) on a wav file,
I knew that the es5506 driver has an define to do that; while the code under #if ES5506_MAKE_WAVS is still there, it can't compile.
I've updated the include wavwrite.h, changed the funtions in util:: ---, but now there are errors about variables not declared or casting errors.

I've spent three full days of vacation on making the emulated SQ1 workable, in order to be able to save wavs of the output, and now i can't do it :(

Understanding how to fix that part of code is WAAAAY beyond my skills: there's someone which could make it works again?

Thanks
User avatar
Parduz
Posts: 4
Joined: Thu Dec 08, 2022 2:12 pm
Location: Bologna, Italy

Re: es5506 driver: write to wav file is broken, Help?

What am i doing wrong?

esq5505.h

Code: Select all

#if ES5506_MAKE_WAVS
 #include"wavwrite.h"
#endif
[...]
#if ES5506_MAKE_WAVS
	std::vector<s32> wav_l;
	std::vector<s32> wav_r;
	util::wav_file   *m_wavraw;                 // raw waveform
#endif
[...]
--

esq5505.cpp

Code: Select all

[...]
void es5505_device::generate_samples(std::vector<write_stream_view> &outputs)
{
	#if ES5506_MAKE_WAVS
	int numsamples = outputs[0].samples();
	if (m_wavraw) {
		printf ("* ");
	}
	#endif
	[...]
	#if ES5506_MAKE_WAVS
		if (m_wavraw) { // if file is open
			printf ("r ");
			s32 l=0; 
			s32 r=0; 
			for (int samp = 0; samp<12; samp++) {
				// read all the 12 currsample and sum them
				l += cursample[samp++];
				r += cursample[samp  ];
			}
			wav_l.push_back(l);
			wav_r.push_back(r);
		}
	#endif
	[...]
	#if ES5506_MAKE_WAVS
	if (m_wavraw) { // if file is open
		printf ("s%lld-%lld-%d ", wav_l.size(), wav_r.size(), numsamples );
		if (wav_l.size()>=100 || wav_r.size() >=100) {
			printf ("w " );
			util::wav_add_data_32lr(*m_wavraw, wav_l.data(), wav_r.data(), wav_l.size(), 4);
			// resize dynamic array - don't want it to copy if it needs to expand
			wav_l.clear();
			wav_l.resize(1,0);
			wav_r.clear();
			wav_r.resize(1,0);
			printf ("! ");
		}
	}
	#endif
}

void es550x_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
	#if ES5506_MAKE_WAVS
	// start the logging once we have a sample rate
	if (m_sample_rate)
	{
		if (!m_wavraw) 
		{
			m_wavraw = util::wav_open("raw.wav", m_sample_rate, 2).get();
			if (!m_wavraw) {
				util::stream_format(std::cerr, "Wav file open ERROR (%p) \n", m_wavraw);
			}else{
				printf("\n\n-_-_-_- WAV OPENED (%p)-_-_-_-\n",m_wavraw);
				wav_l.clear();
				wav_l.resize(1,0);
				wav_r.clear();
				wav_r.resize(1,0);
				printf ("^ ");
			}
		}else{
			printf ("> ");
		}
	}
	#endif

	// loop until all samples are output
	generate_samples(outputs);

	#if ES5506_MAKE_WAVS
	printf ("<\n");
	#endif
}
--

OUTPUT:

Code: Select all

[MINGW64] F:\MameDev\msys64\src\mame>sq1


-_-_-_- WAV OPENED (000002285f3e1310)-_-_-_-
^ * r s2-2-1 <
> * r s3-3-1 <
> * r s4-4-1 <
> * r s5-5-1 <
> * r s6-6-1 <
> * r s7-7-1 <
> * r s8-8-1 <
> * r s9-9-1 <
> * r s10-10-1 <
> * r s11-11-1 <
> * r s12-12-1 <
> * r s13-13-1 <
> * r s14-14-1 <
> * r s15-15-1 <
> * r s16-16-1 <
> * r s17-17-1 <
> * r s18-18-1 <
> * r s19-19-1 <
> * r s20-20-1 <
> * r s21-21-1 <
> * r s22-22-1 <
> * r s23-23-1 <
> * r s24-24-1 <
> * r s25-25-1 <
> * r s26-26-1 <
> * r s27-27-1 <
> * r s28-28-1 <
> * r s29-29-1 <
> * r s30-30-1 <
> * r s31-31-1 <
> * r s32-32-1 <
> * r s33-33-1 <
> * r s34-34-1 <
> * r s35-35-1 <
> * r s36-36-1 <
> * r s37-37-1 <
> * r s38-38-1 <
> * r s39-39-1 <
> * r s40-40-1 <
> * r s41-41-1 <
> * r s42-42-1 <
> * r s43-43-1 <
> * r s44-44-1 <
> * r s45-45-1 <
> * r s46-46-1 <
> * r s47-47-1 <
> * r s48-48-1 <
> * r s49-49-1 <
> * r s50-50-1 <
> * r s51-51-1 <
> * r s52-52-1 <
> * r s53-53-1 <
> * r s54-54-1 <
> * r s55-55-1 <
> * r s56-56-1 <
> * r s57-57-1 <
> * r s58-58-1 <
> * r s59-59-1 <
> * r s60-60-1 <
> * r s61-61-1 <
> * r s62-62-1 <
> * r s63-63-1 <
> * r s64-64-1 <
> * r s65-65-1 <
> * r s66-66-1 <
> * r s67-67-1 <
> * r s68-68-1 <
> * r s69-69-1 <
> * r s70-70-1 <
> * r s71-71-1 <
> * r s72-72-1 <
> * r s73-73-1 <
> * r s74-74-1 <
> * r s75-75-1 <
> * r s76-76-1 <
> * r s77-77-1 <
> * r s78-78-1 <
> * r s79-79-1 <
> * r s80-80-1 <
> * r s81-81-1 <
> * r s82-82-1 <
> * r s83-83-1 <
> * r s84-84-1 <
> * r s85-85-1 <
> * r s86-86-1 <
> * r s87-87-1 <
> * r s88-88-1 <
> * r s89-89-1 <
> * r s90-90-1 <
> * r s91-91-1 <
> * r s92-92-1 <
> * r s93-93-1 <
> * r s94-94-1 <
> * r s95-95-1 <
> * r s96-96-1 <
> * r s97-97-1 <
> * r s98-98-1 <
> * r s99-99-1 <
> * r s100-100-1 w
-----------------------------------------------------
Exception at EIP=00007ff796de2da2 (not found): ACCESS VIOLATION
While attempting to read memory at ffffffffffffffff
-----------------------------------------------------
RAX=e6df6878f9697b76 RBX=00000000000000c8 RCX=0000000000000000 RDX=32412f37442d3244
RSI=0000000000000000 RDI=000002285f3e1318 RBP=0000000000000000 RSP=000000c1bcff93d0
 R8=0000022855f990a0  R9=0000000000000064 R10=0000000000000000 R11=0000000000000246
R12=0000000000000004 R13=32412f37442d3244 R14=00000000000000c8 R15=000002285601b0e0
-----------------------------------------------------
Stack crawl:
  000000c1bcff9430: 00007ff796de2da2 (not found)
  000000c1bcff9490: 00007ff794e638fc (not found)
  000000c1bcff95c0: 00007ff794aa7a87 (not found)
  000000c1bcff9680: 00007ff794aa816f (not found)
  000000c1bcff9770: 00007ff794c0af1b (not found)
  000000c1bcff9810: 00007ff794c0a9ad (not found)
  000000c1bcff9900: 00007ff794c0ae48 (not found)
  000000c1bcff99b0: 00007ff794c0b87f (not found)
  000000c1bcff9a20: 00007ff794bee13b (not found)
  000000c1bcff9ba0: 00007ff794ba0698 (not found)
  000000c1bcfff030: 00007ff7950aa36b (not found)
  000000c1bcfff420: 00007ff795146a76 (not found)
  000000c1bcfff700: 00007ff79514709b (not found)
  000000c1bcfff760: 00007ff7950a4aa9 (not found)
  000000c1bcfffb30: 00007ff796e9f287 (not found)
  000000c1bcfffc00: 00007ff7949e13b1 (not found)
  000000c1bcfffc30: 00007ff7949e14e6 (not found)
  000000c1bcfffc60: 00007ffc2d2474b4 (BaseThreadInitThunk+0x0014)
  000000c1bcfffce0: 00007ffc2dc226a1 (RtlUserThreadStart+0x0021)

[MINGW64] F:\MameDev\msys64\src\mame>
Why the error at writing the data to file?
What am i doing wrong?

Return to “MAME Discussion”