Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <atari_sound_setup.h>
- #include <mint/falcon.h>
- #include <mint/osbind.h>
- #include <stdio.h>
- #include <stdlib.h>
- static volatile int muted;
- static volatile int endOfPlayback;
- static void __attribute__((interrupt)) timerA(void)
- {
- static unsigned long previousFrameAddr;
- *((volatile unsigned long *)0xFFFF9804L) = ~*((volatile unsigned long *)0xFFFF9804L);
- unsigned long frameAddr = 0;
- frameAddr |= *((volatile unsigned char *)0xFFFF8903L) << 16;
- frameAddr |= *((volatile unsigned char *)0xFFFF8905L) << 8;
- frameAddr |= *((volatile unsigned char *)0xFFFF8907L);
- if (previousFrameAddr == frameAddr) {
- *((volatile unsigned char *)0xFFFF8901L) &= 0xFC; // disable playback/repeat
- previousFrameAddr = 0;
- muted = 1;
- } else {
- previousFrameAddr = frameAddr;
- }
- endOfPlayback = 1;
- *((volatile unsigned char *)0xFFFFFA0FL) &= ~(1<<5); // clear in service bit
- }
- int main(int argc, char *argv[]) {
- char* filename = "en.raw";
- if (argc == 2)
- filename = argv[1];
- FILE* f = fopen(filename, "rb");
- if (!f)
- return EXIT_FAILURE;
- AudioSpec desired, obtained;
- desired.frequency = 24585;
- desired.channels = 2;
- desired.format = AudioFormatSigned16MSB;
- desired.samples = 2048;
- if (!AtariSoundSetupInitXbios(&desired, &obtained) || obtained.format != AudioFormatSigned16MSB)
- return EXIT_FAILURE;
- const size_t sampleBufferSize = obtained.samples * obtained.channels * 50 * 2; // 16-bit
- char *sampleBuffer = (char *)Mxalloc(2 * sampleBufferSize, MX_STRAM); // logical/physical buffer
- if (!sampleBuffer)
- return EXIT_FAILURE;
- memset(sampleBuffer, 0, 2 * sampleBufferSize);
- char *phys = sampleBuffer;
- char *log = sampleBuffer + sampleBufferSize;
- Buffoper(0x00);
- Setinterrupt(SI_TIMERA, SI_PLAY);
- Xbtimer(XB_TIMERA, 1<<3, 1, timerA); // event count mode, count to '1'
- Jenabint(MFP_TIMERA);
- fread(phys, 1, sampleBufferSize, f);
- Setbuffer(SR_PLAY, phys, phys + sampleBufferSize);
- Buffoper(SB_PLA_ENA | SB_PLA_RPT);
- endOfPlayback = 1;
- while(1) {
- if (endOfPlayback) {
- endOfPlayback = 0;
- char* tmp = phys;
- phys = log;
- log = tmp;
- fread(phys, 1, sampleBufferSize, f);
- Setbuffer(SR_PLAY, phys, phys + sampleBufferSize);
- if (muted) {
- Buffoper(SB_PLA_ENA | SB_PLA_RPT);
- endOfPlayback = 1;
- muted = 0;
- }
- }
- for (int i = 0; i < 500; i++)
- Vsync();
- }
- Buffoper(0x00);
- Jdisint(MFP_TIMERA);
- AtariSoundSetupDeinitXbios();
- Mfree(sampleBuffer);
- fclose(f);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement