bool InitAllegroSound () { bool fRet = false; reserve_voices(2,1); if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) < 0) TRACE("install_sound() failed: %s\n", allegro_error); else fRet = true; return fRet; }
static int allegro_startup(unsigned int freq) { log_debug("Starting up Allegro sound... "); remove_sound(); set_config_int("sound", "sb_freq", (int) freq); detect_digi_driver(DIGI_AUTODETECT); reserve_voices(1, 0); if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0) { log_debug("Failed: %s\n", allegro_error); return -1; } /* This is not a good idea, as the user might want to specify this from the setup program. */ /* set_volume(255, 0); */ log_debug("OK: %s, %s\n", digi_driver->name, digi_driver->desc); return 0; }
BOOL saInitSoundCard( int soundcard, int sample_rate ) { int i,id; /* install a digital sound driver */ // Normally, soundcard =0 means no sound in raine. // I will try not to break this to keep compatibility with the other // sources... id = sound_card_id(soundcard); if (max_mixer_volume) set_volume_per_voice(0); reserve_voices(16,0); // found by nlx_doom if (install_sound(id, MIDI_NONE, NULL) != 0) { //set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error initialising sound system\n%s\n", allegro_error); RaineSoundCard = 0; return 0; } // a super mega bug in allegro, at least in my installation. /* Maybe it's a compilation bug (gcc bug) but I don't want to test a lib without the optimizations, so I'll leave this as is. I must initialise the sound driver twice or reserve_voices is simply ignored and I loose voices */ remove_sound(); if (max_mixer_volume) set_volume_per_voice(0); else set_volume_per_voice(-1); if (install_sound(id, MIDI_NONE, NULL) != 0) { //set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error initialising sound system\n%s\n", allegro_error); RaineSoundCard = 0; return 0; } set_volume(255,-1); for( i = 0; i < NUMVOICES; i++ ){ lpWave[i] = 0; playing[i] = 0; #ifdef DUMP_CHANNELS sprintf(s,"stream%02d.raw",i); stream_out[i] = fopen(s,"wb"); #endif } stream_buffer_max = STREAM_BUFFER_MAXB; //reserved_channel = 0; pause_sound = 0; /* pause flag off */ if(!init_sound_emulators()) { return FALSE; // Everything fine } return TRUE; }
int msdos_init_sound(void) { #ifdef USE_SEAL int i; /* Ask the user if no soundcard was chosen */ if (soundcard == -1) { unsigned int k; printf("\nSelect the audio device:\n"); for (k = 0;k < AGetAudioNumDevs();k++) { /* don't show the AWE32, it's too slow, users must choose Sound Blaster */ if (AGetAudioDevCaps(k,&caps) == AUDIO_ERROR_NONE && strcmp(caps.szProductName,"Sound Blaster AWE32")) printf(" %2d. %s\n",k,caps.szProductName); } printf("\n"); if (k < 10) { i = getch(); soundcard = i - '0'; } else scanf("%d",&soundcard); } /* initialize SEAL audio library */ if (soundcard == 0) /* silence */ { /* update the Machine structure to show that sound is disabled */ Machine->sample_rate = 0; return 0; } /* open audio device */ /* info.nDeviceId = AUDIO_DEVICE_MAPPER;*/ info.nDeviceId = soundcard; /* always use 16 bit mixing if possible - better quality and same speed of 8 bit */ info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_RAW_SAMPLE; /* use stereo output if supported */ if (usestereo) { if (Machine->drv->sound_attributes & SOUND_SUPPORTS_STEREO) info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO | AUDIO_FORMAT_RAW_SAMPLE; } info.nSampleRate = Machine->sample_rate; if (AOpenAudio(&info) != AUDIO_ERROR_NONE) { printf("audio initialization failed\n"); return 1; } AGetAudioDevCaps(info.nDeviceId,&caps); logerror("Using %s at %d-bit %s %u Hz\n", caps.szProductName, info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8, info.wFormat & AUDIO_FORMAT_STEREO ? "stereo" : "mono", info.nSampleRate); /* open and allocate voices, allocate waveforms */ if (AOpenVoices(SOUND_CHANNELS) != AUDIO_ERROR_NONE) { printf("voices initialization failed\n"); return 1; } for (i = 0; i < SOUND_CHANNELS; i++) { lpWave[i] = 0; } stream_playing = 0; stream_cache_data = 0; stream_cache_len = 0; stream_cache_stereo = 0; /* update the Machine structure to reflect the actual sample rate */ Machine->sample_rate = info.nSampleRate; logerror("set sample rate: %d\n",Machine->sample_rate); if (sampleratedetect) { TICKER a,b; LONG start,end; if (ACreateAudioVoice(&hVoice[0]) != AUDIO_ERROR_NONE) return 1; if ((lpWave[0] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0) { ADestroyAudioVoice(hVoice[0]); return 1; } lpWave[0]->wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO; lpWave[0]->nSampleRate = Machine->sample_rate; lpWave[0]->dwLength = 3*Machine->sample_rate; lpWave[0]->dwLoopStart = 0; lpWave[0]->dwLoopEnd = 3*Machine->sample_rate; if (ACreateAudioData(lpWave[0]) != AUDIO_ERROR_NONE) { free(lpWave[0]); lpWave[0] = 0; return 1; } memset(lpWave[0]->lpData,0,3*Machine->sample_rate); /* upload the data to the audio DRAM local memory */ AWriteAudioData(lpWave[0],0,3*Machine->sample_rate); APrimeVoice(hVoice[0],lpWave[0]); ASetVoiceFrequency(hVoice[0],Machine->sample_rate); ASetVoiceVolume(hVoice[0],0); AStartVoice(hVoice[0]); a = ticker(); /* wait some time to let everything stabilize */ do { AUpdateAudioEx(Machine->sample_rate / Machine->drv->frames_per_second); b = ticker(); } while (b-a < TICKS_PER_SEC/10); a = ticker(); AGetVoicePosition(hVoice[0],&start); do { AUpdateAudioEx(Machine->sample_rate / Machine->drv->frames_per_second); b = ticker(); } while (b-a < TICKS_PER_SEC); AGetVoicePosition(hVoice[0],&end); nominal_sample_rate = Machine->sample_rate; Machine->sample_rate = end - start; logerror("actual sample rate: %d\n",Machine->sample_rate); AStopVoice(hVoice[0]); ADestroyAudioData(lpWave[0]); free(lpWave[0]); lpWave[0] = 0; ADestroyAudioVoice(hVoice[0]); } else nominal_sample_rate = Machine->sample_rate; #if 0 { char *blaster_env; /* Get Soundblaster base address from environment variabler BLASTER */ /* Soundblaster OPL base port, at some compatibles this must be 0x388 */ if(!getenv("BLASTER")) { printf("\nBLASTER variable not found, disabling fm sound!\n"); No_OPL = options.no_fm = 1; } else { blaster_env = getenv("BLASTER"); BaseSb = i = 0; while ((blaster_env[i] & 0x5f) != 0x41) i++; /* Look for 'A' char */ while (blaster_env[++i] != 0x20) { BaseSb = (BaseSb << 4) + (blaster_env[i]-0x30); } } } #endif #endif #ifdef USE_ALLEGRO reserve_voices(1,0); if (install_sound(DIGI_AUTODETECT,MIDI_NONE,0) != 0) { logerror("Allegro install_sound error: %s\n",allegro_error); return 1; } nominal_sample_rate = Machine->sample_rate; #endif num_used_opl = 0; osd_set_mastervolume(attenuation); /* set the startup volume */ return 0; }