| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A cross-platform .NET implementation of the Mod95 MOD player
This is a verbatim implementation of the magnificent code developed by Olivier Lapicque for his Mod95 player.
For more information, visit https://openmpt.org/legacy_software
Instantiating a new SoundFile:
A new SoundFile object is instantiated by calling the SoundFile ctor and passing the audio backend's parameters, such as the desired sample rate, bit depth (8/16) and channel count (1/2).
SharpMod.SoundFile sf = new SharpMod.SoundFile(modFileFullPath, sampleRate, bitDepth == 16, channels == 2, false);# Inputs
# sf : an initialized SoundFile (sampleRate, bitDepth, channels, loop already set)
# backend : the audio device / streaming sink (OpenAL, WASAPI, Web Audio, …)
# BUFFER_BYTES : size of one PCM chunk to hand to the backend
# TARGET_DEPTH : how many chunks to keep queued ahead of the playback cursor
buffer := allocate(BUFFER_BYTES) # reusable PCM scratch buffer
bufferIsClear := false
isPlaying := true
isPaused := false
backend.Open(sf.Rate, sf.Is16Bit, sf.IsStereo)
backend.PrimeWithSilence(BUFFER_BYTES) # one silent chunk so playback can start
while isPlaying:
if isPaused:
sleep(short)
continue
backend.ReleaseProcessedBuffers() # recycle chunks the device has consumed
if backend.QueuedBufferCount() >= TARGET_DEPTH:
sleep(short) # backend is full, don't starve nor flood
continue
bytesRead := sf.Read(buffer, BUFFER_BYTES) # pulls/synthesizes the next PCM chunk
if bytesRead == 0:
# End of song reached (Loop=false). Emit silence so the device drains cleanly.
if not bufferIsClear:
zero(buffer)
bufferIsClear := true
if sf.Position >= sf.PositionCount:
isPlaying := false
else:
bufferIsClear := false
backend.SubmitBuffer(buffer, BUFFER_BYTES) # hand the chunk to the device queue
backend.DrainAndClose()
Key points:
Then, whenever the audio backend requests audio data, call the SoundFile.Read method to parse the tracker and receive back a raw audio buffer, which can be passed back to the audio renderer.
The repository also ships several reference players built on top of the SharpMod library:
| Back | FazBrowse Home | New Git URL |