Beispiel #1
0
int main(int argc, char *argv[])
{
    const char bar_length=50;
    dro_status drost;
    const char spin[]="-\\|/";
    int spin_index=0;
    int i;

    SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER);
    sound_init();
    start_opl_emulation();

    dro_load(data,data_length);
    dro_play(2);
    do
    {
        dro_get_status(&drost);
        printf("%c[",spin[spin_index]);
        for(i=0; i<bar_length-3; i++)
        {
            if (i<((float)drost.position/drost.length)*(bar_length-3)) printf("=");
            else printf(".");
        }
        printf("]\r");
        fflush(stdout);
        usleep(100000);
        spin_index=(spin_index+1) % 4;
    } while(drost.playing);
    usleep(1000000);

    dro_stop();
    sound_end();
    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    uint8_t *hsc;
    uint32_t lp;
    hsc=hsc_load("TECHNO.HSC");
    if(hsc==NULL)
    {
        printf("lostship.hsc not found. \n");
        return 3;
    }
    SDL_Init(SDL_INIT_AUDIO | SDL_INIT_TIMER);
    sound_init();
    start_opl_emulation();

    hsc_play(hsc,1);
    while(hsc_get_status())
    {
        if(lp!=hsc_get_pattpos())
        {
            printf("status - %d; pos - %d; pattpos - %d                       \r",hsc_get_status(),hsc_get_pos(),hsc_get_pattpos());
            lp=hsc_get_pattpos();
            fflush(stdout);
            usleep(100000);
        }
    }
    
    sound_end();
    return 0;
}
Beispiel #3
0
static int
machine_select_machine( fuse_machine_info *machine )
{
  int width, height, i;
  int capabilities;

  machine_current = machine;

  settings_set_string( &settings_current.start_machine, machine->id );
  
  tstates = 0;

  /* Reset the event stack */
  event_reset();
  if( event_add( 0, timer_event ) ) return 1;
  if( event_add( machine->timings.tstates_per_frame, spectrum_frame_event ) )
    return 1;

  sound_end();

  if( uidisplay_end() ) return 1;

  capabilities = libspectrum_machine_capabilities( machine->machine );

  /* Set screen sizes here */
  if( capabilities & LIBSPECTRUM_MACHINE_CAPABILITY_TIMEX_VIDEO ) {
    width = DISPLAY_SCREEN_WIDTH;
    height = 2*DISPLAY_SCREEN_HEIGHT;
  } else {
    width = DISPLAY_ASPECT_WIDTH;
    height = DISPLAY_SCREEN_HEIGHT;
  }

  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.
   */
  for( i = 0; i < 2 * SPECTRUM_RAM_PAGES; i++ )
    memory_map_ram[i].writable = 0;

  /* Do a hard reset */
  if( machine_reset( 1 ) ) return 1;

  /* And the dock menu item */
  if( capabilities & LIBSPECTRUM_MACHINE_CAPABILITY_TIMEX_DOCK ) {
    ui_menu_activate( UI_MENU_ITEM_MEDIA_CARTRIDGE_DOCK_EJECT, 0 );
  }

  /* Reset any dialogue boxes etc. which contain machine-dependent state */
  ui_widgets_reset();

  return 0;
}
static int
machine_select_machine( fuse_machine_info *machine )
{
  int width, height;
  int capabilities;

  machine_current = machine;

  settings_set_string( &settings_current.start_machine, machine->id );
  
  tstates = 0;

  /* Reset the event stack */
  event_reset();
  event_add( 0, timer_event );
  event_add( machine->timings.tstates_per_frame, spectrum_frame_event );

  sound_end();

  if( uidisplay_end() ) return 1;

  capabilities = libspectrum_machine_capabilities( machine->machine );

  /* Set screen sizes here */
  if( capabilities & LIBSPECTRUM_MACHINE_CAPABILITY_TIMEX_VIDEO ) {
    width = DISPLAY_SCREEN_WIDTH;
    height = 2*DISPLAY_SCREEN_HEIGHT;
  } else {
    width = DISPLAY_ASPECT_WIDTH;
    height = DISPLAY_SCREEN_HEIGHT;
  }

  if( uidisplay_init( width, height ) ) return 1;

  sound_init( settings_current.sound_device );

  /* Do a hard reset */
  if( machine_reset( 1 ) ) return 1;

  /* And the dock menu item */
  if( capabilities & LIBSPECTRUM_MACHINE_CAPABILITY_TIMEX_DOCK ) {
    ui_menu_activate( UI_MENU_ITEM_MEDIA_CARTRIDGE_DOCK_EJECT, 0 );
  }

  /* Reset any dialogue boxes etc. which contain machine-dependent state */
  ui_widgets_reset();

  return 0;
}
Beispiel #5
0
int main(int argc,char *argv[])
{
char *ptr;

progname=argv[0]?argv[0]:"aylet";
if((ptr=strrchr(progname,'/'))!=NULL)
  progname=ptr+1;

parseoptions(argc,argv);

if(list_only)
  {
  do_list();
  exit(0);
  }

/* even when not using curses/GTK+ we go via the UI code
 * (apart from the above :-)).
 */
ui_init(argc,argv);

if(!sound_init())
  {
  ui_end();
  fprintf(stderr,"%s: couldn't open sound device.\n",progname);
  exit(1);
  }

mainloop();

if(sound_enabled)
  sound_end();

ui_end();

exit(0);
}
Beispiel #6
0
static int
sound_init_blip( Blip_Buffer **buf, Blip_Synth **synth )
{
  *buf = new_Blip_Buffer();
  blip_buffer_set_clock_rate( *buf, sound_get_effective_processor_speed() );
  /* Allow up to 1s of playback buffer - this allows us to cope with slowing
     down to 2% of speed where a single Speccy frame generates just under 1s
     of sound */
  if ( blip_buffer_set_sample_rate( *buf, settings_current.sound_freq, 1000 ) ) {
    sound_end();
    ui_error( UI_ERROR_ERROR, "out of memory at %s:%d", __FILE__, __LINE__ );
    return 0;
  }

  *synth = new_Blip_Synth();

  blip_synth_set_volume( *synth, sound_get_volume( settings_current.volume_beeper ) );
  blip_synth_set_output( *synth, *buf );

  blip_buffer_set_bass_freq( *buf, speaker_type[ option_enumerate_sound_speaker_type() ].bass );
  blip_synth_set_treble_eq( *synth, speaker_type[ option_enumerate_sound_speaker_type() ].treble );

  return 1;
}
Beispiel #7
0
static void
sound_resample( void )
{
  int error;
  SRC_DATA data;

  data.data_in = convert_input_buffer;
  data.input_frames = sound_generator_framesiz;
  data.data_out = convert_output_buffer;
  data.output_frames = sound_framesiz;
  data.src_ratio =
    ( double ) settings_current.sound_freq / sound_generator_freq;
  data.end_of_input = 0;

  src_short_to_float_array( ( const short * ) sound_buf, convert_input_buffer,
			    sound_generator_framesiz * sound_channels );

  while( data.input_frames ) {
    error = src_process( src_state, &data );
    if( error ) {
      ui_error( UI_ERROR_ERROR, "hifi sound downsample error %s",
		src_strerror( error ) );
      sound_end(_this);
      return;
    }

    src_float_to_short_array( convert_output_buffer, ( short * ) sound_buf,
			      data.output_frames_gen * sound_channels );

    sound_lowlevel_frame( sound_buf,
			  data.output_frames_gen * sound_channels );

    data.data_in += data.input_frames_used * sound_channels;
    data.input_frames -= data.input_frames_used;
  }
}
Beispiel #8
0
void
sound_pause( void )
{
  if( sound_enabled )
    sound_end();
}
Beispiel #9
0
static void sound_init( CAY8910 *_this, const char *device, unsigned long nSampleRate )
{
//  static int first_init = 1;
//  int f, ret;
  float hz;
#ifdef HAVE_SAMPLERATE
  int error;
#endif /* #ifdef HAVE_SAMPLERATE */

/* if we don't have any sound I/O code compiled in, don't do sound */
#ifdef NO_SOUND
  return;
#endif

#if 0
  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;

/* only try for stereo if we need it */
  if( sound_stereo_ay || sound_stereo_beeper )
    sound_stereo = 1;
  ret =
    sound_lowlevel_init( device, &settings_current.sound_freq,
			 &sound_stereo );
  if( ret )
    return;
#endif

#if 0
/* important to override these settings if not using stereo
 * (it would probably be confusing to mess with the stereo
 * settings in settings_current though, which is why we make copies
 * rather than using the real ones).
 */
  if( !sound_stereo ) {
    sound_stereo_ay = 0;
    sound_stereo_beeper = 0;
  }

  sound_enabled = sound_enabled_ever = 1;

  sound_channels = ( sound_stereo ? 2 : 1 );
#endif
  sound_channels = 3;	// 3 mono channels: ABC

//  hz = ( float ) machine_current->timings.processor_speed /
//    machine_current->timings.tstates_per_frame;
  hz = HZ_COMMON_DENOMINATOR;

//  sound_generator_freq =
//    settings_current.sound_hifi ? HIFI_FREQ : settings_current.sound_freq;
  sound_generator_freq = nSampleRate;
  sound_generator_framesiz = sound_generator_freq / (int)hz;

#if 0
  if( ( sound_buf = (libspectrum_signed_word*) malloc( sizeof( libspectrum_signed_word ) *
			    sound_generator_framesiz * sound_channels ) ) ==
      NULL
      || ( tape_buf =
	   malloc( sizeof( libspectrum_signed_word ) *
		   sound_generator_framesiz ) ) == NULL ) {
    if( sound_buf ) {
      free( sound_buf );
      sound_buf = NULL;
    }
    sound_end(_this);
    return;
  }
#endif

//  sound_framesiz = ( float ) settings_current.sound_freq / hz;
  sound_framesiz = sound_generator_freq / (int)hz;

#ifdef HAVE_SAMPLERATE
  if( settings_current.sound_hifi ) {
    if( ( convert_input_buffer = malloc( sizeof( float ) *
					 sound_generator_framesiz *
					 sound_channels ) ) == NULL
	|| ( convert_output_buffer =
	     malloc( sizeof( float ) * sound_framesiz * sound_channels ) ) ==
	NULL ) {
      if( convert_input_buffer ) {
	free( convert_input_buffer );
	convert_input_buffer = NULL;
      }
      sound_end(_this);
      return;
    }
  }

  src_state = src_new( SRC_SINC_MEDIUM_QUALITY, sound_channels, &error );
  if( error ) {
    ui_error( UI_ERROR_ERROR,
	      "error initialising sample rate converter %s",
	      src_strerror( error ) );
    sound_end(_this);
    return;
  }
#endif /* #ifdef HAVE_SAMPLERATE */

/* if we're resuming, we need to be careful about what
 * gets reset. The minimum we can do is the beeper
 * buffer positions, so that's here.
 */
#if 0
  sound_oldpos[0] = sound_oldpos[1] = -1;
  sound_fillpos[0] = sound_fillpos[1] = 0;
#endif

/* this stuff should only happen on the initial call.
 * (We currently assume the new sample rate will be the
 * same as the previous one, hence no need to recalculate
 * things dependent on that.)
 */
#if 0
  if( first_init ) {
    first_init = 0;

    for( f = 0; f < 2; f++ )
      sound_oldval[f] = sound_oldval_orig[f] = 0;
  }
#endif

#if 0
  if( sound_stereo_beeper ) {
    for( f = 0; f < STEREO_BUF_SIZE; f++ )
      pstereobuf[f] = 0;
    pstereopos = 0;
    pstereobufsiz = ( sound_generator_freq * psgap ) / 22000;
  }

  if( sound_stereo_ay ) {
    int pos =
      ( sound_stereo_ay_narrow ? 3 : 6 ) * sound_generator_freq / 8000;

    for( f = 0; f < STEREO_BUF_SIZE; f++ )
      rstereobuf_l[f] = rstereobuf_r[f] = 0;
    rstereopos = 0;

    /* the actual ACB/ABC bit :-) */
    rchan1pos = -pos;
    if( sound_stereo_ay_abc )
      rchan2pos = 0, rchan3pos = pos;
    else
      rchan2pos = pos, rchan3pos = 0;
  }
#endif

#if 0
  ay_tick_incr = ( int ) ( 65536. *
			   libspectrum_timings_ay_speed( machine_current->
							 machine ) /
			   sound_generator_freq );
#endif
  _this->ay_tick_incr = ( int ) ( 65536. * m_fCurrentCLK_AY8910 / sound_generator_freq );	// [TC]
}
Beispiel #10
0
/* read a file and play it. sound_init() should already have been called,
 * and sound device should still be open when we exit.
 */
void mainloop(void)
{
int oldfile=-1;

aydata.filedata=NULL;
aydata.tracks=NULL;

/* this is kind of a weird multi-level event loop (if
 * you consider do_interrupt()); it's difficult to do it very
 * differently without turning the Z80 emulation inside-out.
 */
while(!want_quit)
  {
  /* load a new file if we need to */
  if(ay_file!=oldfile)
    {
    if(aydata.tracks) free(aydata.tracks);
    if(aydata.filedata) free(aydata.filedata);
    
    if(!read_ay_file(ay_filenames[ay_file]))
      {
      ui_end();
      if(sound_enabled) sound_end();
      fprintf(stderr,"%s: reading `%s' failed.\n",
              progname,ay_filenames[ay_file]);
      exit(1);
      }

    if(!play_one_track_only)
      ay_track=0;
    else
      {
      ay_track=play_one_track_only-1;
      
      if(ay_track>=aydata.num_tracks)
        {
        ui_end();
        if(sound_enabled) sound_end();
        fprintf(stderr,"%s: `%s' has only %d track%s.\n",
                progname,ay_filenames[ay_file],
                aydata.num_tracks,(aydata.num_tracks==1)?"":"s");
        exit(1);
        }
      }

    if(go_to_last)
      {
      go_to_last=0;
      ay_track=aydata.num_tracks-1;
      }
    }
  
  oldfile=ay_file;

  /* only do the whole emulation thing if we're actually playing... */
  if(playing)
    {
    /* re-enable sound after stopping, if needed */
    if(!sound_enabled && !sound_init())
      {
      ui_end();
      fprintf(stderr,"%s: couldn't reopen sound device.\n",progname);
      exit(1);
      }
  
    ay_current_reg=0;
    sound_ay_reset();
    mem_init(ay_track);
    tunetime_reset();
    tsmax=FRAME_STATES_128;
    do_cpc=0;
    z80loop(aydata.tracks[ay_track].data,
            aydata.tracks[ay_track].data_stacketc);
    }

  /* if stopped, close sound device */
  if(sound_enabled && !playing)
    sound_end();
  
  /* do reset now, so any paused/stopped status time makes sense */
  tunetime_reset();
  while((!playing || paused) && ay_file==oldfile)
    do_interrupt();
  }

free(aydata.tracks);
free(aydata.filedata);
}