Here is my over-engineered streaming ZCM player with built-in format conversion and sample rate conversion. This uses
_SNDRAWBATCH for playback and neatly wraps most QB64-PE _SNDRAW* functions for ease of use.
There are two libraries -
zcmstream (
zcmstream.bas +
zcmstream.bi) and
rawresampler (
rawresampler.h +
rawresampler.bi).
rawresampler can be used standalone. However,
zcmstream depends on
rawresampler.
zcm_stream_test.bas is a test wrapper that shows how to use
zcmstream. See
ZCMStream_Play() to understand how to use
rawresampler.
zcmstream API (see sources for documentation):
Code: (Select All)
FUNCTION ZCMStream_Open%% (context AS ZCMStreamType, fileName AS STRING)
SUB ZCMStream_Close (context AS ZCMStreamType)
FUNCTION ZCMStream_Is16Bit%% (context AS ZCMStreamType)
FUNCTION ZCMStream_IsStereo%% (context AS ZCMStreamType)
FUNCTION ZCMStream_GetVolume! (context AS ZCMStreamType)
SUB ZCMStream_SetVolume (context AS ZCMStreamType, volume AS SINGLE)
FUNCTION ZCMStream_GetSampleRate~& (context AS ZCMStreamType)
FUNCTION ZCMStream_GetTotalFrames~& (context AS ZCMStreamType)
FUNCTION ZCMStream_GetCurrentFrame~& (context AS ZCMStreamType)
FUNCTION ZCMStream_GetPlayingFrames~& (context AS ZCMStreamType)
FUNCTION ZCMStream_Play~& (context AS ZCMStreamType, chunkFrames AS _UNSIGNED LONG)
rawresampler API (see sources for documentation):
Code: (Select All)
FUNCTION RawResampler_S8~&& (src AS _UNSIGNED _OFFSET, dst AS _UNSIGNED _OFFSET, inSampleRate AS _UNSIGNED LONG, outSampleRate AS _UNSIGNED LONG, inputSampleFrames AS _UNSIGNED _INTEGER64, channels AS _UNSIGNED LONG)
FUNCTION RawResampler_U8~&& (src AS _UNSIGNED _OFFSET, dst AS _UNSIGNED _OFFSET, inSampleRate AS _UNSIGNED LONG, outSampleRate AS _UNSIGNED LONG, inputSampleFrames AS _UNSIGNED _INTEGER64, channels AS _UNSIGNED LONG)
FUNCTION RawResampler_S16~&& (src AS _UNSIGNED _OFFSET, dst AS _UNSIGNED _OFFSET, inSampleRate AS _UNSIGNED LONG, outSampleRate AS _UNSIGNED LONG, inputSampleFrames AS _UNSIGNED _INTEGER64, channels AS _UNSIGNED LONG)
FUNCTION RawResampler_S32~&& (src AS _UNSIGNED _OFFSET, dst AS _UNSIGNED _OFFSET, inSampleRate AS _UNSIGNED LONG, outSampleRate AS _UNSIGNED LONG, inputSampleFrames AS _UNSIGNED _INTEGER64, channels AS _UNSIGNED LONG)
FUNCTION RawResampler_F32~&& (src AS _UNSIGNED _OFFSET, dst AS _UNSIGNED _OFFSET, inSampleRate AS _UNSIGNED LONG, outSampleRate AS _UNSIGNED LONG, inputSampleFrames AS _UNSIGNED _INTEGER64, channels AS _UNSIGNED LONG)
Update:
Added a third library -
zcm (
zcm.bas). The
zcm library allows one to load and save non-streaming ZCM audio.
zcm_test.bas is a test wrapper that shows how to use the
zcm library.
zcm API (see sources for documentation):
Code: (Select All)
FUNCTION ZCM_Save%% (srcAudioHandle AS LONG, dstFileName AS STRING)
FUNCTION ZCM_Load& (srcFileName AS STRING)
Added some test audio files.
MIT license.
Enjoy!