Page 1 of 1

libZPlay include + header (windows 32-bit only)

Posted: Fri Mar 02, 2012 6:14 pm
by ts-soft
libZPlay is a MultiMedia Library like FMOD or Bass.dll

Info's: http://libzplay.sourceforge.net/
Requires: SDK: http://sourceforge.net/projects/libzpla ... z/download

libzplay_header.pbi:

Code: Select all

Enumeration ;TStreamFormat
  #sfUnknown
  #sfMp3
  #sfOgg
  #sfWav
  #sfPCM
  #sfFLAC
  #sfFLACOgg
  #sfAC3
  #sfAacADTS
  #sfWaveIn
  #sfAutodetect = 1000
EndEnumeration

#WaveOutWaveMapper = $FFFFFFFF
#WaveInWaveMapper = $FFFFFFFF

Enumeration ;TFFTGraphSize
  #FFTGraphMinWidht = 100
  #FFTGraphMinHeight = 60
EndEnumeration

Enumeration ;TMBPDetectionMethos
  #dmPeaks
  #dmAutoCorrelation
EndEnumeration

Enumeration ;TFFTGraphHorizontalScale
  #gsLogarithmic
  #gsLinear
EndEnumeration

Enumeration ;TSeekMethod
  #smFromBeginning = 1
  #smFromEnd = 2
  #smFromCurrendForward = 4
  #smFromCurrentBackward = 8
EndEnumeration

Enumeration ;TTimeFormat
  #tfMillisecond = 1
  #tfSecond = 2
  #tfHMS = 4
  #tfSamples = 8
EndEnumeration

Enumeration ;TWaveOutForma
  #format_invalid = 0
  #format_11khz_8bit_mono = 1
  #format_11khz_8bit_stereo = 2
  #format_11khz_16bit_mono = 4
  #format_11khz_16bit_stereo = 8
  #format_22khz_8bit_mono = 16
  #format_22khz_8bit_stereo = 32
  #format_22khz_16bit_mono = 64
  #format_22khz_16bit_stereo = 128
  #format_44khz_8bit_mono = 256
  #format_44khz_8bit_stereo = 512
  #format_44khz_16bit_mono = 1024
  #format_44khz_16bit_stereo = 2048
EndEnumeration

Enumeration ;TWaveOutFunctionality
  #supportPitchControl = 1
  #supportPlaybackRateControl = 2
  #supportVolumeControl = 4
  #supportSeparateLeftRightVolume = 8
  #supportSync = 16
  #supportSampleAccuratePosition = 32
  #supportDirectSound = 6
EndEnumeration

Enumeration ;TID3Version
  #id3Version1 = 1
  #id3Version2 = 2
EndEnumeration

Enumeration ;TFFTGraphType
  #gtLinesLeftOnTop
  #gtLinesRightOnTop
  #gtAreaLeftOnTop
  #gtAreaRightOnTop
  #gtBarsLeftOnTop
  #gtBarsRightOnTop
  #gtSpectrum
EndEnumeration

Enumeration ;TFFTWindow
  #fwRectangular = 1
  #fwHamming
  #fwHann
  #fwCosine
  #fwLanczos
  #fwBartlett
  #fwTriangular
  #fwGauss
  #fwBartlettHann
  #fwBlackman
  #fwNuttall
  #fwBlackmanHarris
  #fwBlackmanNuttall
  #fwFlatTop
EndEnumeration

Enumeration ;TFFTGraphParamID
  #gpFFTPoints = 1
  #gpGraphType
  #gpWindow
  #gpHorizontalScale
  #gpSubgrid
  #gpTransparency
  #gpFrequencyScaleVisible
  #gpDecibelScaleVisible
  #gpFrequencyGridVisible
  #gpDecibelGridVisible
  #gpBgBitmapVisible
  #gpBgBitmapHandle
  #gpColor1
  #gpColor2
  #gpColor3
  #gpColor4
  #gpColor5
  #gpColor6
  #gpColor7
  #gpColor8
  #gpColor9
  #gpColor10
  #gpColor11
  #gpColor12
  #gpColor13
  #gpColor14
  #gpColor15
  #gpColor16
EndEnumeration

Enumeration ;TCallbackMessage
  #MsgStopAsync = 1
  #MsgPlayAsync = 2
  #MsgEnterLoopAsync = 4
  #MsgExitLoopAsync = 8
  #MsgEnterVolumeSlideAsync = 16
  #MsgExitVolumeSlideAsync = 32
  #MsgStreamBufferDoneAsync = 64
  #MsgStreamNeedMoreDataAsync = 128
  #MsgNextSongAsync = 256
  #MsgStop = 65536
  #MsgPlay = 131072
  #MsgEnterLoop = 262144
  #MsgExitLoop = 524288
  #MsgEnterVolumeSlide = 1048576
  #MsgExitVolumeSlide = 2097152
  #MsgStreamBufferDone = 4194304
  #MsgStreamNeedMoreData = 8388608
  #MsgNextSong = 16777216
  #MsgWaveBuffer = 33554432
EndEnumeration

Prototype TCallbackFunc(*instance, *user_data, message, param1, param2)

Enumeration ;TSettingID
  #sidWaveBufferSize = 1
  #sidAccurateLength
  #sidAccurateSeek
  #sidSamplerate
  #sidChannelNumber
  #sidBitPerSample
  #sidBigEndian
  #sidWaveInBufferSize
EndEnumeration

Structure TStreamHMSTime
  hour.l
  minute.l
  second.l
  millisecond.l
EndStructure

Structure TStreamTime
  sec.l
  ms.l
  samples.l
  hms.TStreamHMSTime
EndStructure

Structure TEchoEffect
  nLeftDelay.l
  nLeftSrcVolume.l
  nLeftEchoVolume.l
  nRightDelay.l
  nRightSrcVolume.l
  nRightEchoVolume.l
EndStructure

Structure TWaveOutInfo
  ManufacturerID.l
  ProductID.l
  DriverVersion.l
  Formats.l
  Channels.l
  Support.l
  ProductName.s
EndStructure

Structure TWaveOutInfoW
  ManufacturerID.l
  ProductID.l
  DriverVersion.l
  Formats.l
  Channels.l
  Support.l
  ProductName.s
EndStructure

Structure TWaveInInfo
  ManufacturerID.l
  ProductID.l
  DriverVersion.l
  Formats.l
  Channels.l
  ProductName.s
EndStructure

Structure TWaveInInfoW
  ManufacturerID.l
  ProductID.l
  DriverVersion.l
  Formats.l
  Channels.l
  ProductName.s
EndStructure

Structure TStreamStatus
  fPlay.l
  fPause.l
  fEcho.l
  fEqualizer.l
  fVocalCut.l
  fSideCut.l
  fChannelMix.l
  fSlideVolume.l
  nLoop.l
  fReverse.l
  nSongIndex.l
  nSongsInQueue.l
EndStructure

Structure TID3Info
  Title.s
  Artist.s
  Album.s
  Year.s
  Comment.s
  TrackNum.s
  Genre.s
EndStructure

Structure TID3Picture
  PicturePresent.l
  CanDrawPicture.l
  MIMEType.s
  PictureType.l
  Description.s
  *PictureData
  PictureDataSize.l
  *hBitmap
  Width.l
  Height.l
  reserved.a[128]
EndStructure

Structure TID3PictureW
  PicturePresent.l
  CanDrawPicture.l
  MIMEType.s
  PictureType.l
  Description.s
  *PictureData
  PictureDataSize.l
  *hBitmap
  Width.l
  Height.l
  reserved.u[128]
EndStructure

Structure TID3InfoEx
  Title.s
  Artist.s
  Album.s
  Year.s
  Comment.s
  TrackNum.s
  Genre.s
  AlbumArtist.s
  Composer.s
  OriginalArtist.s
  Copyright.s
  URL.s
  Encoder.s
  Publisher.s
  BPM.l
  Picture.TID3Picture
  reserved.a[128]
EndStructure

Structure TID3InfoExW
  Title.s
  Artist.s
  Album.s
  Year.s
  Comment.s
  TrackNum.s
  Genre.s
  AlbumArtist.s
  Composer.s
  OriginalArtist.s
  Copyright.s
  URL.s
  Encoder.s
  Publisher.s
  BPM.l
  Picture.TID3PictureW
  reserved.u[128]
EndStructure

Structure TID3InfoW
  Title.s
  Artist.s
  Album.s
  Year.s
  Comment.s
  TrackNum.s
  Genre.s
EndStructure

Structure TStreamInfo
  SamplingRate.l
  ChannelNumber.l
  VBR.l
  Bitrate.l
  Length.TStreamTime
  Description.s
EndStructure

Structure TStreamInfoW
  SamplingRate.l
  ChannelNumber.l
  VBR.l
  Bitrate.l
  Length.TStreamTime
  Description.s
EndStructure

Structure TStreamLoadInfo
  NumberOfBuffers.l
  NumberOfBytes.l
EndStructure

libzplay_include.pbi:

Code: Select all

XIncludeFile "libzplay_header.pbi"

Import "libzplay.lib"
  CreateZPlay()
  zplay_AddFile(hZPlay, sFileName.p-Ascii, nFormat)
  zplay_AddFileW(hZPlay, sFileName.p-Unicode, nFormat)
  zplay_Close(hZPlay)
  zplay_CreateZPlay()
  zplay_DestroyZPlay(hZPlay)
  zplay_DetectBPM(hZPlay, nMethod)
  zplay_DetectFileBPM(hZPlay, pchFileName.p-Ascii, nFormat, nMethod)
  zplay_DetectFileBPMW(hZPlay, pchFileName.p-Unicode, nFormat, nMethod)
  zplay_DrawBitmapToHDC(hZPlay, *hDC, x, y, width, height, *hBitmap)
  zplay_DrawBitmapToHWND(hZPlay, *hwnd, x, y, width, height, *hBitmap)
  zplay_DrawFFTGraphOnHDC(hZPlay, *hDC, nX, nY, nWidth, nHeight)
  zplay_DrawFFTGraphOnHWND(hZPlay, *hwnd, nX, nY, nWidth, nHeight)
  zplay_EnableEcho(hZPlay, fEnable)
  zplay_EnableEqualizer(hZPlay, fEnable)
  zplay_EnumerateWaveOut(hZPlay)
  zplay_GetBitrate(hZPlay, fAverage)
  zplay_GetDynamicStreamLoad(hZPlay, *pStreamLoadInfo.TStreamLoadInfo)
  zplay_GetEchoParam(hZPlay, nNumberOfEffects, *pEchoEffect)
  zplay_GetEqualizerBandGain(hZPlay, nBandIndex)
  zplay_GetEqualizerParam(hZPlay, *pnBandGain, nNumberOfBands, nPreAmpGain)
  zplay_GetEqualizerPoints(hZPlay, *pnFreqPoint, nNumOfPoints)
  zplay_GetEqualizerPreampGain(hZPlay)
  zplay_GetError(hZPlay)
  zplay_GetErrorW(hZPlay)
  zplay_GetFFTData(hZPlay, nFFTPoints, nFFTWindow, *pnHarmonicNumber, *pnHarmonicFreq, *pnLeftAmplitude , *pnRightAmplitude, *pnLeftPhase, *pnRightPhase)
  zplay_GetFFTGraphParam(hZPlay, nParamID)
  zplay_GetFileFormat(hZPlay, pchFileName.p-Ascii)
  zplay_GetFileFormatW(hZPlay, pchFileName.p-Unicode)
  zplay_GetMasterVolume(hZPlay, *pnLeftVolume, *pnRightVolume)
  zplay_GetPitch(hZPlay)
  zplay_GetPlayerVolume(hZPlay, *pnLeftVolume, *pnRightVolume)
  zplay_GetPosition(hZPlay, *pTime.TStreamTime)
  zplay_GetRate(hZPlay)
  zplay_GetSettings(hZPlay, nSettingID)
  zplay_GetStatus(hZPlay, *pStatus.TStreamStatus)
  zplay_GetStreamInfo(hZPlay, *pInfo.TWaveInInfo)
  zplay_GetStreamInfoW(hZPlay, *pInfo.TWaveInInfoW)
  zplay_GetTempo(hZPlay)
  zplay_GetVUData(hZPlay, *pnLeftChannel, *pnRightChannel)
  zplay_GetVersion(hZPlay)
  zplay_GetWaveOutInfo(hZPlay, nIndex, *pWaveOutInfo.TWaveOutInfo)
  zplay_GetWaveOutInfoW(hZPlay, nIndex, *pWaveOutInfo.TWaveOutInfoW)
  zplay_IsStreamDataFree(hZPlay, *sMemNewData)
  zplay_LoadFileID3(hZPlay, pchFileName.p-Ascii, nFormat, nId3Version, *pId3Info.TID3Info)
  zplay_LoadFileID3Ex(hZPlay, pchFileName.p-Ascii, nFormat, nId3Version, *pId3Info.TID3Info, fDecodeEmbededPicture)
  zplay_LoadFileID3ExW(hZPlay,pchFileName.p-Unicode, nFormat, nId3Version, *pId3Info.TID3InfoW, fDecodeEmbededPicture)
  zplay_LoadFileID3W(hZPlay,pchFileName.p-Unicode, nFormat, nId3Version, *pId3Info.TID3InfoW)
  zplay_LoadID3(hZPlay, nId3Version, *pId3Info.TID3Info)
  zplay_LoadID3Ex(hZPlay, *pId3Info.TID3InfoEx, fDecodeEmbededPicture)
  zplay_LoadID3ExW(hZPlay,*pId3Info.TID3InfoExW, fDecodeEmbededPicture)
  zplay_LoadID3W(hZPlay, nId3Version, *pId3Info.TID3InfoW)
  zplay_MixChannels(hZPlay, fEnable, nLeftPercent, nRightPercent)
  zplay_OpenFile(hZPlay, sFileName.p-Ascii, nFormat)
  zplay_OpenFileW(hZPlay, sFileName.p-Unicode, nFormat)
  zplay_OpenStream(hZPlay, fBuffered, *sMemStream, nStreamSize, nFormat, fDynamic)
  zplay_Pause(hZPlay)
  zplay_Play(hZPlay)
  zplay_PlayLoop(hZPlay, fFormatStartTime, *pStartTime.TStreamTime, fFormatEndTime, *pEndTime.TStreamTime, nNumOfCycles, fContinuePlaying)
  zplay_PushDataToStream(hZPlay, *sMemNewData, nNewDataize)
  zplay_Resume(hZPlay)
  zplay_ReverseMode(hZPlay, fEnable)
  zplay_Seek(hZPlay, fFormat, *pTime, nMoveMethod)
  zplay_SetCallbackFunc(hZPlay, *pCallbackFunc.TCallbackFunc, nMessages, *user_data)
  zplay_SetEchoParam(hZPlay, *pEchoEffect.TEchoEffect, nNumberOfEffects)
  zplay_SetEqualizerBandGain(hZPlay, nBandIndex, nGain)
  zplay_SetEqualizerParam(hZPlay, nPreAmpGain, *pnBandGain, nNumberOfBands)
  zplay_SetEqualizerPoints(hZPlay, *pnFreqPoint, nNumOfPoints)
  zplay_SetEqualizerPreampGain(hZPlay, nGain)
  zplay_SetFFTGraphParam(hZPlay, nParamID, nValue)
  zplay_SetMasterVolume(hZPlay, nLeftVolume, nRightVolume)
  zplay_SetPitch(hZPlay, nPitch)
  zplay_SetPlayerVolume(hZPlay, nLeftVolume, nRightVolume)
  zplay_SetRate(hZPlay, nRate)
  zplay_SetSettings(hZPlay, nSettingID, nValue)
  zplay_SetTempo(hZPlay, nTempo)
  zplay_SetWaveOutDevice(hZPlay, nIndex)
  zplay_SlideVolume(hZPlay, fFormatStart, *pTimeStart.TStreamTime, nStartVolumeLeft, nStartVolumeRight, fFormatEnd, *pTimeEnd.TStreamTime, nEndVolumeLeft, nEndVolumeRight)
  zplay_StereoCut(hZPlay, fEnable, fOutputCenter, fBassToSides)
  zplay_Stop(hZPlay)
EndImport
Example:

Code: Select all

EnableExplicit

XIncludeFile "libzplay_include.pbi"

Define hZPlay, File.s, Text.s
Define ID3.TID3Info

File = OpenFileRequester("Please select a mp3-file", "*.mp3", "MP3-File|*.mp3", 0)
If File
  hZPlay = CreateZPlay()
  If hZPlay
    If zplay_OpenFile(hZPlay, File, #sfMp3)
      CompilerIf #PB_Compiler_Unicode
      If zplay_LoadFileID3W(hZPlay, File,#sfMp3, #id3Version2, @ID3)
      CompilerElse
      If zplay_LoadFileID3(hZPlay, File,#sfMp3, #id3Version2, @ID3)
      CompilerEndIf
        zplay_Play(hZPlay)
        Text = "Title: " +  id3\Title + #LF$
        Text + "from album: " + id3\Album + #LF$
        Text + "from year: " + id3\Year + #LF$ + #LF$
        Text + "Press okay to stop music"
        MessageRequester("Test libzplay", Text)
      EndIf
    EndIf
    zplay_Close(hZPlay)
    zplay_DestroyZPlay(hZPlay)
  EndIf
EndIf
Have Fun

Re: libZPlay include + header (windows 32-bit only)

Posted: Sat Mar 03, 2012 2:02 am
by ozzie
Very interesting! Looks like it handles audio playback very well, although I haven't tried it. Disappointing that there appears to have been no development since April 2010. There are some more features I'd like to see, such as ASIO support (not mentioned) and sample-locked playback of multiple files, but what has been implemented so far looks good.

Re: libZPlay include + header (windows 32-bit only)

Posted: Sat Mar 03, 2012 4:36 am
by IdeasVacuum
Very nice, thanks for sharing ts-soft.

Re: libZPlay include + header (windows 32-bit only)

Posted: Sat Mar 03, 2012 2:24 pm
by ts-soft
A better example:

Code: Select all

EnableExplicit

XIncludeFile "libzplay_include.pbi"

Define hZPlay, File.s
Define ID3.TID3Info

File = OpenFileRequester("Please select a mp3-file", "*.mp3", "MP3-File|*.mp3", 0)
If File
  hZPlay = zplay_CreateZPlay()
  If hZPlay
    If zplay_OpenFile(hZPlay, File, #sfMp3)
      CompilerIf #PB_Compiler_Unicode
      If zplay_LoadID3W(hZPlay, #id3Version2, @ID3)
      CompilerElse
      If zplay_LoadID3(hZPlay, #id3Version2, @ID3)
      CompilerEndIf
        zplay_Play(hZPlay)
        OpenWindow(0, #PB_Ignore, #PB_Ignore, 200, 170, GetFilePart(File), #PB_Window_SystemMenu | #PB_Window_Tool)
        TextGadget(0, 5, 110, 190, 20, "Album:" + #TAB$ + ID3\Album)
        TextGadget(1, 5, 130, 190, 20, "Artist:" + #TAB$ + id3\Artist)
        TextGadget(2, 5, 150, 190, 20, "Title:" + #TAB$ + ID3\Title)
        AddWindowTimer(0, 1, 100)
        zplay_SetFFTGraphParam(hZPlay, #gpGraphType, #gtAreaLeftOnTop)
        Repeat
          Select WaitWindowEvent()
            Case #PB_Event_CloseWindow : Break
            Case #PB_Event_Timer
              zplay_DrawFFTGraphOnHWND(hZPlay, WindowID(0), 5, 5, 190, 100)
          EndSelect
        ForEver
      EndIf
    EndIf
    zplay_Close(hZPlay)
    zplay_DestroyZPlay(hZPlay)
  EndIf
EndIf
Preview:
Image