Page 2 of 2

Posted: Tue Aug 31, 2010 7:38 pm
by counterp
HOLD ON A DAMN SECOND.

It appears I was reading them the wrong way. I set the buffer size to each spc's compressed file size instead of actual size.... :?

But now i just get 'emulation error' when I try to play a spc file.

Code: Select all

	protected int play_( byte out [], int count )
	{
		dsp.setOutput( out );
		
		// Run for count/2*32 clocks + extra to get DSP time half-way between samples,
		// since CPU might run for slightly less than requested
		int clockCount = count * (32 / 2) + 16 - ((time - dspTime) & 31);
		time            -= clockCount;
		dspTime         -= clockCount;
		timers [0].time -= clockCount;
		timers [1].time -= clockCount;
		timers [2].time -= clockCount;
		runCpu();
		
		if ( time < 0 ) // emulation error
		{
			logError();
			return 0;
		}
		
		// Catch up to CPU
		runTimer( timers [0], time );
		runTimer( timers [1], time );
		runTimer( timers [2], time );
		
		// Run DSP to present
		int delta;
		if ( (delta = time - dspTime) >= 0 )
		{
			delta = (delta >> 5) + 1;
			dspTime += delta << 5;
			dsp.run( delta );
		}
		
		assert dsp.sampleCount() == count;
		return dsp.sampleCount();
	}

Code: Select all

	public void run()
	{
		line.start();
		
		// play track until stop signal
		byte [] buf = new byte [8192];
		while ( playing_ && !emu.trackEnded() )
		{
			int count = emu.play( buf, buf.length / 2 );
			line.write( buf, 0, count * 2 );
			idle();
		}
		
		playing_ = false;
		line.stop();
	}

Posted: Tue Aug 31, 2010 8:18 pm
by blargg
Does the original code play the same SPC file correctly? I think you should be able to give it a URL to the file, of the form file:/// or something like that.

Posted: Wed Sep 01, 2010 5:32 am
by counterp
Hmm yeah it does...

EDIT: Used your method of loading from DataReader class.

Now it works, thanks :D

Only problem is most of the time the sound messes up in the beginning. (Occasionally it doesn't)

EDIT: Sorted that out... Thanks a bunch!

Posted: Wed Sep 01, 2010 2:23 pm
by blargg
Sound messes up at the beginning, I'm curious. Was it some Java sound driver issue? Java was always fairly glitchy on my machine. I ran tests where I fed it a pure sine wave, where my code was almost surely bug-free, yet I still got glitches when starting, sometimes repeated buffers etc.

Posted: Wed Sep 01, 2010 2:42 pm
by counterp
I just run a sound first and cut it off before it actually makes a sound to load all the variables and instantiate classes etc...

EDIT: Using Xcomp argument to fix. So yeah, I was right, it probably just took a bit to load everything. Let me see how this works out later, might switch to Xint or some other method to fix the slow compiling.

Posted: Wed Sep 01, 2010 3:40 pm
by blargg
Nifty solution! I'll have to remember that. You could set the volume to zero and load an SPC and play it for a moment. Maybe that's what you meant.

Posted: Wed Sep 01, 2010 4:11 pm
by counterp
I just play it for 1 ms but now I'm gonna set the volume to 0 anyways thanks. (Assuming using arguments causes problems)

EDIT: Hmm this small fix doesn't seem to work when doing any heavy operations, not just starting up the jvm...

EDIT2: cool, found using a bigger buffer fixed problem (you set to 8192 bytes in the run method of SPCPlayer class or whatever it is called).