这几天用labview写了个mp3播放器,基于bass.dll库制作的,我的第一个labview作品,哈哈!
基本实现了一些功能:
mp3文件的播放、暂停、停止
播放列表的生成,调整,选择播放
歌曲播放时间的显示、调整
音量的调节
频谱图的显示
播放模式的选择:单曲播放、顺序播放、单曲循环、所有循环
支持lrc格式歌词同步播放
当然中间遇到了不少问题,毕竟是第一次做labview的程序,一些很基本的也接触不多:
1、DLL的调用,首先是如何调用,了解到的方法有:写script脚本;使用调用节点;导入共享库。这里用的是最后一种方法,于是涉及到头文件的问题,好在Bass.dll的编写者给我们留了头文件。
2、导入共享库的问题,这里有不少,很多类型在头文件中未定义,查看导入时的错误报告能找到原因,把.h中需要修改的地方修改过来即可。最后还是有些类型无法找到,但并不影响编程,就没再管。只有被正确定义为了C语言的基本数据类型才能被labview识别。
3、事件循环与主程序同时跳出的问题,之前没有接触过,可以创建一个布尔链接多个while,算是个小技巧。
4、控件响应用户输入的问题。这里用到了载入条和列表框,之前不知道为什么载入条不能调整位置、列表框不能选取高亮,搞了半天才懂得,原来要设置成输入控件就可以了……
5、头文件是个很有用的东西,不仅仅在导入共享库的时候有用,之后在调用函数设置初值时,Bass帮助手册中都是用的已定义好的符号,如“BASS_DATA_FFT1024”,而该符号代表的数值就要从头文件中获得。
6、列表框项的拖放、调整,设置成可拖放型,在拖放结束的时候再对歌曲列表做相应调整。然而获取列表框选取项的方法还是没有解决……
7、关于原始函数传递指针的问题。C语言中没有字符串变量,因此字符串都是用指针传递,再对指针对应的内存进行读写,若只是读到好,在labview中直接传递字符串就可以,但涉及到写的问题时,labview中必须保证已经分配了足够的内存来完成读写,要不会显示内存错误的提示。数组也是一样的道理。这在绘制FFT图时遇到。具体办法在NI网站上找到了解答。
8、歌词的同步还涉及到lrc格式的解读,在做字符串匹配的时候发现labview的正则表达式不支持\d这样的标识~
参考链接:
http://www.aobonet.com/dev/Delphi/200901/5792.html
http://forums.ni.com/ni/board?board.id=170
空间:
Hi ,
can you send me a vi of mp3 player
I had createed a labview application for grab my microphone audio using Bass.dll (http://www.un4seen.com/)
but i'm stuck .
I have useed this function
DWORD BASS_ChannelGetData(
DWORD handle,
void
*buffer,
DWORD length
);
The function works well.
I recieved a string data from void *buffer , the data are a sample of FFT and I recieved a lenght data.
The problem is :
How is it possible to convert my FFT data in to a wav file .
Any Help or advice is much appreciated
Simone
try this:
Starts recording.
HRECORD BASS_RecordStart( DWORD freq, DWORD chans, DWORD flags, RECORDPROC *proc void *user ); |
When not using a callback (proc = NULL), the recorded data is instead retrieved via BASS_ChannelGetData.
Retrieves the immediate sample data (or an FFT representation of it) of a stream or MOD music channel. Can also be used with a recording channel.
DWORD BASS_ChannelGetData( DWORD handle, void *buffer, DWORD length ); |
When retrieving sample data, 8-bit samples are unsigned (0 to 255) , 16-bit samples are signed (-32768 to 32767), 32-bit floating-point samples range from -1 to +1 (not clipped, so can actually be outside this range). That is unless the BASS_DATA_FLOAT flag is used, in which case, the sample data will be converted to 32-bit floating-point if it is not already.
Numeric to receive the *buffer.Sound VI to write .wav file.
Thanks for your replay!!!
My problem was put the sample in a wave file .
I have tryed to done this but when I have open the file with media player it dosen't work.
If I open the file with notepad :
"RIFF0 WAVEfmt D¬ D¬ fact data "
but there is not data inside...
what's wrong?
Thanks
Simone
In attachement there is my Vi
Hello qwbaoba,
I try to develop a Labview MP3 player.
To help me, could you share the source code (block diagram) of your player?
( I know, now we are in 2014 but I try )
Thank you in advance.
Syned