int main( void ) { struct RDArgs *rdargs; int rc = RETURN_OK; GfxBase = (struct GfxBase *) OpenLibrary( GRAPHICSNAME, 37 ); IntuitionBase = (struct IntuitionBase *) OpenLibrary( "intuition.library", 37 ); if( GfxBase == NULL ) { Printf( "Unable to open %s version %ld\n", (ULONG) GRAPHICSNAME, 37 ); cleanup(); return RETURN_FAIL; } if( IntuitionBase == NULL ) { Printf( "Unable to open %s version %ld\n", (ULONG) "intuition.library", 37 ); cleanup(); return RETURN_FAIL; } rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL ); if( rdargs != NULL ) { /* Refresh database */ if( args.refresh && !args.remove ) { ULONG id; OpenAHI(); /* First, empty the database */ for( id = AHI_NextAudioID( AHI_INVALID_ID ); id != (ULONG) AHI_INVALID_ID; id = AHI_NextAudioID( AHI_INVALID_ID ) ) { AHI_RemoveAudioMode( id ); } /* Now add all modes */ if( !AHI_LoadModeFile( "DEVS:AudioModes" ) ) { if( IS_MORPHOS ) { ULONG res; /* Be quiet here. - Piru */ APTR *windowptr = &((struct Process *) FindTask(NULL))->pr_WindowPtr; APTR oldwindowptr = *windowptr; *windowptr = (APTR) -1; res = AHI_LoadModeFile( "MOSSYS:DEVS/AudioModes" ); *windowptr = oldwindowptr; if( !res ) { if( !args.quiet ) { PrintFault( IoErr(), "AudioModes" ); } rc = RETURN_ERROR; } } else { if ( !args.quiet ) { PrintFault( IoErr(), "DEVS:AudioModes" ); } rc = RETURN_ERROR; } } } /* Load mode files */ if( args.files != NULL && !args.remove ) { int i = 0; OpenAHI(); while( args.files[i] ) { if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet ) { PrintFault( IoErr(), args.files[i] ); rc = RETURN_ERROR; } i++; } } /* Remove database */ if( args.remove ) { if( args.files || args.refresh ) { PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" ); rc = RETURN_FAIL; } else { ULONG id; OpenAHI(); for( id = AHI_NextAudioID( AHI_INVALID_ID ); id != (ULONG) AHI_INVALID_ID; id = AHI_NextAudioID( AHI_INVALID_ID ) ) { AHI_RemoveAudioMode( id ); } } } /* Make display mode doublescan (allowing > 28 kHz sample rates) */ if( args.dblscan ) { ULONG id; ULONG bestid = INVALID_ID; int minper = INT_MAX; struct Screen *screen = NULL; static const struct ColorSpec colorspecs[] = { { 0, 0, 0, 0 }, { 1, 0, 0, 0 }, {-1, 0, 0, 0 } }; union { struct MonitorInfo mon; struct DisplayInfo dis; } buffer; for( id = NextDisplayInfo( INVALID_ID ); id != (ULONG) INVALID_ID; id = NextDisplayInfo( id ) ) { int period; if( GetDisplayInfoData( NULL, (UBYTE*) &buffer.dis, sizeof(buffer.dis), DTAG_DISP, id ) ) { if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) ) { continue; } } if( GetDisplayInfoData( NULL, (UBYTE*) &buffer.mon, sizeof(buffer.mon), DTAG_MNTR, id ) ) { period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) ); if( period < minper ) { minper = period; bestid = id; } } } if( bestid != (ULONG) INVALID_ID && minper < 100 ) { screen = OpenScreenTags( NULL, SA_DisplayID, bestid, SA_Colors, (ULONG) &colorspecs, TAG_DONE ); } else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 ) { /* No suitable screen mode found, let's bang the hardware... Using code from Sebastiano Vigna <*****@*****.**>. */ struct Custom *custom = (struct Custom *) 0xdff000; custom->bplcon0 = 0x8211; custom->ddfstrt = 0x0018; custom->ddfstop = 0x0058; custom->hbstrt = 0x0009; custom->hsstop = 0x0017; custom->hbstop = 0x0021; custom->htotal = 0x0071; custom->vbstrt = 0x0000; custom->vsstrt = 0x0003; custom->vsstop = 0x0005; custom->vbstop = 0x001D; custom->vtotal = 0x020E; custom->beamcon0 = 0x0B88; custom->bplcon1 = 0x0000; custom->bplcon2 = 0x027F; custom->bplcon3 = 0x00A3; custom->bplcon4 = 0x0011; } if( screen != NULL ) { CloseScreen( screen ); } } FreeArgs( rdargs ); } cleanup(); return rc; }
int main( void ) { struct RDArgs *rdargs; int rc = RETURN_OK; rdargs = ReadArgs( TEMPLATE , (LONG *) &args, NULL ); if( rdargs != NULL ) { /* Refresh database */ if( args.refresh && !args.remove ) { OpenAHI(); if( !AHI_LoadModeFile( "DEVS:AudioModes" ) && !args.quiet ) { PrintFault( IoErr(), "DEVS:AudioModes" ); rc = RETURN_ERROR; } } /* Load mode files */ if( args.files != NULL && !args.remove ) { int i = 0; OpenAHI(); while( args.files[i] ) { if( !AHI_LoadModeFile( args.files[i] ) && !args.quiet ) { PrintFault( IoErr(), args.files[i] ); rc = RETURN_ERROR; } i++; } } /* Remove database */ if( args.remove ) { if( args.files || args.refresh ) { PutStr( "The REMOVE switch cannot be used together with FILES or REFRESH.\n" ); rc = RETURN_FAIL; } else { ULONG id; OpenAHI(); for( id = AHI_NextAudioID( AHI_INVALID_ID ); id != AHI_INVALID_ID; id = AHI_NextAudioID( AHI_INVALID_ID ) ) { AHI_RemoveAudioMode( id ); } } } /* Make display mode doublescan (allowing > 28 kHz sample rates) */ if( args.dblscan ) { ULONG id; ULONG bestid = INVALID_ID; int minper = MAXINT; struct Screen *screen = NULL; static const struct ColorSpec colorspecs[] = { { 0, 0, 0, 0 }, { 1, 0, 0, 0 }, {-1, 0, 0, 0 } }; union { struct MonitorInfo mon; struct DisplayInfo dis; } buffer; for( id = NextDisplayInfo( INVALID_ID ); id != (ULONG) INVALID_ID; id = NextDisplayInfo( id ) ) { int period; if( GetDisplayInfoData( NULL, (UBYTE*) &buffer.dis, sizeof(buffer.dis), DTAG_DISP, id ) ) { if( !(buffer.dis.PropertyFlags & (DIPF_IS_ECS | DIPF_IS_AA ) ) ) { continue; } } if( GetDisplayInfoData( NULL, (UBYTE*) &buffer.mon, sizeof(buffer.mon), DTAG_MNTR, id ) ) { period = buffer.mon.TotalColorClocks * buffer.mon.TotalRows / ( 2 * ( buffer.mon.TotalRows - buffer.mon.MinRow + 1 ) ); if( period < minper ) { minper = period; bestid = id; } } } if( bestid != (ULONG) INVALID_ID && minper < 100 ) { screen = OpenScreenTags( NULL, SA_DisplayID, bestid, SA_Colors, (ULONG) &colorspecs, TAG_DONE ); } else if( ( GfxBase->ChipRevBits0 & (GFXF_HR_DENISE | GFXF_AA_LISA ) ) != 0 ) { /* No suitable screen mode found, let's bang the hardware... Using code from Sebastiano Vigna <*****@*****.**>. */ extern struct Custom custom; custom.bplcon0 = 0x8211; custom.ddfstrt = 0x0018; custom.ddfstop = 0x0058; custom.hbstrt = 0x0009; custom.hsstop = 0x0017; custom.hbstop = 0x0021; custom.htotal = 0x0071; custom.vbstrt = 0x0000; custom.vsstrt = 0x0003; custom.vsstop = 0x0005; custom.vbstop = 0x001D; custom.vtotal = 0x020E; custom.beamcon0 = 0x0B88; custom.bplcon1 = 0x0000; custom.bplcon2 = 0x027F; custom.bplcon3 = 0x00A3; custom.bplcon4 = 0x0011; } if( screen != NULL ) { CloseScreen( screen ); } } FreeArgs( rdargs ); } cleanup( rc ); }
int AudioOpen(unsigned long freq, unsigned long minbufsize, unsigned long bitrate, unsigned long stereo) { ULONG Type; Frequency = freq; so.playback_rate = Frequency; if(stereo) so.stereo = TRUE; else so.stereo = FALSE; switch(bitrate) { case 8: so.sixteen_bit = FALSE; BitRate=1; if(stereo) { Stereo=2; Type = AHIST_S8S; } else { Stereo=1; Type = AHIST_M8S; } break; default: //defaulting to 16bit, because it means it won't crash atleast case QUAL_16BIT: so.sixteen_bit = TRUE; BitRate=2; if(stereo) { Stereo=2; Type = AHIST_S16S; } else { Stereo=1; Type = AHIST_M16S; } break; } if(prelude) prelude = OpenPrelude(Type, freq, minbufsize); if(prelude) return 1; else printf("Defaulting to AHI...\n"); /* only 1 channel right? */ /* NOTE: The buffersize will not always be what you requested * it finds the minimun AHI requires and then rounds it up to * nearest 32 bytes. Check AHIData->BufferSize or Samples[n].something_Length */ if(AHIData = OpenAHI(1, Type, AHI_INVALID_ID, AHI_DEFAULT_FREQ, 0, minbufsize)) { printf("AHI opened\n"); printf("BuffSize %d\n", AHIData->BufferSize); } else { printf("AHI failed to open: %d\n", AHIData); return 0; } so.buffer_size = AHIData->BufferSize; // in bytes if (so.buffer_size > MAX_BUFFER_SIZE) so.buffer_size = MAX_BUFFER_SIZE; /* Lots of useful fields in the AHIData struct, have a look */ AHIBase = AHIData->AHIBase; actrl = AHIData->AudioCtrl; Frequency = AHIData->MixingFreq; printf("signal %ld\n", AHIData->SoundFuncSignal); Wait(AHIData->SoundFuncSignal); /* I don't think it should start playing until there is something * In the buffer, however to set off the SoundFunc it should * probably go through the buffer at least once, just silently. */ AHI_SetFreq(0, Frequency, actrl, AHISF_IMM); Wait(AHIData->SoundFuncSignal); AHI_SetVol(0, 0x10000, 0x8000, actrl, AHISF_IMM); mixsamples=AHIData->BufferSamples; SoundSignal = AHIData->SoundFuncSignal; return 1; }