[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [288] trunk/fuse
Brought to you by:
fredm
|
From: <fr...@us...> - 2007-01-09 21:02:26
|
Revision: 288
http://svn.sourceforge.net/fuse-for-macosx/?rev=288&view=rev
Author: fredm
Date: 2007-01-09 13:02:14 -0800 (Tue, 09 Jan 2007)
Log Message:
-----------
Fix distorted AY sound on snapshot load.
Modified Paths:
--------------
trunk/fuse/fuse.cpp
trunk/fuse/fuse.h
trunk/fuse/machine.c
trunk/fuse/sound.c
trunk/fuse/sound.h
trunk/fuse/tape.c
Modified: trunk/fuse/fuse.cpp
===================================================================
--- trunk/fuse/fuse.cpp 2007-01-09 21:00:00 UTC (rev 287)
+++ trunk/fuse/fuse.cpp 2007-01-09 21:02:14 UTC (rev 288)
@@ -94,12 +94,6 @@
/* Is Spectrum emulation currently paused, and if so, how many times? */
int fuse_emulation_paused;
-/* Are we going to try and use the sound card; this differs from
- sound.c:sound_enabled in that this gives a desire, whereas sound_enabled
- is an actual state; when the Spectrum emulation is not running, this
- stores whether we try to reenable the sound card afterwards */
-int fuse_sound_in_use;
-
/* The creator information we'll store in file formats that support this */
libspectrum_creator *fuse_creator;
@@ -245,16 +239,6 @@
z80_init();
- fuse_sound_in_use = 0;
- if( settings_current.sound && settings_current.emulation_speed == 100 )
- sound_init( settings_current.sound_device );
-
- if( sound_enabled ) {
- fuse_sound_in_use = 1;
- } else {
- settings_current.sound = 0;
- }
-
if( timer_init() ) return 1;
error = timer_estimate_reset(); if( error ) return error;
@@ -431,43 +415,6 @@
"--version Print version number and exit.\n\n" );
}
-/* Start sound output */
-void
-fuse_sound_enable(void)
-{
- /* No sound if fastloading in progress */
- if( settings_current.fastload && tape_is_playing() ) return;
-
- /* If we now want sound, enable it */
- if( settings_current.sound && settings_current.emulation_speed == 100 ) {
-
- sound_init( settings_current.sound_device );
- sound_ay_reset();
-
- /* If the sound code couldn't re-initialise, fall back to the
- signal based routines */
- if( !sound_enabled ) {
- /* Increment pause_count, report, decrement pause_count
- * (i.e. avoid the effects of fuse_emulation_{,un}pause).
- * Otherwise, we may be recursively reporting this error. */
- fuse_emulation_paused++;
- fuse_emulation_paused--;
- settings_current.sound = fuse_sound_in_use = 0;
-
- }
- fuse_sound_in_use = sound_enabled;
- } else if( fuse_sound_in_use ) {
- fuse_sound_in_use = 0;
- }
-}
-
-/* Stop sound output */
-void
-fuse_sound_disable(void)
-{
- if( sound_enabled ) sound_end();
-}
-
/* Stop all activities associated with actual Spectrum emulation */
int fuse_emulation_pause(void)
{
@@ -485,7 +432,7 @@
/* If we had sound enabled (and hence doing the speed regulation),
turn it off */
- if( sound_enabled ) sound_end();
+ sound_pause();
return 0;
}
@@ -499,11 +446,12 @@
decrement the pause count */
if( --fuse_emulation_paused ) return 0;
+ /* If we now want sound, enable it */
+ sound_unpause();
+
/* Restart speed estimation with no information */
error = timer_estimate_reset(); if( error ) return error;
- fuse_sound_enable();
-
return 0;
}
Modified: trunk/fuse/fuse.h
===================================================================
--- trunk/fuse/fuse.h 2007-01-09 21:00:00 UTC (rev 287)
+++ trunk/fuse/fuse.h 2007-01-09 21:02:14 UTC (rev 288)
@@ -43,13 +43,8 @@
int fuse_emulation_pause(void); /* Stop and start emulation */
int fuse_emulation_unpause(void);
-void fuse_sound_enable(); /* Start sound output */
-void fuse_sound_disable(); /* Stop sound output */
-
void fuse_abort( void ) GCC_NORETURN; /* Emergency shutdown */
-extern int fuse_sound_in_use; /* Are we trying to produce sound? */
-
extern libspectrum_creator *fuse_creator; /* Creator information for file
formats which support this */
Modified: trunk/fuse/machine.c
===================================================================
--- trunk/fuse/machine.c 2007-01-09 21:00:00 UTC (rev 287)
+++ trunk/fuse/machine.c 2007-01-09 21:02:14 UTC (rev 288)
@@ -256,6 +256,8 @@
if( event_add( machine->timings.tstates_per_frame, EVENT_TYPE_FRAME ) )
return 1;
+ sound_end();
+
if( uidisplay_end() ) return 1;
capabilities = libspectrum_machine_capabilities( machine->machine );
@@ -271,6 +273,8 @@
if( uidisplay_init( width, height ) ) return 1;
+ sound_init( settings_current.sound_device );
+
/* Mark RAM as not-present/read-only. The machine's reset function will
* mark available pages as present/writeable.
*/
@@ -385,8 +389,6 @@
/* These things should happen on all resets */
z80_reset();
- /* sound_ay_reset() *absolutely must* be called before either
- sound_frame() or sound_ay_write() */
sound_ay_reset();
printer_zxp_reset();
Modified: trunk/fuse/sound.c
===================================================================
--- trunk/fuse/sound.c 2007-01-09 21:00:00 UTC (rev 287)
+++ trunk/fuse/sound.c 2007-01-09 21:02:14 UTC (rev 288)
@@ -44,13 +44,13 @@
#include "settings.h"
#include "sound.h"
#include "sound/lowlevel.h"
+#include "tape.h"
#include "ui/ui.h"
/* Do we have any of our sound devices available? */
/* configuration */
-int sound_enabled=0; /* Are we currently using the sound card;
- cf fuse.c:fuse_sound_in_use */
+int sound_enabled=0; /* Are we currently using the sound card */
int sound_enabled_ever=0; /* if it's *ever* been in use; see
sound_ay_write() and sound_ay_reset() */
int sound_stereo=0; /* true for stereo *output sample* (only) */
@@ -147,10 +147,6 @@
for(f=0;f<3;f++)
ay_tone_tick[f]=ay_tone_high[f]=0,ay_tone_period[f]=1;
-ay_tick_incr=(int)(65536.*
- libspectrum_timings_ay_speed(machine_current->machine)/
- settings_current.sound_freq);
-
ay_change_count=0;
}
@@ -159,20 +155,19 @@
{
static int first_init=1;
int f,ret;
-int sound_max_framesiz;
+float hz;
/* if we don't have any sound I/O code compiled in, don't do sound */
#ifndef HAVE_SOUND
return;
#endif
-if(sound_enabled)
- {
- ui_error(UI_ERROR_ERROR,
- "sound_init() called with sound_enabled set, can't happen!" );
- sound_end();
+/* sound_enabled can be set here if we are in the SDL UI and have start
+ machine set, or if we have a snapshot set at the command line on
+ program start */
+if( !(!sound_enabled && settings_current.sound &&
+ settings_current.emulation_speed == 100) )
return;
- }
sound_stereo_ay=settings_current.stereo_ay;
sound_stereo_beeper=settings_current.stereo_beeper;
@@ -199,11 +194,15 @@
sound_enabled=sound_enabled_ever=1;
sound_channels=(sound_stereo?2:1);
-sound_max_framesiz=settings_current.sound_freq/50;
+hz = (float)machine_current->timings.processor_speed /
+ machine_current->timings.tstates_per_frame;
+
+sound_framesiz = settings_current.sound_freq / hz;
+
if((sound_buf=malloc(sizeof(libspectrum_signed_word)*
- sound_max_framesiz*sound_channels))==NULL ||
- (tape_buf=malloc(sizeof(libspectrum_signed_word)*sound_max_framesiz))==NULL)
+ sound_framesiz*sound_channels))==NULL ||
+ (tape_buf=malloc(sizeof(libspectrum_signed_word)*sound_framesiz))==NULL)
{
if(sound_buf)
{
@@ -258,10 +257,39 @@
rchan2pos=pos,rchan3pos=0;
}
-fuse_sound_in_use=1;
+ay_tick_incr=(int)(65536.*
+ libspectrum_timings_ay_speed(machine_current->machine)/
+ settings_current.sound_freq);
}
+void sound_pause(void)
+{
+if(sound_enabled) sound_end();
+}
+
+
+void sound_unpause(void)
+{
+/* No sound if fastloading in progress */
+if( settings_current.fastload && tape_is_playing() ) return;
+
+sound_init( settings_current.sound_device );
+
+/* If the sound code couldn't re-initialise, fall back to the
+ signal based routines */
+if(!sound_enabled)
+ {
+ /* Increment pause_count, report, decrement pause_count
+ * (i.e. avoid the effects of fuse_emulation_{,un}pause).
+ * Otherwise, we may be recursively reporting this error. */
+ fuse_emulation_paused++;
+ fuse_emulation_paused--;
+ settings_current.sound = 0;
+ }
+}
+
+
void sound_end(void)
{
if(sound_enabled)
@@ -605,11 +633,6 @@
*/
void sound_ay_write(int reg,int val,libspectrum_dword now)
{
-/* have to allow it across pauses for snap-loading to work,
- * so see if sound has *ever* been enabled.
- */
-if(!sound_enabled_ever) return;
-
if(ay_change_count<AY_CHANGE_MAX)
{
ay_change[ay_change_count].tstates=now;
@@ -626,11 +649,7 @@
void sound_ay_reset(void)
{
int f;
-float hz = 50;
-/* as above... */
-if(!sound_enabled_ever) return;
-
/* recalculate timings based on new machines ay clock */
sound_ay_init();
@@ -640,11 +659,6 @@
for(f=0;f<3;f++)
ay_tone_high[f]=0;
ay_tone_subcycles=ay_env_subcycles=0;
-
-hz = (float)machine_current->timings.processor_speed /
- machine_current->timings.tstates_per_frame;
-
-sound_framesiz = settings_current.sound_freq / hz;
}
Modified: trunk/fuse/sound.h
===================================================================
--- trunk/fuse/sound.h 2007-01-09 21:00:00 UTC (rev 287)
+++ trunk/fuse/sound.h 2007-01-09 21:02:14 UTC (rev 288)
@@ -30,6 +30,8 @@
#include <libspectrum.h>
void sound_init( const char *device );
+void sound_pause( void );
+void sound_unpause( void );
void sound_end( void );
void sound_ay_write( int reg, int val, libspectrum_dword now );
void sound_ay_reset( void );
Modified: trunk/fuse/tape.c
===================================================================
--- trunk/fuse/tape.c 2007-01-09 21:00:00 UTC (rev 287)
+++ trunk/fuse/tape.c 2007-01-09 21:02:14 UTC (rev 288)
@@ -600,7 +600,7 @@
sound_beeper( 1, tape_microphone );
/* If we're fastloading, turn sound off */
- if( settings_current.fastload ) fuse_sound_disable();
+ if( settings_current.fastload ) sound_pause();
loader_tape_play();
@@ -639,7 +639,7 @@
/* If we were fastloading, sound was off, so turn it back on, and
reset the speed counter */
if( settings_current.fastload ) {
- fuse_sound_enable();
+ sound_unpause();
timer_estimate_reset();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|