libzplay库

libzplay目前,非开源,只可以在windows上应用;关于MP3文件播放:通常步骤是:获取MP3相关参数->解码->相关平台播放音频接口播放声音;可以播放解码播放MP3的库很多,如果VLC,ffplay,或者directshow,解码库一般可以用lame,播放播放库可以用SDL,或者Windows上的waveout,directsound等很多方法,这里例举

大家好,又见面了,我是你们的朋友全栈君。

libzplay目前,非开源,只可以在windows上应用;

关于MP3文件播放:通常步骤是:获取MP3相关参数 -> 解码-> 相关平台播放音频接口播放声音;

可以播放解码播放MP3的库很多,如果VLC,ffplay,或者directshow,解码库一般可以用lame,播放播放库可以用SDL,或者Windows上的waveout,directsound等很多方法,这里例举了,因为在任何平台上,无论怎么封装库,最后调用的还是平台播放接口;

这里在Windows上推荐的MP3播放器是libzplay;

这里说明一下libzplay库:

很方便的详细简单的讲解libzplay的应用;

libzplay工程非开源,下到的库中说应用说明文档较少,函数注释较少,有些功能靠猜,不过可以通过测试确定,但是功能还是比较强大的,工程中的示例代码较多;

一:

libzplay除了可以播放MP3,还可以播放WAV,PCM等音频文件,从其枚举值中可以看到播放的支持类型:

This is multimedia library for playing mp3, mp2, mp1, ogg, flac, oga, ac3,
aac, wav and pcm files and streams.

关于streams的播放,可以参考dynamic_stream示例,示例中的是获取MP3格式,但是也可以通过接口自定义设置格式;

enum TStreamFormat
{

sfUnknown = 0,
sfMp3 = 1,
sfOgg = 2,
sfWav = 3,
sfPCM = 4,
sfFLAC = 5,
sfFLACOgg = 6,
sfAC3 = 7,
sfAacADTS = 8,
sfWaveIn = 9,
sfAutodetect = 1000
};

二:

这里简单将其说明放到这里:

===========================================================================================
1. ABOUT
===========================================================================================
libZPlay ver. 2.02 (Win32)

Version: 2.02
Date: May, 2010. 

This is multimedia library for playing mp3, mp2, mp1, ogg, flac, oga, ac3,
aac, wav and pcm files and streams. 

This library integrate all decoders/encoders for supported formats.
You don’t need additional libraries. Library is using native
WINAPI functions from kernel32.dll, user32.dll, gdi32.dll and winmm.dll.
All these libraries are standard libraries on all Microsoft Windows.
There is no need for MFC or .NET support.
Just pure WINAPI. 

Library will play music directly to soundcard.
Simple and easy. No need for additional programming.
You can play music using only 3 lines of code (create class, open file and start playing).
Simple, simple, simple … 

With version 2.00 you can record music from your soundcard.
Read more in libzplay.chm documentation file.

libZPlay library is combination of multiple decoding/encoding libraries.
Read topic 8. COPYRIGHT for more informations.

 
===========================================================================================
2. Supported formats
=========================================================================================== 
 
– MP3  -> mp3, mp2, mp1  MPEG-1, MPEG-2, MPEG 2.5 – Layer I, Layer II, Layer III.
          Read topic 9: MP3 and AAC LICENSE  

– OGG  -> ogg – VORBIS OGG 
 
– AC3  -> A/52 aka. ac3

– AAC  -> HE, LC, MAIN and LTP profile, MPEG2 and MPEG-4 AAC decoder.
          Read topic 9: MP3 and AAC LICENSE

– FLAC -> flac, oga – Native FLAC and OGG flac 
 
– WAVE -> wav – PCM WAVE with RIFF header, uncompressed, 8, 16 bit per sample 
 
– PCM  -> any file – Raw PCM audio format, uncomressed, 8 16 bit per sample  

 
===========================================================================================
3. Supported languages
===========================================================================================

Library is customized for:

– Standard C/C++ (native) 
– Visual C++ .NET (VC.NET wrapper class) 
– Visual Basic .NET (VB.NET wrapper class) 
– C# (C#.NET wrapper class) 
– Delphi (Delphi wrapper class) 
– and any other language which can use exported __stdcall functions from dll library 
 
 
===========================================================================================
4. Features
===========================================================================================

– supports mp3, ogg, flac, ac3, aac, wav, pcm 
– supports wave-in input (get samples from line-in, microphone, ….)
– supports encoding samples into mp3, ogg, flac, wave and aac streams and files
– UNICODE support for functions using strings ( filename, error messages, ID3 info, … ) 
– read info tags from file ( ID3v1, ID3v2, VORBIS comment, wave RIFF list,
  FLAC VORBIS comment, embeded picture ) 
– easy drawing embeded picture to screen
– REVERSE PLAYING (you can play song backward in real time, “real” backward playing
  without predecoding in PCM) 
– built in equaliter, user can specify own subbands, add subbands, … 
– built in echo and reverb sound processor 
– pitch/rate/tempo change 
– stereo cut effect 
– detect beat-per-minute using 2 methods ( peak detection and autocorrelation) 
– loop playing (you can play just one portion of file, repeat this portion … ) 
– channel mixer (you can mix left and right chanel, convert stereo to mono … ) 
– volume slide control (fade-in and fade-out) 
– internal volume control (without affecting wave out device volume) 
– pulling VU meter data (you can simply create VU meter) 
– pulling FFT data (you can simply build FFT spectrum analyzer) 
– built in FFT spectrum graph, library will draw complete spectrum graph on your window 
– callback mechanism (class will inform you about events like play, stop, fade, …) 
– access to decoded PCM data throug callback message 
– play data from disk files, UNICODE SUPPORT 
– play data from allocated memory 
– play dynamic streams (push small memory chunks into stream while song is playing,
  for download streams) 
– selecting wave output (for multiple waveout devices) 
– easy play, pause, seek … 
– class interface for VC.NET, VB.NET, C# and Delphi. 
 

===========================================================================================
5. ARCHIVE CONTENTS
===========================================================================================

.\
  \C#              – C# support files
  \C++             – C/C++ support files
  \Delphi          – Delphi support files
  \VB.NET          – VB.NET support files
  \VC.NET          – VC.NET support files
  \license         – license informations for libraries included in libZPlay library

  libzplay.dll    – libZPlay (WIN32) library – full version
  libzplay.chm    – complete documentation for libZPlay library

===========================================================================================
6. HOW TO USE LIBZPLAY
===========================================================================================
For more informations read instructions from install.txt in C#, C++, Delphi, VB.NET or
VC.NET folder.

播放示例:

示例1:

player = CreateZPlay();

// open file
if(player->OpenFile( “F:\\t.mp3”, sfAutodetect) == 0)
{

printf(“Error: %s\nPress key to exit.\r\n”, player->GetError());
player->Release();
return  ;
}

player->Play();

示例2:

从sfWaveIn播放枚举值可以看出,应该是支持音频输入设备采集播放的;

这个示例讲解了打开音频设备,播放,但是关于第一个参数的音频名称,可以通过directshow,或者directsound等方法枚举音频设置;

所以这个示例,可以替代portaudio,或者directsound,或者wavein等一些方法,如果不想播放声音,可以设置音量为0;

player = CreateZPlay();

       //设置参数:
       player->SetSettings(sidAccurateLength,1);

// open file
if(player->OpenFile( “virtual-audio-capturer”, sfWaveIn) == 0)
{

printf(“Error: %s\nPress key to exit.\r\n”, player->GetError());
player->Release();
return  ;
}

player->Play();

示例3:

获取MP3解码值,或音频设备采集值;

这个是关心的,但是,在示例代码中没有看到示例程序,也没有看到说明文档;

不过可以根据:MsgWaveBuffer猜测,应该是支持数据获取的;所以这里的示例首先参考回调函数设置的示例,然后设置数据获取;

enum  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
};

ZPlay* player;

int  __stdcall  CallbackFunc(void* instance, void *user_data, TCallbackMessage message, unsigned int param1, unsigned int param2)
{

ZPlay *myinstance = (ZPlay*) instance;

switch(message)
{

case MsgNextSong:
{

printf(“Index: %u  Left: %u\n”, param1, param2); 
}
break;

case  MsgWaveBuffer:
{

                       //在这个参数中,第一个参数是指针,第二个参数是长度;
static FILE * f = fopen(“F:\\tm.pcm”,”w+b”);
fwrite( (unsigned char * )param1, 1, param2, f );
}

}

return 0;
}

void CtestMPThreeToPcmDlg::OnBnClickedButton1()
{

// TODO: 在此添加控件通知处理程序代码

// create class instance
player = CreateZPlay();

player->SetSettings(sidAccurateLength,1);

player->SetCallbackFunc(CallbackFunc, /*MsgNextSong*/MsgWaveBuffer, 0);

// open file
//if(player->OpenFile( “F:\\t.mp3”, sfAutodetect) == 0)
if(player->OpenFile( “virtual-audio-capturer”, sfWaveIn) == 0)
{

printf(“Error: %s\nPress key to exit.\r\n”, player->GetError());
player->Release();
return  ;
}

player->Play();

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/127304.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号