int sound_init(void) { if(sound_lowlevel_init(NULL, &sound_freq,&sound_stereo)) { /* XXX a bit vague, maybe I should put this check in sound_init() */ //fprintf(stderr,"z81: warning: " // "couldn't initialise sound device, sound disabled.\n"); return(1); } /* important to override this if not using stereo */ if(!sound_stereo) sound_stereo_acb=0; sound_enabled=1; sound_framesiz=sound_freq/50; if((sound_buf=malloc(sound_framesiz*(sound_stereo+1)))==NULL) { sound_lowlevel_end(); return(1); } sound_oldval=sound_oldval_orig=128; sound_oldpos=-1; sound_fillpos=0; sound_ptr=sound_buf; beeper_tick=0; beeper_tick_incr=(1<<24)/sound_freq; //if(sound_ay) sound_ay_init(); return(0); }
void sound_init( const char *device ) { float hz; double treble; Blip_Synth **ay_left_synth; Blip_Synth **ay_mid_synth; Blip_Synth **ay_mid_synth_r; Blip_Synth **ay_right_synth; /* Allow sound as long as emulation speed is greater than 2% (less than that and a single Speccy frame generates more than a seconds worth of sound which is bigger than the maximum Blip_Buffer of 1 second) */ if( !( !sound_enabled && settings_current.sound && settings_current.emulation_speed > 1 ) ) return; /* only try for stereo if we need it */ sound_stereo_ay = option_enumerate_sound_stereo_ay(); if( settings_current.sound && sound_lowlevel_init( device, &settings_current.sound_freq, &sound_stereo_ay ) ) return; if( !sound_init_blip(&left_buf, &left_beeper_synth) ) return; if( sound_stereo_ay != SOUND_STEREO_AY_NONE && !sound_init_blip(&right_buf, &right_beeper_synth) ) return; treble = speaker_type[ option_enumerate_sound_speaker_type() ].treble; ay_a_synth = new_Blip_Synth(); blip_synth_set_volume( ay_a_synth, sound_get_volume( settings_current.volume_ay) ); blip_synth_set_treble_eq( ay_a_synth, treble ); ay_b_synth = new_Blip_Synth(); blip_synth_set_volume( ay_b_synth, sound_get_volume( settings_current.volume_ay) ); blip_synth_set_treble_eq( ay_b_synth, treble ); ay_c_synth = new_Blip_Synth(); blip_synth_set_volume( ay_c_synth, sound_get_volume( settings_current.volume_ay) ); blip_synth_set_treble_eq( ay_c_synth, treble ); left_specdrum_synth = new_Blip_Synth(); blip_synth_set_volume( left_specdrum_synth, sound_get_volume( settings_current.volume_specdrum ) ); blip_synth_set_output( left_specdrum_synth, left_buf ); blip_synth_set_treble_eq( left_specdrum_synth, treble ); /* 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). */ ay_a_synth_r = NULL; ay_b_synth_r = NULL; ay_c_synth_r = NULL; if( sound_stereo_ay != SOUND_STEREO_AY_NONE ) { /* Attach the Blip_Synth's we've already created as appropriate, and * create one more Blip_Synth for the middle channel's right buffer. */ if( sound_stereo_ay == SOUND_STEREO_AY_ACB ) { ay_left_synth = &ay_a_synth; ay_mid_synth = &ay_c_synth; ay_mid_synth_r = &ay_c_synth_r; ay_right_synth = &ay_b_synth; } else if ( sound_stereo_ay == SOUND_STEREO_AY_ABC ) { ay_left_synth = &ay_a_synth; ay_mid_synth = &ay_b_synth; ay_mid_synth_r = &ay_b_synth_r; ay_right_synth = &ay_c_synth; } else { ui_error( UI_ERROR_ERROR, "unknown AY stereo separation type: %d", sound_stereo_ay ); fuse_abort(); } blip_synth_set_output( *ay_left_synth, left_buf ); blip_synth_set_output( *ay_mid_synth, left_buf ); blip_synth_set_output( *ay_right_synth, right_buf ); *ay_mid_synth_r = new_Blip_Synth(); blip_synth_set_volume( *ay_mid_synth_r, sound_get_volume( settings_current.volume_ay ) ); blip_synth_set_output( *ay_mid_synth_r, right_buf ); blip_synth_set_treble_eq( *ay_mid_synth_r, treble ); right_specdrum_synth = new_Blip_Synth(); blip_synth_set_volume( right_specdrum_synth, sound_get_volume( settings_current.volume_specdrum ) ); blip_synth_set_output( right_specdrum_synth, right_buf ); blip_synth_set_treble_eq( right_specdrum_synth, treble ); } else { blip_synth_set_output( ay_a_synth, left_buf ); blip_synth_set_output( ay_b_synth, left_buf ); blip_synth_set_output( ay_c_synth, left_buf ); } sound_enabled = sound_enabled_ever = 1; sound_channels = ( sound_stereo_ay != SOUND_STEREO_AY_NONE ? 2 : 1 ); /* Adjust relative processor speed to deal with adjusting sound generation frequency against emulation speed (more flexible than adjusting generated sample rate) */ hz = ( float )sound_get_effective_processor_speed() / machine_current->timings.tstates_per_frame; /* Size of audio data we will get from running a single Spectrum frame */ sound_framesiz = ( float )settings_current.sound_freq / hz; sound_framesiz++; samples = (blip_sample_t *)libspectrum_calloc( sound_framesiz * sound_channels, sizeof(blip_sample_t) ); /* initialize movie settings... */ movie_init_sound( settings_current.sound_freq, sound_stereo_ay ); }
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] }
void sound_init( const char *device ) { int ret; float hz; /* Allow sound as long as emulation speed is greater than 2% (less than that and a single Speccy frame generates more than a seconds worth of sound which is bigger than the maximum Blip_Buffer of 1 second) */ if( !( !sound_enabled && settings_current.sound && settings_current.emulation_speed > 1 ) ) return; sound_stereo_ay = settings_current.stereo_ay; /* only try for stereo if we need it */ if( sound_stereo_ay ) sound_stereo = 1; ret = sound_lowlevel_init( device, &settings_current.sound_freq, &sound_stereo ); if( ret ) return; if( !sound_init_blip(&left_buf, &left_beeper_synth) ) return; if( sound_stereo && !sound_init_blip(&right_buf, &right_beeper_synth) ) return; ay_a_synth = new_Blip_Synth(); blip_synth_set_volume( ay_a_synth, sound_get_volume( settings_current.volume_ay) ); blip_synth_set_output( ay_a_synth, left_buf ); blip_synth_set_treble_eq( ay_a_synth, speaker_type[ settings_current.speaker_type ].treble ); ay_b_synth = new_Blip_Synth(); blip_synth_set_volume( ay_b_synth, sound_get_volume( settings_current.volume_ay) ); blip_synth_set_treble_eq( ay_b_synth, speaker_type[ settings_current.speaker_type ].treble ); ay_c_synth = new_Blip_Synth(); blip_synth_set_volume( ay_c_synth, sound_get_volume( settings_current.volume_ay) ); blip_synth_set_output( ay_c_synth, left_buf ); blip_synth_set_treble_eq( ay_c_synth, speaker_type[ settings_current.speaker_type ].treble ); /* 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; } ay_a_synth_r = NULL; ay_b_synth_r = NULL; ay_c_synth_r = NULL; if( sound_stereo ) { ay_c_synth_r = new_Blip_Synth(); blip_synth_set_volume( ay_c_synth_r, sound_get_volume( settings_current.volume_ay ) ); blip_synth_set_output( ay_c_synth_r, right_buf ); if( sound_stereo_ay ) { /* stereo with ACB stereo. */ blip_synth_set_output( ay_b_synth, right_buf ); } else { ay_a_synth_r = new_Blip_Synth(); blip_synth_set_volume( ay_a_synth_r, sound_get_volume( settings_current.volume_ay ) ); blip_synth_set_output( ay_a_synth_r, right_buf ); blip_synth_set_treble_eq( ay_a_synth_r, speaker_type[ settings_current.speaker_type ].treble ); blip_synth_set_output( ay_b_synth, left_buf ); ay_b_synth_r = new_Blip_Synth(); blip_synth_set_volume( ay_b_synth_r, sound_get_volume( settings_current.volume_ay ) ); blip_synth_set_output( ay_b_synth_r, right_buf ); blip_synth_set_treble_eq( ay_b_synth_r, speaker_type[ settings_current.speaker_type ].treble ); } } else { blip_synth_set_output( ay_b_synth, left_buf ); } sound_enabled = sound_enabled_ever = 1; sound_channels = ( sound_stereo ? 2 : 1 ); /* Adjust relative processor speed to deal with adjusting sound generation frequency against emulation speed (more flexible than adjusting generated sample rate) */ hz = ( float )sound_get_effective_processor_speed() / machine_current->timings.tstates_per_frame; /* Size of audio data we will get from running a single Spectrum frame */ sound_framesiz = ( float )settings_current.sound_freq / hz; sound_framesiz++; samples = (blip_sample_t *)calloc( sound_framesiz * sound_channels, sizeof(blip_sample_t) ); }