Double Buffered Sample Replay Routine

All about modules/digital tunes in a variety of tracker & sampled formats

Moderators: lotek_style, Moderator Team

Post Reply
mlynn1974
Atari Super Hero
Atari Super Hero
Posts: 764
Joined: Mon Mar 03, 2008 10:33 pm
Contact:

Double Buffered Sample Replay Routine

Post by mlynn1974 »

I don't know if this has been done or asked before but I would like to write a double buffered sample replay routine.
The aim of this would be to have a library that I could use to make good quality sample demos very quickly.

This would have a number of advantages:
1. Long samples bigger than physical memory could be loaded,
2. A demo could be run off a hard disk on a half-meg STFM,
3. Should implement STFM YM2149 and STe improved replay routines.

Potential problems:
1. Compensate for slow loading devices and different CPU speeds i.e. the loader would have to idle while the first buffer is playing and the second buffer is full. When the first buffer has stopped playing it should switch to the other buffer to play while the loader is filling the next buffer again.
2. The system should minimize clicks and setup when switching buffers.

Questions:
1. Can I use XBIOS fopen\fseek\fread\fclose in an interrupt service routine in supervisor mode?
2. Should I allocate static buffers or if my demo was running from Gem is it safer to use malloc()?

I don't think I know enough about writing Interrupt Service Routines to write this code.
I guess I'd use Timer A to replay the sound and Timer C for the loader.
Leaving Timer B alone for rasters.

I think the most efficient buffer size I would start at would be 92160 bytes or about 8.34 seconds at 11kHz. A floppy could easily load
that in less time leaving the loader idling for a fair amound of time.

I was thinking about how the POV Kinky Boots Demo works and guess it might be using a double buffer but it used a custom track loader.
Any suggestions would be very welcome.
Still got, still working: Atari 4Mb STe, MegaST 2, 520STFM (x2), 2.5Mb STF, Atari 2600JR, Flashback 8 Gold.
Hardware: PC720B, Cumana CSA 354, Ultimate Ripper, Discovery Cartridge, Blitz Turbo, Synchro Express II (US and UK Versions).
User avatar
metalages
Captain Atari
Captain Atari
Posts: 482
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Double Buffered Sample Replay Routine

Post by metalages »

I have done this in my flexi glass stuff http://cyber.savina.net/ it was ste only
If i well remember i had a routine in the vbl that check the current position of playing into the DMA sound buffer. This vbl stuff was requiring loading of the first or second half of the buffer accordingly. As you said with a few ten kb you can play a sample of the size of the disk. The loading routine was a custom fdc routine using interrupt at each sector (not the system one)
User avatar
metalages
Captain Atari
Captain Atari
Posts: 482
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Double Buffered Sample Replay Routine

Post by metalages »

... And I was playing at 12.5 khz. Fdc is fast enough but I guess 25 would be to much
User avatar
FedePede04
Atari God
Atari God
Posts: 1215
Joined: Fri Feb 04, 2011 12:14 am
Location: Denmark
Contact:

Re: Double Buffered Sample Replay Routine

Post by FedePede04 »

You can get an interrupt call back on the ste.(timer a) when its finish playing the sampels. It is very simple. I found a source code some places (I dont remember where) that both could play samples using ST or the STE
Atari will rule the world, long after man has disappeared

sometime my English is a little weird, Google translate is my best friend :)
User avatar
ggn
Atari God
Atari God
Posts: 1317
Joined: Sat Dec 28, 2002 4:49 pm

Re: Double Buffered Sample Replay Routine

Post by ggn »

mlynn1974 wrote:Questions:
1. Can I use XBIOS fopen\fseek\fread\fclose in an interrupt service routine in supervisor mode?
Yes. Both this and this demo use standard GEMDOS calls (not xbios ;)) to read from hard disk while the demo is running. I used 2 rather large buffers (I remember I streamed 50066Hz sample and I either used 5 or 10 seconds buffer - you do the math!) just to be sure and I did massive fread()s to fill in each one. I didn't check the sample pointer as Metal Ages suggested but instead used _hz_200 ($4ba) to count in 200Hz ticks (it was also used for synchronisation).
mlynn1974 wrote:2. Should I allocate static buffers or if my demo was running from Gem is it safer to use malloc()?

I can't think of a problem with using any of the two methods - personally I allocated the buffers in the BSS.
is 73 Falcon patched atari games enough ? ^^
User avatar
metalages
Captain Atari
Captain Atari
Posts: 482
Joined: Thu Jun 06, 2013 5:14 pm
Location: France
Contact:

Re: Double Buffered Sample Replay Routine

Post by metalages »

I have not used the timer A on the STe buffer indeed.
The VBL interrupt was just checking the current playing address of the DMA sound. When it enters the second half of the buffer, it launches loading for the first half of the buffer and then when the address has looped since the last VBL, it launches loading for the second half of the buffer.

If you use the system routine for loading, I guess your whole screen needs to run into an interrupt (VBL I guess) ?

--------------------------
For Rebirth, the system is more complex but same idea : stream the PCM musik to have everything fitting in 1mb RAM.
I load a buffer in background from FDC and slice transfers in VBL to left or right channel then use balance level to mix the 2 samples (you need to listen in mono...)

Here is the score code that synchronizes everything and require samples loading (kind of C co-routine using "funny" macro trick :))
https://github.com/gibs75/demOS/blob/ma ... SNDTRACK.C
https://github.com/gibs75/demOS/blob/ma ... DK/SOUND.H

VBL slices transfers, increments SNDdmaLoopCount when it sees the playing address has looped since last VBL and set the balance into the Microwire
https://github.com/gibs75/demOS/blob/ma ... DK/SOUND.S
mlynn1974
Atari Super Hero
Atari Super Hero
Posts: 764
Joined: Mon Mar 03, 2008 10:33 pm
Contact:

Re: Double Buffered Sample Replay Routine

Post by mlynn1974 »

Thanks for the advice everyone. If I get the time to work on this I'll share my results.
Thanks ggn for reminding me it's Gemdos not Xbios. I'll need to read the STE sound document.

I have an example in STOS I don't remember writing that plays the Popeye tune using DMA. It was probably copied from an ST Format example. I didn't use a STOS Extension in my demo. This code must be 25 years old. The tune takes up 171070 bytes and lasts for about a minute. The code is really simple so that might be a starting point.

I personally haven't used a C Compiler on the ST.
It was either STOS, GFA Basic or a bit of 68000 for me back in the day.
Still got, still working: Atari 4Mb STe, MegaST 2, 520STFM (x2), 2.5Mb STF, Atari 2600JR, Flashback 8 Gold.
Hardware: PC720B, Cumana CSA 354, Ultimate Ripper, Discovery Cartridge, Blitz Turbo, Synchro Express II (US and UK Versions).
User avatar
atari_mark
Captain Atari
Captain Atari
Posts: 203
Joined: Thu Oct 10, 2002 12:30 pm
Location: Wigan, England
Contact:

Re: Double Buffered Sample Replay Routine

Post by atari_mark »

Thought I would reply to this old thread :) Boris wrote all the code but I remember it used a 50% compression on audio. It loads a block of data then depacks it and replays it whilst loading the next block of data. The code is all on the POV CD (v2).
Mac Sys Data/Persistence Of Vision

Instructions said to install Windows 2000 or better so I installed Fedora.
Post Reply

Return to “The Digital Department”