Advertisement
Guest User

Untitled

a guest
Feb 1st, 2024
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.51 KB | None | 0 0
  1. #include <atari_sound_setup.h>
  2. #include <mint/falcon.h>
  3. #include <mint/osbind.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. static volatile int muted;
  8. static volatile int endOfPlayback;
  9. static void __attribute__((interrupt)) timerA(void)
  10. {
  11.     static unsigned long previousFrameAddr;
  12.  
  13.     *((volatile unsigned long *)0xFFFF9804L) = ~*((volatile unsigned long *)0xFFFF9804L);
  14.  
  15.     unsigned long frameAddr = 0;
  16.     frameAddr |= *((volatile unsigned char *)0xFFFF8903L) << 16;
  17.     frameAddr |= *((volatile unsigned char *)0xFFFF8905L) << 8;
  18.     frameAddr |= *((volatile unsigned char *)0xFFFF8907L);
  19.  
  20.     if (previousFrameAddr == frameAddr) {
  21.         *((volatile unsigned char *)0xFFFF8901L) &= 0xFC;   // disable playback/repeat
  22.         previousFrameAddr = 0;
  23.         muted = 1;
  24.     } else {
  25.         previousFrameAddr = frameAddr;
  26.     }
  27.    
  28.     endOfPlayback = 1;
  29.  
  30.     *((volatile unsigned char *)0xFFFFFA0FL) &= ~(1<<5);    // clear in service bit
  31. }
  32.  
  33. int main(int argc, char *argv[]) {
  34.     char* filename = "en.raw";
  35.  
  36.     if (argc == 2)
  37.         filename = argv[1];
  38.  
  39.     FILE* f = fopen(filename, "rb");
  40.     if (!f)
  41.         return EXIT_FAILURE;
  42.  
  43.     AudioSpec desired, obtained;
  44.    
  45.     desired.frequency = 24585;
  46.     desired.channels = 2;
  47.     desired.format = AudioFormatSigned16MSB;
  48.     desired.samples = 2048;
  49.  
  50.     if (!AtariSoundSetupInitXbios(&desired, &obtained) || obtained.format != AudioFormatSigned16MSB)
  51.         return EXIT_FAILURE;
  52.  
  53.     const size_t sampleBufferSize = obtained.samples * obtained.channels * 50 * 2;  // 16-bit
  54.     char *sampleBuffer = (char *)Mxalloc(2 * sampleBufferSize, MX_STRAM);   // logical/physical buffer
  55.     if (!sampleBuffer)
  56.         return EXIT_FAILURE;
  57.     memset(sampleBuffer, 0, 2 * sampleBufferSize);
  58.  
  59.     char *phys = sampleBuffer;
  60.     char *log = sampleBuffer + sampleBufferSize;
  61.  
  62.     Buffoper(0x00);
  63.     Setinterrupt(SI_TIMERA, SI_PLAY);
  64.     Xbtimer(XB_TIMERA, 1<<3, 1, timerA);    // event count mode, count to '1'
  65.     Jenabint(MFP_TIMERA);
  66.  
  67.     fread(phys, 1, sampleBufferSize, f);
  68.     Setbuffer(SR_PLAY, phys, phys + sampleBufferSize);
  69.    
  70.     Buffoper(SB_PLA_ENA | SB_PLA_RPT);
  71.     endOfPlayback = 1;
  72.  
  73.     while(1) {
  74.         if (endOfPlayback) {
  75.             endOfPlayback = 0;
  76.  
  77.             char* tmp = phys;
  78.             phys = log;
  79.             log = tmp;
  80.  
  81.             fread(phys, 1, sampleBufferSize, f);
  82.             Setbuffer(SR_PLAY, phys, phys + sampleBufferSize);
  83.             if (muted) {
  84.                 Buffoper(SB_PLA_ENA | SB_PLA_RPT);
  85.                 endOfPlayback = 1;
  86.                 muted = 0;
  87.             }
  88.         }
  89.  
  90.         for (int i = 0; i < 500; i++)
  91.             Vsync();
  92.     }
  93.  
  94.     Buffoper(0x00);
  95.  
  96.     Jdisint(MFP_TIMERA);
  97.  
  98.     AtariSoundSetupDeinitXbios();
  99.  
  100.     Mfree(sampleBuffer);
  101.    
  102.     fclose(f);
  103.    
  104.     return EXIT_SUCCESS;
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement